List of usage examples for javax.swing JMenuItem setName
public void setName(String name)
From source file:net.java.sip.communicator.impl.osdependent.jdic.TrayMenuFactory.java
/** * Changes the tray menu item properties, like name, text and icon. * @param trayItem the tray menu item to change * @param name the new name of the item/*from w ww.j a v a 2 s .c o m*/ * @param textID the new text identifier * @param iconID the new icon string identifier */ private static void changeTrayMenuItem(Object trayItem, String name, String textID, String iconID) { String text = Resources.getString(textID); if (trayItem instanceof JMenuItem) { JMenuItem jmenuItem = (JMenuItem) trayItem; jmenuItem.setName(name); jmenuItem.setText(text); jmenuItem.setIcon(Resources.getImage(iconID)); } else if (trayItem instanceof MenuItem) { MenuItem menuItem = (MenuItem) trayItem; menuItem.setName(name); menuItem.setLabel(text); } }
From source file:net.java.sip.communicator.impl.osdependent.jdic.TrayMenuFactory.java
/** * Creates a tray menu with the given <tt>name</tt>, text given by * <tt>textID</tt> and icon given by <tt>iconID</tt>. The <tt>listener</tt> * is handling item events and the <tt>swing</tt> value indicates if we * should create a Swing menu item or and an AWT item. * @param name the name of the item/*from ww w .j a v a 2 s . c om*/ * @param textID the identifier of the text in the localization resources * @param iconID the identifier of the icon in the image resources * @param listener the <tt>ActionListener</tt> handling action events * @param swing indicates if we should create a Swing menu item or an AWT * item * @return a reference to the newly created item */ private static Object createTrayMenuItem(String name, String textID, String iconID, ActionListener listener, boolean swing) { String text = Resources.getString(textID); Object trayMenuItem; if (swing) { JMenuItem menuItem = new JMenuItem(text, Resources.getImage(iconID)); menuItem.setName(name); menuItem.addActionListener(listener); trayMenuItem = menuItem; } else { MenuItem menuItem = new MenuItem(text); menuItem.setName(name); menuItem.addActionListener(listener); trayMenuItem = menuItem; } return trayMenuItem; }
From source file:org.esa.beam.visat.toolviews.stat.MaskSelectionToolSupport.java
public JMenuItem createDeleteMaskMenuItem() { final JMenuItem menuItem = new JMenuItem(String.format("Delete Mask '%s' ", maskName)); menuItem.setName("deleteMask"); menuItem.addActionListener(new ActionListener() { @Override/*from www . ja v a 2s .c o m*/ public void actionPerformed(ActionEvent e) { if (plotAreaSelectionTool != null) { plotAreaSelectionTool.removeAnnotation(); } Product product = pagePanel.getProduct(); if (product != null) { Mask mask = product.getMaskGroup().get(maskName); if (mask != null) { product.getMaskGroup().remove(mask); } } } }); return menuItem; }
From source file:com.haulmont.cuba.desktop.sys.MenuBuilder.java
private void createMenuBarItem(JMenuBar menuBar, MenuItem item) { String caption = menuConfig.getItemCaption(item.getId()); if (!item.getChildren().isEmpty() || item.isMenu()) { final JMenu jMenu = new JMenu(caption); jMenu.addMenuListener(new MenuListener() { @Override//from w w w . ja v a 2 s . c o m public void menuSelected(MenuEvent e) { jMenu.requestFocus(); } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); jMenu.setName(item.getId()); menuBar.add(jMenu); createSubMenu(jMenu, item); } else { JMenuItem jMenuItem = new JMenuItem(caption); jMenuItem.setName(item.getId()); //todo remove hardcoded border jMenuItem.setBorder(BorderFactory.createEmptyBorder(1, 4, 2, 4)); assignShortcut(jMenuItem, item); jMenuItem.setMaximumSize( new Dimension(jMenuItem.getPreferredSize().width, jMenuItem.getMaximumSize().height)); assignCommand(jMenuItem, item); menuBar.add(jMenuItem); } }
From source file:com.haulmont.cuba.desktop.sys.MenuBuilder.java
private void createSubMenu(JMenu jMenu, MenuItem item) { List<MenuItem> itemChildren = new ArrayList<>(item.getChildren()); CollectionUtils.filter(itemChildren, object -> object.isPermitted(userSession)); List<MenuItemContainer> items = new ArrayList<>(); // prepare menu items for (MenuItem child : itemChildren) { if (child.getChildren().isEmpty()) { if (child.isSeparator()) { items.add(new MenuItemContainer()); } else { JMenuItem jMenuItem = new JMenuItem(menuConfig.getItemCaption(child.getId())); jMenuItem.setName(child.getId()); assignCommand(jMenuItem, child); assignShortcut(jMenuItem, child); items.add(new MenuItemContainer(jMenuItem)); }/*from ww w . ja va 2 s .c om*/ } else { JMenu jChildMenu = new JMenu(menuConfig.getItemCaption(child.getId())); createSubMenu(jChildMenu, child); if (!isMenuEmpty(jChildMenu)) { items.add(new MenuItemContainer(jChildMenu)); } } } // remove unnecessary separators if (!items.isEmpty()) { Iterator<MenuItemContainer> iterator = items.iterator(); JMenuItem menuItem = getNextMenuItem(iterator); boolean useSeparator = false; while (menuItem != null) { if (useSeparator) jMenu.addSeparator(); jMenu.add(menuItem); useSeparator = false; menuItem = null; if (iterator.hasNext()) { MenuItemContainer itemContainer = iterator.next(); if (!itemContainer.isSeparator()) menuItem = itemContainer.getMenuItem(); else { menuItem = getNextMenuItem(iterator); useSeparator = true; } } } } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopPopupButton.java
protected void showPopup() { popup.removeAll();// w w w .ja v a 2 s . com for (final Action action : actionList) { if (action.isVisible()) { final JMenuItem menuItem = new JMenuItem(action.getCaption()); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { action.actionPerform((Component) action.getOwner()); } }); menuItem.setEnabled(action.isEnabled()); menuItem.setName(action.getId()); initAction(action, menuItem); popup.add(menuItem); } } int popupHeight = popup.getComponentCount() * 25; Point pt = new Point(); SwingUtilities.convertPointToScreen(pt, impl); int y; if (pt.getY() + impl.getHeight() + popupHeight < Toolkit.getDefaultToolkit().getScreenSize().getHeight()) { y = impl.getHeight(); } else { y = -popupHeight; } // do not show ugly empty popup if (popup.getComponentCount() > 0) { popup.show(impl, 0, y); } }
From source file:au.org.ala.delta.editor.DeltaEditor.java
private JMenuBar buildMenus() { JMenuBar menuBar = new JMenuBar(); // File menu. This on is kind of special, in that it gets rebuilt each // time a file is opened. _fileMenu = new JMenu(); _fileMenu.setName("mnuFile"); buildFileMenu(_fileMenu);// w ww . j a v a2s. com menuBar.add(_fileMenu); // Edit Menu JMenu mnuEdit = buildEditMenu(); menuBar.add(mnuEdit); // Search Menu JMenu mnuSearch = buildSearchMenu(); menuBar.add(mnuSearch); // View Menu JMenu mnuView = buildViewMenu(); menuBar.add(mnuView); // Window menu _windowMenu = new JMenu(); _windowMenu.setName("mnuWindow"); buildWindowMenu(_windowMenu); menuBar.add(_windowMenu); JMenu mnuHelp = new JMenu(); mnuHelp.setName("mnuHelp"); JMenuItem mnuItHelpContents = new JMenuItem(); mnuItHelpContents.setName("mnuItHelpContents"); mnuHelp.add(mnuItHelpContents); mnuItHelpContents.addActionListener(_helpController.helpAction()); JMenuItem mnuItHelpOnSelection = new JMenuItem(IconHelper.createImageIcon("help_cursor.png")); mnuItHelpOnSelection.setName("mnuItHelpOnSelection"); mnuItHelpOnSelection.addActionListener(_helpController.helpOnSelectionAction()); mnuHelp.add(mnuItHelpOnSelection); javax.swing.Action openAboutAction = _actionMap.get("openAbout"); if (isMac()) { configureMacAboutBox(openAboutAction); } else { JMenuItem mnuItAbout = new JMenuItem(); mnuItAbout.setAction(openAboutAction); mnuHelp.addSeparator(); mnuHelp.add(mnuItAbout); } menuBar.add(mnuHelp); return menuBar; }
From source file:au.org.ala.delta.intkey.Intkey.java
/** * Build the help menu/* www . j a v a 2 s.com*/ * * @param actionMap * The action map for the main GUI window * @return The JMenu for the help menu */ private JMenu buildHelpMenu(boolean advancedMode, ActionMap actionMap) { JMenu mnuHelp = new JMenu(); mnuHelp.setName("mnuHelp"); JMenuItem mnuItHelpTopics = new JMenuItem(); mnuItHelpTopics.setName("mnuItHelpTopics"); mnuItHelpTopics.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { UIUtils.displayHelpTopic(HELP_ID_TOPICS, getMainFrame(), e); } }); mnuHelp.add(mnuItHelpTopics); if (advancedMode) { JMenuItem mnuItHelpCommands = new JMenuItem(); mnuItHelpCommands.setName("mnuItHelpCommands"); mnuItHelpCommands.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { UIUtils.displayHelpTopic(HELP_ID_COMMANDS, getMainFrame(), e); } }); mnuHelp.add(mnuItHelpCommands); } if (isMac()) { configureMacAboutBox(actionMap.get("mnuItHelpAbout")); } else { JMenuItem mnuItAbout = new JMenuItem(); mnuItAbout.setAction(actionMap.get("mnuItHelpAbout")); mnuHelp.add(mnuItAbout); } return mnuHelp; }
From source file:au.org.ala.delta.intkey.Intkey.java
/** * Build the queries menu//from w w w .j a v a 2s.c om * * @param actionMap * The action map for the main GUI window * @return The JMenu for the queries menu */ private JMenu buildQueriesMenu(ActionMap actionMap) { // Some menus/menu items should be disabled if no dataset is loaded. boolean isDatasetLoaded = _context.getDataset() != null; JMenu mnuQueries = new JMenu(); mnuQueries.setName("mnuQueries"); JMenuItem mnuItRestart = new JMenuItem(new DirectiveAction(new RestartDirective(), _context)); mnuItRestart.setName("mnuItRestart"); mnuItRestart.setEnabled(isDatasetLoaded); mnuQueries.add(mnuItRestart); mnuQueries.addSeparator(); JMenuItem mnuItDescribe = new JMenuItem(new DirectiveAction(new DescribeDirective(), _context)); mnuItDescribe.setName("mnuItDescribe"); mnuItDescribe.setEnabled(isDatasetLoaded); mnuQueries.add(mnuItDescribe); JMenuItem mnuItDiagnose = new JMenuItem(new DirectiveAction(new DiagnoseDirective(), _context)); mnuItDiagnose.setName("mnuItDiagnose"); mnuItDiagnose.setEnabled(isDatasetLoaded); mnuQueries.add(mnuItDiagnose); mnuQueries.addSeparator(); JMenuItem mnuItDifferences = new JMenuItem(new DirectiveAction(new DifferencesDirective(), _context)); mnuItDifferences.setName("mnuItDifferences"); mnuItDifferences.setEnabled(isDatasetLoaded); mnuQueries.add(mnuItDifferences); JMenuItem mnuItSimilarities = new JMenuItem(new DirectiveAction(new SimilaritiesDirective(), _context)); mnuItSimilarities.setName("mnuItSimilarities"); mnuItSimilarities.setEnabled(isDatasetLoaded); mnuQueries.add(mnuItSimilarities); mnuQueries.addSeparator(); JMenuItem mnuItSummary = new JMenuItem(new DirectiveAction(new SummaryDirective(), _context)); mnuItSummary.setName("mnuItSummary"); mnuItSummary.setEnabled(isDatasetLoaded); mnuQueries.add(mnuItSummary); return mnuQueries; }
From source file:au.org.ala.delta.intkey.Intkey.java
/** * Build the browsing menu//from www . jav a2 s . c o m * * @param actionMap * The action map for the main GUI window * @return The JMenu for the browsing menu */ private JMenu buildBrowsingMenu(ActionMap actionMap) { // Some menus/menu items should be disabled if no dataset is loaded. boolean isDatasetLoaded = _context.getDataset() != null; JMenu mnuBrowsing = new JMenu(); mnuBrowsing.setName("mnuBrowsing"); JMenuItem mnuItCharacters = new JMenuItem(new DirectiveAction(new CharactersDirective(), _context)); mnuItCharacters.setName("mnuItCharacters"); mnuItCharacters.setEnabled(isDatasetLoaded); mnuBrowsing.add(mnuItCharacters); JMenuItem mnuItTaxa = new JMenuItem(new DirectiveAction(new TaxaDirective(), _context)); mnuItTaxa.setName("mnuItTaxa"); mnuItTaxa.setEnabled(isDatasetLoaded); mnuBrowsing.add(mnuItTaxa); mnuBrowsing.addSeparator(); JMenu mnuFind = new JMenu(); mnuFind.setName("mnuFind"); JMenuItem mnuItFindCharacters = new JMenuItem(new DirectiveAction(new FindCharactersDirective(), _context)); mnuItFindCharacters.setName("mnuItFindCharacters"); mnuItFindCharacters.setEnabled(isDatasetLoaded); mnuFind.add(mnuItFindCharacters); JMenuItem mnuItFindTaxa = new JMenuItem(new DirectiveAction(new FindTaxaDirective(), _context)); mnuItFindTaxa.setName("mnuItFindTaxa"); mnuItFindTaxa.setEnabled(isDatasetLoaded); mnuFind.setEnabled(isDatasetLoaded); mnuFind.add(mnuItFindTaxa); mnuBrowsing.add(mnuFind); mnuBrowsing.addSeparator(); JMenu mnuIllustrate = new JMenu(); mnuIllustrate.setName("mnuIllustrate"); JMenuItem mnuItIllustrateCharacters = new JMenuItem( new DirectiveAction(new IllustrateCharactersDirective(), _context)); mnuItIllustrateCharacters.setName("mnuItIllustrateCharacters"); mnuItIllustrateCharacters.setEnabled(isDatasetLoaded); mnuIllustrate.add(mnuItIllustrateCharacters); JMenuItem mnuItIllustrateTaxa = new JMenuItem(new DirectiveAction(new IllustrateTaxaDirective(), _context)); mnuItIllustrateTaxa.setName("mnuItIllustrateTaxa"); mnuItIllustrateTaxa.setEnabled(isDatasetLoaded); mnuIllustrate.setEnabled(isDatasetLoaded); mnuIllustrate.add(mnuItIllustrateTaxa); mnuBrowsing.add(mnuIllustrate); mnuBrowsing.addSeparator(); JMenuItem mnuItInformation = new JMenuItem(new DirectiveAction(new InformationDirective(), _context)); mnuItInformation.setName("mnuItInformation"); mnuItInformation.setEnabled(isDatasetLoaded); mnuBrowsing.add(mnuItInformation); return mnuBrowsing; }