Search in sources :

Example 6 with TabActionEvent

use of org.netbeans.swing.tabcontrol.event.TabActionEvent in project netbeans-rcp-lite by outersky.

the class TabDisplayerUI method shouldPerformAction.

/**
 * Allows ActionListeners attached to the container to determine if the
 * event should be acted on. Delegates to <code>displayer.postActionEvent()</code>.
 * This method will create a TabActionEvent with the passed string as an
 * action command, and cause the displayer to fire this event.  It will
 * return true if no listener on the displayer consumed the TabActionEvent;
 * consuming the event is the way a listener can veto a change, or provide
 * special handling for it.
 *
 * @param e The original tab action event.
 * @return true if the event posted was not consumed by any listener
 * @since 1.27
 */
protected final boolean shouldPerformAction(TabActionEvent e) {
    TabActionEvent evt = new TabActionEvent(displayer, e.getActionCommand(), e.getTabIndex(), e.getMouseEvent());
    evt.setGroupName(e.getGroupName());
    displayer.postActionEvent(evt);
    return !evt.isConsumed();
}
Also used : TabActionEvent(org.netbeans.swing.tabcontrol.event.TabActionEvent)

Example 7 with TabActionEvent

use of org.netbeans.swing.tabcontrol.event.TabActionEvent in project netbeans-rcp-lite by outersky.

the class TabbedHandler method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (e instanceof TabActionEvent) {
        TabActionEvent tae = (TabActionEvent) e;
        String cmd = tae.getActionCommand();
        if (TabbedContainer.COMMAND_SELECT.equals(cmd)) {
            return;
        }
        tae.consume();
        if (TabbedContainer.COMMAND_CLOSE == cmd) {
            // == test is safe here
            TopComponent tc = tabbed.getTopComponentAt(tae.getTabIndex());
            if (tc != null && modeView != null) {
                modeView.getController().userClosedTopComponent(modeView, tc);
            } else {
                Logger.getLogger(TabbedHandler.class.getName()).warning("TopComponent to be closed is null at index " + tae.getTabIndex());
            }
        } else if (TabbedContainer.COMMAND_POPUP_REQUEST == cmd) {
            handlePopupMenuShowing(tae.getMouseEvent(), tae.getTabIndex());
        } else if (TabbedContainer.COMMAND_MAXIMIZE == cmd) {
            handleMaximization(tae);
        } else if (TabbedContainer.COMMAND_CLOSE_ALL == cmd) {
            ActionUtils.closeAllDocuments(true);
        } else if (TabbedContainer.COMMAND_CLOSE_ALL_BUT_THIS == cmd) {
            TopComponent tc = tabbed.getTopComponentAt(tae.getTabIndex());
            ActionUtils.closeAllExcept(tc, true);
        // Pin button handling here
        } else if (TabbedContainer.COMMAND_ENABLE_AUTO_HIDE.equals(cmd)) {
            if (Switches.isTopComponentSlidingEnabled() && tabbed.getComponent().isShowing()) {
                TopComponent tc = tabbed.getTopComponentAt(tae.getTabIndex());
                // prepare slide operation
                Component tabbedComp = tabbed.getComponent();
                String side = WindowManagerImpl.getInstance().guessSlideSide(tc);
                SlideOperation operation = SlideOperationFactory.createSlideIntoEdge(tabbedComp, side, true);
                operation.setStartBounds(new Rectangle(tabbedComp.getLocationOnScreen(), tabbedComp.getSize()));
                operation.prepareEffect();
                modeView.getController().userEnabledAutoHide(modeView, tc);
                modeView.getController().userTriggeredSlideIntoEdge(modeView, operation);
            }
        } else if (TabbedContainer.COMMAND_MINIMIZE_GROUP.equals(cmd)) {
            if (Switches.isModeSlidingEnabled()) {
                TopComponent tc = tabbed.getTopComponentAt(0);
                WindowManagerImpl wm = WindowManagerImpl.getInstance();
                ModeImpl mode = (ModeImpl) wm.findMode(tc);
                if (null != mode) {
                    wm.userMinimizedMode(mode);
                }
            }
        } else if (TabbedContainer.COMMAND_RESTORE_GROUP.equals(cmd)) {
            String nameOfModeToRestore = tae.getGroupName();
            if (null != nameOfModeToRestore) {
                TopComponent tc = tabbed.getTopComponentAt(0);
                WindowManagerImpl wm = WindowManagerImpl.getInstance();
                ModeImpl slidingMode = (ModeImpl) wm.findMode(tc);
                ModeImpl modeToRestore = (ModeImpl) wm.findMode(nameOfModeToRestore);
                if (null != modeToRestore && null != slidingMode) {
                    wm.userRestoredMode(slidingMode, modeToRestore);
                }
            }
        } else if (TabbedContainer.COMMAND_CLOSE_GROUP.equals(cmd)) {
            if (Switches.isModeClosingEnabled()) {
                TopComponent tc = tabbed.getTopComponentAt(0);
                WindowManagerImpl wm = WindowManagerImpl.getInstance();
                ModeImpl mode = (ModeImpl) wm.findMode(tc);
                if (null != mode) {
                    wm.userClosedMode(mode);
                }
            }
        }
    } else if (e instanceof SlideBarActionEvent) {
        // slide bar commands
        SlideBarActionEvent sbe = (SlideBarActionEvent) e;
        String cmd = sbe.getActionCommand();
        if (SlideBar.COMMAND_POPUP_REQUEST.equals(cmd)) {
            handlePopupMenuShowing(sbe.getMouseEvent(), sbe.getTabIndex());
        } else if (SlideBar.COMMAND_SLIDE_IN.equals(cmd)) {
            modeView.getController().userTriggeredSlideIn(modeView, sbe.getSlideOperation());
        } else if (SlideBar.COMMAND_SLIDE_RESIZE.equals(cmd)) {
            modeView.getController().userResizedSlidingWindow(modeView, sbe.getSlideOperation());
        } else if (SlideBar.COMMAND_SLIDE_OUT.equals(cmd)) {
            // when the call comes from the change of tehmodel rather than user clicking,
            // ignore activation requests.
            // #48539
            SlideOperation op = new ProxySlideOperation(sbe.getSlideOperation(), ignoreChange);
            modeView.getController().userTriggeredSlideOut(modeView, op);
        } else if (SlideBar.COMMAND_DISABLE_AUTO_HIDE.equals(cmd)) {
            TopComponent tc = tabbed.getTopComponentAt(sbe.getTabIndex());
            modeView.getController().userDisabledAutoHide(modeView, tc);
        } else if (SlideBar.COMMAND_MAXIMIZE == cmd) {
            TopComponent tc = tabbed.getTopComponentAt(sbe.getTabIndex());
            MaximizeWindowAction mwa = new MaximizeWindowAction(tc);
            if (mwa.isEnabled())
                mwa.actionPerformed(e);
        }
    }
}
Also used : TabActionEvent(org.netbeans.swing.tabcontrol.event.TabActionEvent) SlideBarActionEvent(org.netbeans.core.windows.view.ui.slides.SlideBarActionEvent) WindowManagerImpl(org.netbeans.core.windows.WindowManagerImpl) ModeImpl(org.netbeans.core.windows.ModeImpl) MaximizeWindowAction(org.netbeans.core.windows.actions.MaximizeWindowAction) TopComponent(org.openide.windows.TopComponent) TopComponent(org.openide.windows.TopComponent) SlideOperation(org.netbeans.core.windows.view.ui.slides.SlideOperation)

Example 8 with TabActionEvent

use of org.netbeans.swing.tabcontrol.event.TabActionEvent in project netbeans-rcp-lite by outersky.

the class ButtonPopupSwitcher method changeSelection.

/**
 * Allow keyboard navigation in document dropdown list.
 *
 * @param event
 * @return
 */
private boolean changeSelection(KeyEvent event) {
    int key = event.getKeyCode();
    int selRow = pTable.getSelectedRow();
    int selCol = pTable.getSelectedColumn();
    if (selRow < 0)
        selRow = 0;
    if (selCol < 0)
        selCol = 0;
    boolean switched = true;
    switch(key) {
        case KeyEvent.VK_LEFT:
            selCol--;
            if (selCol < 0) {
                selCol = pTable.getColumnCount() - 1;
            }
            break;
        case KeyEvent.VK_RIGHT:
            selCol++;
            if (selCol > pTable.getColumnCount() - 1) {
                selCol = 0;
            }
            break;
        case KeyEvent.VK_DOWN:
            selRow++;
            if (selRow > pTable.getRowCount() - 1) {
                selCol++;
                selRow = 0;
                if (selCol > pTable.getColumnCount() - 1) {
                    selCol = 0;
                }
            }
            break;
        case KeyEvent.VK_UP:
            selRow--;
            if (selRow < 0) {
                selCol--;
                selRow = pTable.getRowCount() - 1;
                if (selCol < 0) {
                    selCol = pTable.getColumnCount() - 1;
                }
            }
            break;
        case KeyEvent.VK_DELETE:
            {
                Item item = (Item) pTable.getModel().getValueAt(selRow, selCol);
                if (null != item && pTable.isClosable(item)) {
                    TabData tab = item.getTabData();
                    int tabIndex = displayer.getModel().indexOf(tab);
                    if (tabIndex >= 0) {
                        if (displayer.getModel().size() == 1) {
                            SwingUtilities.invokeLater(new Runnable() {

                                @Override
                                public void run() {
                                    hideCurrentPopup();
                                }
                            });
                        }
                        TabActionEvent evt = new TabActionEvent(displayer, TabDisplayer.COMMAND_CLOSE, tabIndex);
                        displayer.postActionEvent(evt);
                        selRow = Math.min(pTable.getModel().getRowCount() - 1, selRow);
                        selCol = Math.min(pTable.getModel().getColumnCount() - 1, selCol);
                        switched = true;
                    }
                }
                break;
            }
        case KeyEvent.VK_ENTER:
            final SwitcherTableItem item = pTable.getSelectedItem();
            if (item != null) {
                item.activate();
                hideCurrentPopup();
            }
            break;
        default:
            switched = false;
    }
    if (switched) {
        pTable.changeSelection(selRow, selCol, false, false);
    }
    return switched;
}
Also used : TabActionEvent(org.netbeans.swing.tabcontrol.event.TabActionEvent) Item(org.netbeans.swing.tabcontrol.DocumentSwitcherTable.Item) SwitcherTableItem(org.netbeans.swing.popupswitcher.SwitcherTableItem) SwitcherTableItem(org.netbeans.swing.popupswitcher.SwitcherTableItem) Point(java.awt.Point)

Aggregations

TabActionEvent (org.netbeans.swing.tabcontrol.event.TabActionEvent)8 TopComponent (org.openide.windows.TopComponent)3 ModeImpl (org.netbeans.core.windows.ModeImpl)2 WindowManagerImpl (org.netbeans.core.windows.WindowManagerImpl)2 SwitcherTableItem (org.netbeans.swing.popupswitcher.SwitcherTableItem)2 Point (java.awt.Point)1 MaximizeWindowAction (org.netbeans.core.windows.actions.MaximizeWindowAction)1 SlideBarActionEvent (org.netbeans.core.windows.view.ui.slides.SlideBarActionEvent)1 SlideOperation (org.netbeans.core.windows.view.ui.slides.SlideOperation)1 Item (org.netbeans.swing.tabcontrol.DocumentSwitcherTable.Item)1