static @Nonnull JMenu createMenuGroupFromElement( @CheckForNull Element main, WindowInterface wi, Object context) { String name = "<none>"; if (main == null) { log.warn("Menu from element called without an element"); return new JMenu(name); } name = LocaleSelector.getAttribute(main, "name"); // Next statement left in if the xml file hasn't been converted if ((name == null) || (name.equals(""))) { if (main.getChild("name") != null) { name = main.getChild("name").getText(); } } JMenu menu = new JMenu(name); ButtonGroup group = new ButtonGroup(); for (Object item : main.getChildren("node")) { Element elem = (Element) item; Action act = actionFromNode(elem, wi, context); JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(act); group.add(menuItem); menu.add(menuItem); if (elem.getChild("current") != null) { setMenuItemInterAction(context, elem.getChild("current").getText(), menuItem); } } return menu; }
static @Nonnull JMenu jMenuFromElement( @CheckForNull Element main, WindowInterface wi, Object context) { boolean addSep = false; String name = "<none>"; if (main == null) { log.warn("Menu from element called without an element"); return new JMenu(name); } name = LocaleSelector.getAttribute(main, "name"); // Next statement left in if the xml file hasn't been converted if ((name == null) || (name.equals(""))) { if (main.getChild("name") != null) { name = main.getChild("name").getText(); } } JMenu menu = new JMenu(name); ArrayList<Integer> mnemonicList = new ArrayList<Integer>(); for (Object item : main.getChildren("node")) { JMenuItem menuItem = null; Element child = (Element) item; if (child.getChildren("node").size() == 0) { // leaf if ((child.getText().trim()).equals("separator")) { addSep = true; } else { if (!(SystemType.isMacOSX() && UIManager.getLookAndFeel().isNativeLookAndFeel() && ((child.getChild("adapter") != null && child .getChild("adapter") .getText() .equals("apps.gui3.TabbedPreferencesAction")) || (child.getChild("current") != null && child.getChild("current").getText().equals("quit"))))) { if (addSep) { menu.addSeparator(); addSep = false; } Action act = actionFromNode(child, wi, context); menu.add(menuItem = new JMenuItem(act)); } } } else { if (addSep) { menu.addSeparator(); addSep = false; } if (child.getChild("group") != null && child.getChild("group").getText().equals("yes")) { // A seperate method is required for creating radio button groups menu.add(createMenuGroupFromElement(child, wi, context)); } else { menu.add(menuItem = jMenuFromElement(child, wi, context)); // not leaf } } if (menuItem != null && child.getChild("current") != null) { setMenuItemInterAction(context, child.getChild("current").getText(), menuItem); } if (menuItem != null && child.getChild("mnemonic") != null) { int mnemonic = convertStringToKeyEvent(child.getChild("mnemonic").getText()); if (mnemonicList.contains(mnemonic)) { log.error( "Menu Item '" + menuItem.getText() + "' Mnemonic '" + child.getChild("mnemonic").getText() + "' has already been assigned"); } else { menuItem.setMnemonic(mnemonic); mnemonicList.add(mnemonic); } } } return menu; }