javax.swing.MenuSelectionManager Java Examples

The following examples show how to use javax.swing.MenuSelectionManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RMenuItemTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@BeforeMethod
public void showDialog() throws Throwable {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            MenuSelectionManager.defaultManager().clearSelectedPath();
            frame = new JFrame(RMenuItemTest.class.getSimpleName());
            frame.setName("frame-" + RMenuItemTest.class.getSimpleName());
            MenuDemo demo = new MenuDemo();
            frame.setJMenuBar(demo.createMenuBar());
            frame.setContentPane(demo.createContentPane());
            frame.pack();
            frame.setVisible(true);
        }
    });
    menus = ComponentUtils.findComponents(JMenu.class, frame);
}
 
Example #2
Source File: SeaGlassCheckBoxMenuItemUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
public void processMouseEvent(JMenuItem item, MouseEvent e, MenuElement path[], MenuSelectionManager manager) {
    Point p = e.getPoint();
    if (p.x >= 0 && p.x < item.getWidth() && p.y >= 0 && p.y < item.getHeight()) {
        if (e.getID() == MouseEvent.MOUSE_RELEASED) {
            manager.clearSelectedPath();
            item.doClick(0);
        } else {
            manager.setSelectedPath(path);
        }
    } else if (item.getModel().isArmed()) {
        int c = path.length - 1;
        MenuElement newPath[] = new MenuElement[c];
        for (int i = 0; i < c; i++) {
            newPath[i] = path[i];
        }
        manager.setSelectedPath(newPath);
    }
}
 
Example #3
Source File: JPopupMenuTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@BeforeMethod
public void showDialog() throws Throwable {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame(JPopupMenuTest.class.getSimpleName());
            frame.setName("frame-" + JPopupMenuTest.class.getSimpleName());
            PopupMenuDemo demo = new PopupMenuDemo();
            frame.setJMenuBar(demo.createMenuBar());
            frame.setContentPane(demo.createContentPane());

            // Create and set up the popup menu.
            demo.createPopupMenu();

            frame.pack();
            frame.setAlwaysOnTop(true);
            frame.setVisible(true);
        }
    });
    MenuSelectionManager.defaultManager().clearSelectedPath();
}
 
Example #4
Source File: StayOpenPopupMenu.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager) {
    if (isReturnAction(e)) { // Handle SPACE and ENTER
        MenuElement[] p = manager.getSelectedPath();
        MenuElement m = p != null && p.length > 0 ? p[p.length - 1] : null;
        if (m instanceof StayOpen) {
            e.consume();
            if (e.getID() == KeyEvent.KEY_PRESSED)
                performAction((StayOpen)m, e.getModifiers());
            return;
        }
    } else for (Component component : getComponents()) { // Handle mnemonics and accelerators
        if (component instanceof StayOpen) {
            StayOpen item = (StayOpen)component;
            JMenuItem i = item.getItem();
            KeyStroke k = KeyStroke.getKeyStrokeForEvent(e);
            if (k.equals(mnemonic(i)) || k.equals(i.getAccelerator())) {
                e.consume();
                manager.setSelectedPath(new MenuElement[] { this, i });
                performAction(item, e.getModifiers());
                return;
            }
        }
    }
    
    super.processKeyEvent(e, path, manager);
}
 
Example #5
Source File: JPopupMenuEndlessLoopTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(() -> {

        JPopupMenu popup = new JPopupMenu("Popup Menu");
        JMenu menu = new JMenu("Menu");
        menu.add(new JMenuItem("Menu Item"));
        popup.add(menu);
        menu.doClick();
        MenuElement[] elems = MenuSelectionManager
                .defaultManager().getSelectedPath();

        if (elems == null || elems.length == 0) {
            throw new RuntimeException("Empty Selection");
        }

        if (elems[0] != popup || elems[1] != menu) {
            throw new RuntimeException("Necessary menus are not selected!");
        }
    });
}
 
Example #6
Source File: JMenuItemJavaElement2Test.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@BeforeMethod
public void showDialog() throws Throwable {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame(JMenuItemJavaElement2Test.class.getSimpleName());
            frame.setName("frame-" + JMenuItemJavaElement2Test.class.getSimpleName());
            PopupMenuDemoX demo = new PopupMenuDemoX();
            frame.setJMenuBar(demo.createMenuBar());
            frame.setContentPane(demo.createContentPane());

            // Create and set up the popup menu.
            demo.createPopupMenu();

            frame.pack();
            frame.setAlwaysOnTop(true);
            frame.setVisible(true);
        }
    });
    MenuSelectionManager.defaultManager().clearSelectedPath();
    JavaElementFactory.add(JMenuItem.class, JMenuItemJavaElement.class);
}
 
Example #7
Source File: WindowsRootPaneUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public boolean postProcessKeyEvent(KeyEvent ev) {
    if(ev.isConsumed()) {
        // do not manage consumed event
        return false;
    }
    if (ev.getKeyCode() == KeyEvent.VK_ALT) {
        root = SwingUtilities.getRootPane(ev.getComponent());
        winAncestor = (root == null ? null :
                SwingUtilities.getWindowAncestor(root));

        if (ev.getID() == KeyEvent.KEY_PRESSED) {
            if (!altKeyPressed) {
                altPressed(ev);
            }
            altKeyPressed = true;
            return true;
        } else if (ev.getID() == KeyEvent.KEY_RELEASED) {
            if (altKeyPressed) {
                altReleased(ev);
            } else {
                MenuSelectionManager msm =
                    MenuSelectionManager.defaultManager();
                MenuElement[] path = msm.getSelectedPath();
                if (path.length <= 0) {
                    WindowsLookAndFeel.setMnemonicHidden(true);
                    WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
                }
            }
            altKeyPressed = false;
        }
        root = null;
        winAncestor = null;
    } else {
        altKeyPressed = false;
    }
    return false;
}
 
Example #8
Source File: WindowsRootPaneUI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public boolean postProcessKeyEvent(KeyEvent ev) {
    if(ev.isConsumed()) {
        // do not manage consumed event
        return false;
    }
    if (ev.getKeyCode() == KeyEvent.VK_ALT) {
        root = SwingUtilities.getRootPane(ev.getComponent());
        winAncestor = (root == null ? null :
                SwingUtilities.getWindowAncestor(root));

        if (ev.getID() == KeyEvent.KEY_PRESSED) {
            if (!altKeyPressed) {
                altPressed(ev);
            }
            altKeyPressed = true;
            return true;
        } else if (ev.getID() == KeyEvent.KEY_RELEASED) {
            if (altKeyPressed) {
                altReleased(ev);
            } else {
                MenuSelectionManager msm =
                    MenuSelectionManager.defaultManager();
                MenuElement[] path = msm.getSelectedPath();
                if (path.length <= 0) {
                    WindowsLookAndFeel.setMnemonicHidden(true);
                    WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
                }
            }
            altKeyPressed = false;
        }
        root = null;
        winAncestor = null;
    } else {
        altKeyPressed = false;
    }
    return false;
}
 
Example #9
Source File: RecentFileAction.java    From constellation with Apache License 2.0 5 votes vote down vote up
/**
 * Workaround for JDK bug 6663119, it ensures that first item in submenu is
 * correctly selected during keyboard navigation.
 */
private void ensureSelected() {
    if (menu.getMenuComponentCount() <= 0) {
        return;
    }

    Component first = menu.getMenuComponent(0);
    if (!(first instanceof JMenuItem)) {
        return;
    }

    Point loc = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(loc, menu);
    MenuElement[] selPath
            = MenuSelectionManager.defaultManager().getSelectedPath();

    // apply workaround only when mouse is not hovering over menu
    // (which signalizes mouse driven menu traversing) and only
    // when selected menu path contains expected value - submenu itself
    if (!menu.contains(loc) && selPath.length > 0
            && menu.getPopupMenu() == selPath[selPath.length - 1]) {
        // select first item in submenu through MenuSelectionManager
        MenuElement[] newPath = new MenuElement[selPath.length + 1];
        System.arraycopy(selPath, 0, newPath, 0, selPath.length);
        JMenuItem firstItem = (JMenuItem) first;
        newPath[selPath.length] = firstItem;
        MenuSelectionManager.defaultManager().setSelectedPath(newPath);
    }
}
 
Example #10
Source File: JMenuBarOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps
 * {@code JMenuBar.processKeyEvent(KeyEvent, MenuElement[], MenuSelectionManager)}
 * through queue
 */
public void processKeyEvent(final KeyEvent keyEvent, final MenuElement[] menuElement, final MenuSelectionManager menuSelectionManager) {
    runMapping(new MapVoidAction("processKeyEvent") {
        @Override
        public void map() {
            ((JMenuBar) getSource()).processKeyEvent(keyEvent, menuElement, menuSelectionManager);
        }
    });
}
 
Example #11
Source File: WindowsRootPaneUI.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean postProcessKeyEvent(KeyEvent ev) {
    if(ev.isConsumed()) {
        // do not manage consumed event
        return false;
    }
    if (ev.getKeyCode() == KeyEvent.VK_ALT) {
        root = SwingUtilities.getRootPane(ev.getComponent());
        winAncestor = (root == null ? null :
                SwingUtilities.getWindowAncestor(root));

        if (ev.getID() == KeyEvent.KEY_PRESSED) {
            if (!altKeyPressed) {
                altPressed(ev);
            }
            altKeyPressed = true;
            return true;
        } else if (ev.getID() == KeyEvent.KEY_RELEASED) {
            if (altKeyPressed) {
                altReleased(ev);
            } else {
                MenuSelectionManager msm =
                    MenuSelectionManager.defaultManager();
                MenuElement[] path = msm.getSelectedPath();
                if (path.length <= 0) {
                    WindowsLookAndFeel.setMnemonicHidden(true);
                    WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
                }
            }
            altKeyPressed = false;
        }
        root = null;
        winAncestor = null;
    } else {
        altKeyPressed = false;
    }
    return false;
}
 
Example #12
Source File: MenuScroller.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the number of items in the scrolling portion of the menu.
 *
 * @param scrollCount the number of items to display at a time
 * @throws IllegalArgumentException if scrollCount is 0 or negative
 */
public void setScrollCount(int scrollCount) {
    if (scrollCount <= 0) {
        throw new IllegalArgumentException("scrollCount must be greater than 0");
    }
    this.scrollCount = scrollCount;
    MenuSelectionManager.defaultManager().clearSelectedPath();
}
 
Example #13
Source File: WindowsRootPaneUI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
 
Example #14
Source File: WindowsRootPaneUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
 
Example #15
Source File: WindowsRootPaneUI.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
 
Example #16
Source File: WindowsRootPaneUI.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public boolean postProcessKeyEvent(KeyEvent ev) {
    if(ev.isConsumed() && ev.getKeyCode() != KeyEvent.VK_ALT) {
        // mnemonic combination, it's consumed, but we need
        // set altKeyPressed to false, otherwise after selection
        // component by mnemonic combination a menu will be open
        altKeyPressed = false;
        return false;
    }
    if (ev.getKeyCode() == KeyEvent.VK_ALT) {
        root = SwingUtilities.getRootPane(ev.getComponent());
        winAncestor = (root == null ? null :
                SwingUtilities.getWindowAncestor(root));

        if (ev.getID() == KeyEvent.KEY_PRESSED) {
            if (!altKeyPressed) {
                altPressed(ev);
            }
            altKeyPressed = true;
            return true;
        } else if (ev.getID() == KeyEvent.KEY_RELEASED) {
            if (altKeyPressed) {
                altReleased(ev);
            } else {
                MenuSelectionManager msm =
                    MenuSelectionManager.defaultManager();
                MenuElement[] path = msm.getSelectedPath();
                if (path.length <= 0) {
                    WindowsLookAndFeel.setMnemonicHidden(true);
                    WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
                }
            }
            altKeyPressed = false;
        }
        root = null;
        winAncestor = null;
    } else {
        altKeyPressed = false;
    }
    return false;
}
 
Example #17
Source File: WindowsRootPaneUI.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public boolean postProcessKeyEvent(KeyEvent ev) {
    if(ev.isConsumed()) {
        // do not manage consumed event
        return false;
    }
    if (ev.getKeyCode() == KeyEvent.VK_ALT) {
        root = SwingUtilities.getRootPane(ev.getComponent());
        winAncestor = (root == null ? null :
                SwingUtilities.getWindowAncestor(root));

        if (ev.getID() == KeyEvent.KEY_PRESSED) {
            if (!altKeyPressed) {
                altPressed(ev);
            }
            altKeyPressed = true;
            return true;
        } else if (ev.getID() == KeyEvent.KEY_RELEASED) {
            if (altKeyPressed) {
                altReleased(ev);
            } else {
                MenuSelectionManager msm =
                    MenuSelectionManager.defaultManager();
                MenuElement[] path = msm.getSelectedPath();
                if (path.length <= 0) {
                    WindowsLookAndFeel.setMnemonicHidden(true);
                    WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
                }
            }
            altKeyPressed = false;
        }
        root = null;
        winAncestor = null;
    } else {
        altKeyPressed = false;
    }
    return false;
}
 
Example #18
Source File: WindowsRootPaneUI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
 
Example #19
Source File: AbstractQuickSearchComboBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public AllMenuItem(Set<Category> evalCats) {
    this.evalCats = evalCats;
    this.totalCount = ProviderModel.getInstance()
            .getCategories().size();
    getModel().addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            if (isShowing() && model.isArmed()) {
                selectedPath = MenuSelectionManager.defaultManager()
                        .getSelectedPath();
            }
        }
    });
    addActionListener(this);
}
 
Example #20
Source File: WindowsRootPaneUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public boolean postProcessKeyEvent(KeyEvent ev) {
    if(ev.isConsumed() && ev.getKeyCode() != KeyEvent.VK_ALT) {
        // mnemonic combination, it's consumed, but we need
        // set altKeyPressed to false, otherwise after selection
        // component by mnemonic combination a menu will be open
        altKeyPressed = false;
        return false;
    }
    if (ev.getKeyCode() == KeyEvent.VK_ALT) {
        root = SwingUtilities.getRootPane(ev.getComponent());
        winAncestor = (root == null ? null :
                SwingUtilities.getWindowAncestor(root));

        if (ev.getID() == KeyEvent.KEY_PRESSED) {
            if (!altKeyPressed) {
                altPressed(ev);
            }
            altKeyPressed = true;
            return true;
        } else if (ev.getID() == KeyEvent.KEY_RELEASED) {
            if (altKeyPressed) {
                altReleased(ev);
            } else {
                MenuSelectionManager msm =
                    MenuSelectionManager.defaultManager();
                MenuElement[] path = msm.getSelectedPath();
                if (path.length <= 0) {
                    WindowsLookAndFeel.setMnemonicHidden(true);
                    WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
                }
            }
            altKeyPressed = false;
        }
        root = null;
        winAncestor = null;
    } else {
        altKeyPressed = false;
    }
    return false;
}
 
Example #21
Source File: WindowsRootPaneUI.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
 
Example #22
Source File: MotifMenuMouseListener.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void mouseReleased(MouseEvent e) {
    MenuSelectionManager.defaultManager().processMouseEvent(e);
}
 
Example #23
Source File: MotifMenuMouseMotionListener.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void mouseMoved(MouseEvent e) {
    MenuSelectionManager.defaultManager().processMouseEvent(e);
}
 
Example #24
Source File: MotifMenuMouseListener.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void mouseReleased(MouseEvent e) {
    MenuSelectionManager.defaultManager().processMouseEvent(e);
}
 
Example #25
Source File: WindowsRootPaneUI.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
void altReleased(KeyEvent ev) {
    if (menuCanceledOnPress) {
        WindowsLookAndFeel.setMnemonicHidden(true);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        return;
    }

    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    if (msm.getSelectedPath().length == 0) {
        // if no menu is active, we try activating the menubar

        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;

        // It might happen that the altRelease event is processed
        // with a reasonable delay since it has been generated.
        // Here we check the last deactivation time of the containing
        // window. If this time appears to be greater than the altRelease
        // event time the event is skipped to avoid unexpected menu
        // activation. See 7121442.
        // Also we must ensure that original source of key event belongs
        // to the same window object as winAncestor. See 8001633.
        boolean skip = false;
        Toolkit tk = Toolkit.getDefaultToolkit();
        if (tk instanceof SunToolkit) {
            Component originalSource = AWTAccessor.getKeyEventAccessor()
                    .getOriginalSource(ev);
            skip = SunToolkit.getContainingWindow(originalSource) != winAncestor ||
                    ev.getWhen() <= ((SunToolkit) tk).getWindowDeactivationTime(winAncestor);
        }

        if (menu != null && !skip) {
            MenuElement[] path = new MenuElement[2];
            path[0] = mbar;
            path[1] = menu;
            msm.setSelectedPath(path);
        } else if(!WindowsLookAndFeel.isMnemonicHidden()) {
            WindowsLookAndFeel.setMnemonicHidden(true);
            WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        }
    } else {
        if((msm.getSelectedPath())[0] instanceof ComboPopup) {
            WindowsLookAndFeel.setMnemonicHidden(true);
            WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        }
    }

}
 
Example #26
Source File: MotifMenuMouseListener.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void mouseReleased(MouseEvent e) {
    MenuSelectionManager.defaultManager().processMouseEvent(e);
}
 
Example #27
Source File: WindowsRootPaneUI.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
void altReleased(KeyEvent ev) {
    if (menuCanceledOnPress) {
        WindowsLookAndFeel.setMnemonicHidden(true);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        return;
    }

    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    if (msm.getSelectedPath().length == 0) {
        // if no menu is active, we try activating the menubar

        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;

        // It might happen that the altRelease event is processed
        // with a reasonable delay since it has been generated.
        // Here we check the last deactivation time of the containing
        // window. If this time appears to be greater than the altRelease
        // event time the event is skipped to avoid unexpected menu
        // activation. See 7121442.
        // Also we must ensure that original source of key event belongs
        // to the same window object as winAncestor. See 8001633.
        boolean skip = false;
        Toolkit tk = Toolkit.getDefaultToolkit();
        if (tk instanceof SunToolkit) {
            Component originalSource = AWTAccessor.getKeyEventAccessor()
                    .getOriginalSource(ev);
            skip = SunToolkit.getContainingWindow(originalSource) != winAncestor ||
                    ev.getWhen() <= ((SunToolkit) tk).getWindowDeactivationTime(winAncestor);
        }

        if (menu != null && !skip) {
            MenuElement[] path = new MenuElement[2];
            path[0] = mbar;
            path[1] = menu;
            msm.setSelectedPath(path);
        } else if(!WindowsLookAndFeel.isMnemonicHidden()) {
            WindowsLookAndFeel.setMnemonicHidden(true);
            WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        }
    } else {
        if((msm.getSelectedPath())[0] instanceof ComboPopup) {
            WindowsLookAndFeel.setMnemonicHidden(true);
            WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        }
    }

}
 
Example #28
Source File: WindowsRootPaneUI.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
void altReleased(KeyEvent ev) {
    if (menuCanceledOnPress) {
        WindowsLookAndFeel.setMnemonicHidden(true);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        return;
    }

    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    if (msm.getSelectedPath().length == 0) {
        // if no menu is active, we try activating the menubar

        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;

        // It might happen that the altRelease event is processed
        // with a reasonable delay since it has been generated.
        // Here we check the last deactivation time of the containing
        // window. If this time appears to be greater than the altRelease
        // event time the event is skipped to avoid unexpected menu
        // activation. See 7121442.
        // Also we must ensure that original source of key event belongs
        // to the same window object as winAncestor. See 8001633.
        boolean skip = false;
        Toolkit tk = Toolkit.getDefaultToolkit();
        if (tk instanceof SunToolkit) {
            Component originalSource = AWTAccessor.getKeyEventAccessor()
                    .getOriginalSource(ev);
            skip = SunToolkit.getContainingWindow(originalSource) != winAncestor ||
                    ev.getWhen() <= ((SunToolkit) tk).getWindowDeactivationTime(winAncestor);
        }

        if (menu != null && !skip) {
            MenuElement[] path = new MenuElement[2];
            path[0] = mbar;
            path[1] = menu;
            msm.setSelectedPath(path);
        } else if(!WindowsLookAndFeel.isMnemonicHidden()) {
            WindowsLookAndFeel.setMnemonicHidden(true);
            WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        }
    } else {
        if((msm.getSelectedPath())[0] instanceof ComboPopup) {
            WindowsLookAndFeel.setMnemonicHidden(true);
            WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        }
    }

}
 
Example #29
Source File: MotifMenuMouseListener.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void mouseReleased(MouseEvent e) {
    MenuSelectionManager.defaultManager().processMouseEvent(e);
}
 
Example #30
Source File: MotifMenuMouseMotionListener.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void mouseDragged(MouseEvent e) {
    MenuSelectionManager.defaultManager().processMouseEvent(e);
}