Search in sources :

Example 51 with JMenuBar

use of javax.swing.JMenuBar in project jdk8u_jdk by JetBrains.

the class Test8013370 method run.

@Override
public void run() {
    if (this.frame == null) {
        JMenuBar menu = new JMenuBar() {

            @Override
            protected boolean processKeyBinding(KeyStroke stroke, KeyEvent event, int condition, boolean pressed) {
                if (stroke == null) {
                    Test8013370.this.error = true;
                    return false;
                }
                return super.processKeyBinding(stroke, event, condition, pressed);
            }
        };
        menu.add(new JMenuItem("Menu"));
        InputMap map = menu.getInputMap(WHEN_IN_FOCUSED_WINDOW);
        // from a array to a hashtable when more than 8 values are added.
        for (int i = 0; i < 9; i++) {
            String name = " Action #" + i;
            map.put(KeyStroke.getKeyStroke(KeyEvent.VK_A + i, CTRL_DOWN_MASK), name);
            menu.getActionMap().put(name, new AbstractAction(name) {

                @Override
                public void actionPerformed(ActionEvent event) {
                    showMessageDialog(null, getValue(NAME));
                }
            });
        }
        this.frame = new JFrame("8013370");
        this.frame.setJMenuBar(menu);
        this.frame.setVisible(true);
    } else {
        this.frame.dispose();
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent) JFrame(javax.swing.JFrame) ActionEvent(java.awt.event.ActionEvent) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JMenuBar(javax.swing.JMenuBar)

Example 52 with JMenuBar

use of javax.swing.JMenuBar in project processdash by dtuma.

the class AbstractCustomProcessEditor method buildMenuBar.

private JMenuBar buildMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menuBar.add(menu);
    menu.add(newMenuItem = new JMenuItem("New"));
    newMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            stopEditing(frame);
            newProcess();
        }
    });
    menu.add(openMenuItem = new JMenuItem("Open..."));
    openMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            stopEditing(frame);
            openProcess();
        }
    });
    menu.add(saveMenuItem = new JMenuItem("Save..."));
    saveMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            stopEditing(frame);
            save();
        }
    });
    menu.add(closeMenuItem = new JMenuItem("Close"));
    closeMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            stopEditing(frame);
            confirmClose(true);
        }
    });
    return menuBar;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 53 with JMenuBar

use of javax.swing.JMenuBar in project processdash by dtuma.

the class ShowGlobalGroupFilterSelector method getMainGroupFilterMenu.

private GroupFilterMenu getMainGroupFilterMenu() {
    ProcessDashboard dash = (ProcessDashboard) getDashboardContext();
    JMenuBar menuBar = dash.getConfigurationMenus();
    for (int i = menuBar.getMenuCount(); i-- > 0; ) {
        Object item = menuBar.getMenu(i);
        if (item instanceof GroupFilterMenu)
            return (GroupFilterMenu) item;
    }
    return null;
}
Also used : ProcessDashboard(net.sourceforge.processdash.ProcessDashboard) JMenuBar(javax.swing.JMenuBar)

Example 54 with JMenuBar

use of javax.swing.JMenuBar in project processdash by dtuma.

the class SimulationHarness method selectNode.

public void selectNode(String node) {
    String[] path = node.split("/");
    JMenuBar menuBar = getHierarchyMenuBar();
    for (int i = 0; i < path.length; i++) {
        JMenu menu = menuBar.getMenu(i);
        int j = 0;
        for (; j < menu.getMenuComponentCount(); j++) {
            JMenuItem menuItem = menu.getItem(i);
            if (path[i].equals(menuItem.getText())) {
                menuItem.doClick();
                uiDelay();
                break;
            }
        }
        if (j == menu.getMenuComponentCount())
            throw new IllegalStateException("Could not select node " + node);
    }
}
Also used : JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 55 with JMenuBar

use of javax.swing.JMenuBar in project cayenne by apache.

the class OSXPlatformInitializer method setupMenus.

public void setupMenus(JFrame frame) {
    // set additional look and feel for the window
    frame.getRootPane().putClientProperty("apple.awt.brushMetalLook", Boolean.TRUE);
    Set<Action> removeActions = new HashSet<>();
    removeActions.add(actionManager.getAction(ExitAction.class));
    removeActions.add(actionManager.getAction(AboutAction.class));
    removeActions.add(actionManager.getAction(ConfigurePreferencesAction.class));
    JMenuBar menuBar = frame.getJMenuBar();
    for (Component menu : menuBar.getComponents()) {
        if (menu instanceof JMenu) {
            JMenu jMenu = (JMenu) menu;
            Component[] menuItems = jMenu.getPopupMenu().getComponents();
            for (int i = 0; i < menuItems.length; i++) {
                if (menuItems[i] instanceof JMenuItem) {
                    JMenuItem jMenuItem = (JMenuItem) menuItems[i];
                    if (removeActions.contains(jMenuItem.getAction())) {
                        jMenu.remove(jMenuItem);
                        // the current (as of 08.2010) menu layout
                        if (i > 0 && i == menuItems.length - 1 && menuItems[i - 1] instanceof JPopupMenu.Separator) {
                            jMenu.remove(i - 1);
                        }
                    }
                }
            }
        }
    }
}
Also used : ConfigurePreferencesAction(org.apache.cayenne.modeler.action.ConfigurePreferencesAction) ConfigurePreferencesAction(org.apache.cayenne.modeler.action.ConfigurePreferencesAction) Action(javax.swing.Action) AboutAction(org.apache.cayenne.modeler.action.AboutAction) ExitAction(org.apache.cayenne.modeler.action.ExitAction) AboutAction(org.apache.cayenne.modeler.action.AboutAction) JPopupMenu(javax.swing.JPopupMenu) ExitAction(org.apache.cayenne.modeler.action.ExitAction) Component(java.awt.Component) JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu) HashSet(java.util.HashSet)

Aggregations

JMenuBar (javax.swing.JMenuBar)119 JMenu (javax.swing.JMenu)83 JMenuItem (javax.swing.JMenuItem)45 ActionEvent (java.awt.event.ActionEvent)36 ActionListener (java.awt.event.ActionListener)30 JPanel (javax.swing.JPanel)28 BoxLayout (javax.swing.BoxLayout)25 Dimension (java.awt.Dimension)23 JFrame (javax.swing.JFrame)17 JScrollPane (javax.swing.JScrollPane)15 JLabel (javax.swing.JLabel)14 JButton (javax.swing.JButton)13 JmriJFrame (jmri.util.JmriJFrame)12 GridBagLayout (java.awt.GridBagLayout)11 BorderLayout (java.awt.BorderLayout)10 JSeparator (javax.swing.JSeparator)10 AbstractAction (javax.swing.AbstractAction)9 FlowLayout (java.awt.FlowLayout)6 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)6 JPopupMenu (javax.swing.JPopupMenu)6