List of usage examples for javax.swing JMenuItem getIcon
public Icon getIcon()
From source file:com.opendoorlogistics.studio.AppFrame.java
private void initMenus() { final JMenuBar menuBar = new JMenuBar(); class AddSpace { void add() { JMenu dummy = new JMenu(); dummy.setEnabled(false);/*w w w.ja v a 2 s . co m*/ menuBar.add(dummy); } } AddSpace addSpace = new AddSpace(); // add file menu ... build on the fly for recent files.. setJMenuBar(menuBar); final JMenu mnFile = new JMenu("File"); mnFile.setMnemonic('F'); mnFile.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { initFileMenu(mnFile); } @Override public void menuDeselected(MenuEvent e) { // TODO Auto-generated method stub } @Override public void menuCanceled(MenuEvent e) { // TODO Auto-generated method stub } }); initFileMenu(mnFile); menuBar.add(mnFile); addSpace.add(); // add edit menu JMenu mnEdit = new JMenu("Edit"); mnEdit.setMnemonic('E'); menuBar.add(mnEdit); addSpace.add(); for (MyAction action : editActions) { JMenuItem item = mnEdit.add(action); if (action.accelerator != null) { item.setAccelerator(action.accelerator); } } // add run scripts menu (hidden until a datastore is loaded) mnScripts = new JMenu("Run script"); mnScripts.setMnemonic('R'); mnScripts.setVisible(false); mnScripts.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { mnScripts.removeAll(); for (final ScriptNode item : scriptsPanel.getScripts()) { if (item.isAvailable() == false) { continue; } if (item.isRunnable()) { mnScripts.add(new AbstractAction(item.getDisplayName(), item.getIcon()) { @Override public void actionPerformed(ActionEvent e) { scriptManager.executeScript(item.getFile(), item.getLaunchExecutorId()); } }); } else if (item.getChildCount() > 0) { JMenu popup = new JMenu(item.getDisplayName()); mnScripts.add(popup); for (int i = 0; i < item.getChildCount(); i++) { final ScriptNode child = (ScriptNode) item.getChildAt(i); if (child.isRunnable()) { popup.add(new AbstractAction(child.getDisplayName(), child.getIcon()) { @Override public void actionPerformed(ActionEvent e) { scriptManager.executeScript(child.getFile(), child.getLaunchExecutorId()); } }); } } } } mnScripts.validate(); } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); menuBar.add(mnScripts); addSpace.add(); // add create script menu menuBar.add(initCreateScriptsMenu()); addSpace.add(); // add window menu JMenu mnWindow = new JMenu("Window"); mnWindow.setMnemonic('W'); menuBar.add(mnWindow); addSpace.add(); initWindowMenus(mnWindow); menuBar.add(initHelpMenu()); addSpace.add(); }
From source file:net.sf.jabref.gui.JabRefFrame.java
/** * Creates icons for the disabled state for all JMenuItems with FontBasedIcons in the given menuElement. * This is necessary as Swing is not able to generate default disabled icons for font based icons. * * @param menuElement the menuElement for which disabled icons should be generated *///from www . j a va 2 s . c om public void createDisabledIconsForMenuEntries(MenuElement menuElement) { for (MenuElement subElement : menuElement.getSubElements()) { if ((subElement instanceof JMenu) || (subElement instanceof JPopupMenu)) { createDisabledIconsForMenuEntries(subElement); } else if (subElement instanceof JMenuItem) { JMenuItem item = (JMenuItem) subElement; if (item.getIcon() instanceof IconTheme.FontBasedIcon) { item.setDisabledIcon(((IconTheme.FontBasedIcon) item.getIcon()).createDisabledIcon()); } } } }
From source file:org.kepler.gui.MenuMapper.java
/** * Recurse through all the submenu heirarchy beneath the passed JMenu * parameter, and for each "leaf node" (ie a menu item that is not a * container for other menu items), add the Action and its menu path to the * passed Map//from w ww .j a v a 2 s. com * * @param nextMenuItem * the JMenu to recurse into * @param menuPathBuff * a delimited String representation of the hierarchical "path" * to this menu item. This will be used as the key in the * actionsMap. For example, the "Graph Editor" menu item beneath * the "New" item on the "File" menu would have a menuPath of * File->New->Graph Editor. Delimeter is "->" (no quotes), and * spaces are allowed within menu text strings, but not around * the delimiters; i.e: New->Graph Editor is OK, but File ->New * is not. * @param MENU_PATH_DELIMITER * String * @param actionsMap * the Map containing key => value pairs of the form: menuPath * (as described above) => Action (the javax.swing.Action * assigned to this menu item) */ public static void storePTIIMenuItems(JMenuItem nextMenuItem, StringBuffer menuPathBuff, final String MENU_PATH_DELIMITER, Map<String, Action> actionsMap) { menuPathBuff.append(MENU_PATH_DELIMITER); if (nextMenuItem != null && nextMenuItem.getText() != null) { String str = nextMenuItem.getText(); // do not make the recent files menu item upper case since // it contains paths in the file system. if (menuPathBuff.toString().startsWith("FILE->RECENT FILES->")) { menuPathBuff = new StringBuffer("File->Recent Files->"); } else { str = str.toUpperCase(); } menuPathBuff.append(str); } if (isDebugging) { log.debug(menuPathBuff.toString()); } // System.out.println(menuPathBuff.toString()); if (nextMenuItem instanceof JMenu) { storePTIITopLevelMenus((JMenu) nextMenuItem, menuPathBuff.toString(), MENU_PATH_DELIMITER, actionsMap); } else { Action nextAction = nextMenuItem.getAction(); // if there is no Action, look for an ActionListener // System.out.println("Processing menu " + nextMenuItem.getText()); if (nextAction == null) { final ActionListener[] actionListeners = nextMenuItem.getActionListeners(); // System.out.println("No Action for " + nextMenuItem.getText() // + "; found " + actionListeners.length // + " ActionListeners"); if (actionListeners.length > 0) { if (isDebugging) { log.debug(actionListeners[0].getClass().getName()); } // ASSUMPTION: there is only one ActionListener nextAction = new AbstractAction() { public void actionPerformed(ActionEvent a) { actionListeners[0].actionPerformed(a); } }; // add all these values - @see diva.gui.GUIUtilities nextAction.putValue(Action.NAME, nextMenuItem.getText()); // System.out.println("storing ptII action for menu " + // nextMenuItem.getText()); nextAction.putValue(GUIUtilities.LARGE_ICON, nextMenuItem.getIcon()); nextAction.putValue(GUIUtilities.MNEMONIC_KEY, new Integer(nextMenuItem.getMnemonic())); nextAction.putValue("tooltip", nextMenuItem.getToolTipText()); nextAction.putValue(GUIUtilities.ACCELERATOR_KEY, nextMenuItem.getAccelerator()); nextAction.putValue("menuItem", nextMenuItem); } else { if (isDebugging) { log.warn("No Action or ActionListener found for " + nextMenuItem.getText()); } } } if (!actionsMap.containsValue(nextAction)) { actionsMap.put(menuPathBuff.toString(), nextAction); if (isDebugging) { log.debug(menuPathBuff.toString() + " :: ACTION: " + nextAction); } } } }
From source file:org.openmicroscopy.shoola.env.ui.TaskBarView.java
/** * Makes and returns a copy of the specified item. * * @param original The item to handle./*from ww w. ja v a2s .c o m*/ * @return See above. */ private JMenuItem copyItem(JMenuItem original) { JMenuItem item = new JMenuItem(original.getAction()); item.setIcon(original.getIcon()); item.setText(original.getText()); item.setToolTipText(original.getToolTipText()); ActionListener[] al = original.getActionListeners(); for (int j = 0; j < al.length; j++) item.addActionListener(al[j]); return item; }