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());
}
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;
}
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;
}
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;
}
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;
}
Aggregations