Package javax.swing

Examples of javax.swing.MenuSelectionManager



public class BasicMenuItemUI extends MenuItemUI {
    protected class MouseInputHandler implements MouseInputListener {
        public void mouseEntered(final MouseEvent e) {
            final MenuSelectionManager manager = MenuSelectionManager.defaultManager();
            if (openMenuTimer != null) {
                openMenuTimer.stop();
            }
            manager.setSelectedPath(Utilities.addToPath(manager.getSelectedPath(), menuItem));
        }
View Full Code Here


            }
            manager.setSelectedPath(Utilities.addToPath(manager.getSelectedPath(), menuItem));
        }

        public void mouseExited(final MouseEvent e) {
            final MenuSelectionManager manager = MenuSelectionManager.defaultManager();
            manager.setSelectedPath(Utilities.removeFromPath(manager.getSelectedPath(), menuItem));
        }
View Full Code Here

            final MenuSelectionManager manager = MenuSelectionManager.defaultManager();
            manager.setSelectedPath(Utilities.removeFromPath(manager.getSelectedPath(), menuItem));
        }

        public void mouseReleased(final MouseEvent e) {
            MenuSelectionManager defaultManager = MenuSelectionManager.defaultManager();
            if (defaultManager.componentForPoint(e.getComponent(), e.getPoint()) == menuItem
                    || Utilities.isEmptyArray(defaultManager.getSelectedPath())) {

                doClick(defaultManager);
            } else {
                defaultManager.processMouseEvent(e);
            }
        }
View Full Code Here

        }
    }

    protected class MouseInputHandler implements MouseInputListener {
        public void mouseEntered(final MouseEvent e) {
            final MenuSelectionManager manager = MenuSelectionManager.defaultManager();
            if (!manager.isComponentPartOfCurrentMenu(menuItem)) {
                return;
            }
            if (Utilities.isEmptyArray(manager.getSelectedPath())) {
                return;
            }
            if (!menuItem.isEnabled()) {
                return;
            }
            if (openMenuTimer != null) {
                openMenuTimer.stop();
            }
            final JMenu menu = (JMenu)menuItem;
            MenuElement[] path = Utilities.addToPath(manager.getSelectedPath(), menu);
            if (menu.isTopLevelMenu()) {
                path = Utilities.addToPath(path, menu.getPopupMenu());
                manager.setSelectedPath(path);
                OPEN_POPUP_ACTION.openPopup(menu);
            } else {
                manager.setSelectedPath(path);
                setupPostTimer(menu);
            }
        }
View Full Code Here

            }
        }

        public void mousePressed(final MouseEvent e) {
            final JMenu menu = (JMenu)menuItem;
            MenuSelectionManager defaultManager = MenuSelectionManager.defaultManager();
            if (menu.isTopLevelMenu()) {
                if (Utilities.isEmptyArray(defaultManager.getSelectedPath())) {
                    defaultManager.setSelectedPath(new MenuElement[] {(JMenuBar)menu.getParent(), menu});
                    OPEN_POPUP_ACTION.openPopup(menu);
                } else {
                    defaultManager.clearSelectedPath();
                }
            }
        }
View Full Code Here

                }
            }
        }

        public void mouseReleased(final MouseEvent e) {
            MenuSelectionManager defaultManager = MenuSelectionManager.defaultManager();
            if (defaultManager.componentForPoint(e.getComponent(), e.getPoint()) == null) {
                defaultManager.clearSelectedPath();
            } else {
                defaultManager.processMouseEvent(e);
            }
        }
View Full Code Here

     * Test method for 'javax.swing.event.MenuKeyEvent.getPath()'
     */
    public void testGetPath() {
        MenuElement[] path = new MenuElement[1];
        event = new MenuKeyEvent(new JMenuItem(), 1, 2, 3, 4, 'a', path,
                new MenuSelectionManager());
        assertSame(path, event.getPath());
        event = new MenuKeyEvent(new JMenuItem(), 1, 2, 3, 4, 'a', null,
                new MenuSelectionManager());
        assertSame(null, event.getPath());
    }
View Full Code Here

        menu.add(item);
        frame.getContentPane().add(menuBar);
        frame.pack();
        frame.show();
        assertEquals(0, menuItemUI.getPath().length);
        MenuSelectionManager manager = MenuSelectionManager.defaultManager();
        manager.setSelectedPath(new MenuElement[] { menuBar, menu, menu.getPopupMenu(), item });
        assertEquals(4, menuItemUI.getPath().length);
        assertSame(menuBar, menuItemUI.getPath()[0]);
        assertSame(menu, menuItemUI.getPath()[1]);
        assertSame(menu.getPopupMenu(), menuItemUI.getPath()[2]);
        assertSame(item, menuItemUI.getPath()[3]);
        manager
                .setSelectedPath(new MenuElement[] { menuBar, item2, menu2, menu.getPopupMenu() });
        assertEquals(5, menuItemUI.getPath().length);
        assertSame(menuBar, menuItemUI.getPath()[0]);
        assertSame(item2, menuItemUI.getPath()[1]);
        assertSame(menu2, menuItemUI.getPath()[2]);
        assertSame(menu.getPopupMenu(), menuItemUI.getPath()[3]);
        assertSame(item, menuItemUI.getPath()[4]);
        manager.setSelectedPath(new MenuElement[] { menuBar });
        assertEquals(1, menuItemUI.getPath().length);
        assertSame(item, menuItemUI.getPath()[0]);
        manager.clearSelectedPath();
        assertEquals(0, menuItemUI.getPath().length);
        frame.dispose();
    }
View Full Code Here

            @Override
            public void doClick(final int pressTime) {
                time = pressTime;
            }
        }
        MenuSelectionManager manager = new MenuSelectionManager();
        manager.setSelectedPath(new MenuElement[] { new JMenu(), new JMenu() });
        MyJMenuItem item = new MyJMenuItem();
        item.setUI(menuItemUI);
        menuItemUI.doClick(manager);
        assertEquals(0, manager.getSelectedPath().length);
        assertEquals(0, item.time);
    }
View Full Code Here

    /*
     * Test method for 'javax.swing.plaf.basic.BasicMenuUI.setupPostTimer(JMenu)'
     */
    @SuppressWarnings("deprecation")
    public void testSetupPostTimer() throws InterruptedException, InvocationTargetException {
        final MenuSelectionManager manager = MenuSelectionManager.defaultManager();
        JFrame frame = new JFrame();
        JMenuBar menuBar = new JMenuBar();
        final JMenu menu = new JMenu("menu");
        menu.setUI(menuUI);
        ConcretePopupListener listener = new ConcretePopupListener();
        menu.getPopupMenu().addPopupMenuListener(listener);
        menu.add(new JMenuItem("item"));
        frame.setJMenuBar(menuBar);
        menuBar.add(menu);
        final JButton button = new JButton();
        frame.getContentPane().add(button);
        frame.pack();
        frame.show();
        SwingWaitTestCase.requestFocusInWindowForComponent(button);
        manager.setSelectedPath(new MenuElement[] { menuBar });
        menu.setDelay(100);
        setupTimerAntWait(menu, menuUI, listener);
        assertFalse(listener.visible);
        manager.setSelectedPath(new MenuElement[] { menuBar, menu });
        setupTimerAntWait(menu, menuUI, listener);
        assertTrue(listener.visible);
        manager.setSelectedPath(new MenuElement[] { menuBar });
        manager.setSelectedPath(new MenuElement[] { menuBar, menu });
        menu.setDelay(10000);
        setupTimerAntWait(menu, menuUI, listener);
        assertFalse(listener.visible);
    }
View Full Code Here

TOP

Related Classes of javax.swing.MenuSelectionManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.