Search in sources :

Example 61 with JMenuItem

use of javax.swing.JMenuItem in project omegat by omegat-org.

the class PropertiesShortcutsTest method testBindKeyStrokesJMenuBar.

/**
 * Test of bindKeyStrokes method, of class PropertiesShortcuts.
 */
@Test
public void testBindKeyStrokesJMenuBar() {
    JMenuBar menu = new JMenuBar();
    JMenu parent = new JMenu();
    JMenuItem child1 = new JMenu();
    JMenuItem child2 = new JMenuItem();
    child2.setActionCommand(TEST_DELETE);
    child2.setAccelerator(CTRL_D);
    JMenuItem grandchild1 = new JMenuItem();
    grandchild1.setActionCommand(TEST_USER_1);
    JMenuItem grandchild2 = new JMenuItem();
    grandchild2.setActionCommand(OUT_OF_LIST);
    grandchild2.setAccelerator(CTRL_X);
    menu.add(parent);
    parent.add(child1);
    parent.add(child2);
    child1.add(grandchild1);
    child1.add(grandchild2);
    // bind
    shortcuts.bindKeyStrokes(menu);
    assertNull(parent.getAccelerator());
    assertNull(child1.getAccelerator());
    assertNull(child2.getAccelerator());
    assertEquals(CTRL_P, grandchild1.getAccelerator());
    assertEquals(CTRL_X, grandchild2.getAccelerator());
}
Also used : JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu) Test(org.junit.Test)

Example 62 with JMenuItem

use of javax.swing.JMenuItem in project jgnash by ccavanaugh.

the class ActionParser method createMenuItem.

private JMenuItem createMenuItem(final ActionNode node) {
    JMenuItem menu;
    Action a = actionMap.get(node.idref);
    if (node.size() > 0) {
        menu = new JMenu(a);
        for (int i = 0; i < node.size(); i++) {
            ActionNode n = node.getChildAt(i);
            if (n.id == null && n.idref == null) {
                // detect a separator
                ((JMenu) menu).addSeparator();
            } else {
                JMenuItem item = createMenuItem(n);
                menu.add(item);
            }
        }
    } else {
        if (node.type == null || node.type.isEmpty()) {
            menu = new JMenuItem(a);
        } else {
            switch(node.type) {
                case "single":
                    menu = new JCheckBoxMenuItem(a);
                    break;
                case "toggle":
                    menu = new JRadioButtonMenuItem(a);
                    if (node.group != null) {
                        // create a group
                        ButtonGroup bGroup;
                        if (buttonGroups.get(node.group) != null) {
                            bGroup = buttonGroups.get(node.group);
                        } else {
                            bGroup = new ButtonGroup();
                            buttonGroups.put(node.group, bGroup);
                        }
                        bGroup.add(menu);
                    }
                    break;
                default:
                    menu = new JMenuItem(a);
                    break;
            }
        }
    }
    menuItemMap.put(node.idref, menu);
    // store the idref in the JMenuItem
    menu.putClientProperty(ID_REF_ATTRIBUTE, node.idref);
    return menu;
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ButtonGroup(javax.swing.ButtonGroup) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 63 with JMenuItem

use of javax.swing.JMenuItem in project jgnash by ccavanaugh.

the class ActionParser method createMenuBar.

public JMenuBar createMenuBar(final String id) {
    JMenuBar menuBar = new JMenuBar();
    Object o = actionTrees.get(id);
    if (o != null) {
        ActionNode node = (ActionNode) o;
        for (int i = 0; i < node.size(); i++) {
            JMenuItem item = createMenuItem(node.getChildAt(i));
            if (item instanceof JMenu) {
                menuBar.add((JMenu) item);
            } else {
                log.log(Level.WARNING, "{0} invalid", item.toString());
            }
        }
    } else {
        log.log(Level.WARNING, "{0} not found", id);
    }
    return menuBar;
}
Also used : JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 64 with JMenuItem

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

the class MetalworksFrame method buildHelpMenu.

protected JMenu buildHelpMenu() {
    JMenu help = new JMenu("Help");
    JMenuItem about = new JMenuItem("About Metalworks...");
    JMenuItem openHelp = new JMenuItem("Open Help Window");
    about.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            showAboutBox();
        }
    });
    openHelp.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            openHelpWindow();
        }
    });
    help.add(about);
    help.add(openHelp);
    return help;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 65 with JMenuItem

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

the class MetalworksFrame method buildFileMenu.

protected JMenu buildFileMenu() {
    JMenu file = new JMenu("File");
    JMenuItem newWin = new JMenuItem("New");
    JMenuItem open = new JMenuItem("Open");
    JMenuItem quit = new JMenuItem("Quit");
    newWin.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            newDocument();
        }
    });
    open.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            openDocument();
        }
    });
    quit.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            quit();
        }
    });
    file.add(newWin);
    file.add(open);
    file.addSeparator();
    file.add(quit);
    return file;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Aggregations

JMenuItem (javax.swing.JMenuItem)1130 ActionEvent (java.awt.event.ActionEvent)559 ActionListener (java.awt.event.ActionListener)464 JMenu (javax.swing.JMenu)369 JPopupMenu (javax.swing.JPopupMenu)225 JMenuBar (javax.swing.JMenuBar)103 AbstractAction (javax.swing.AbstractAction)90 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)76 ArrayList (java.util.ArrayList)71 JPanel (javax.swing.JPanel)70 Point (java.awt.Point)65 JSeparator (javax.swing.JSeparator)63 File (java.io.File)61 JLabel (javax.swing.JLabel)61 BorderLayout (java.awt.BorderLayout)57 JButton (javax.swing.JButton)54 Component (java.awt.Component)53 ButtonGroup (javax.swing.ButtonGroup)50 Dimension (java.awt.Dimension)46 MouseEvent (java.awt.event.MouseEvent)45