List of usage examples for javax.swing JMenuItem setActionCommand
public void setActionCommand(String actionCommand)
From source file:org.omegat.gui.shortcuts.PropertiesShortcutsTest.java
/** * Test of bindKeyStrokes method, of class PropertiesShortcuts. *///from ww w . j av a2 s. c o m @Test public void testBindKeyStrokes_JMenuItem_Recursive() { // case JMenu with children 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); parent.add(child1); parent.add(child2); child1.add(grandchild1); child1.add(grandchild2); // bind shotcuts.bindKeyStrokes(parent); KeyStroke result = parent.getAccelerator(); assertNull(result); result = child1.getAccelerator(); assertNull(result); result = child2.getAccelerator(); assertNull(result); KeyStroke expected = CTRL_P; result = grandchild1.getAccelerator(); assertEquals(expected, result); expected = CTRL_X; result = grandchild2.getAccelerator(); assertEquals(expected, result); }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.AnnotationDataUI.java
/** * Creates the selection menu.//from ww w . j a va2s .c om * * @return See above. */ private JPopupMenu createDocSelectionMenu() { if (docSelectionMenu != null) return docSelectionMenu; docSelectionMenu = new JPopupMenu(); JMenuItem item = new JMenuItem("Local document..."); item.setToolTipText("Import a local document to the server " + "and attach it."); item.addActionListener(controller); item.setActionCommand("" + EditorControl.ADD_LOCAL_DOCS); docSelectionMenu.add(item); item = new JMenuItem("Uploaded document..."); item.setToolTipText("Attach a document already uploaded " + "to the server."); item.addActionListener(controller); item.setActionCommand("" + EditorControl.ADD_UPLOADED_DOCS); docSelectionMenu.add(item); return docSelectionMenu; }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java
/** * Creates or recycles the menu.//from ww w . j av a 2 s .c o m * * @param invoker The component invoking the menu. * @param loc The location of the mouse clicked. */ private void showViewMenu(JComponent invoker, Point loc) { if (viewMenu == null) { viewMenu = new JPopupMenu(); IconManager icons = IconManager.getInstance(); JMenuItem button = new JMenuItem(icons.getIcon(IconManager.VIEW)); button.setText(ViewAction.NAME); button.setToolTipText(ViewAction.DESCRIPTION); button.setActionCommand("" + EditorControl.VIEW_IMAGE); button.addActionListener(controller); viewMenu.add(button); button = new JMenuItem(icons.getIcon(IconManager.VIEWER_IJ)); button.setText(ViewAction.NAME_IJ); button.setToolTipText(ViewAction.DESCRIPTION_IJ); button.setActionCommand("" + EditorControl.VIEW_IMAGE_IN_IJ); button.addActionListener(controller); viewMenu.add(button); } viewMenu.show(invoker, loc.x, loc.y); }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.ToolBar.java
/** Creates or recycles the save as menu. */ private JPopupMenu createSaveAsMenu() { saveAsMenu = new JPopupMenu(); IconManager icons = IconManager.getInstance(); downloadItem = new JMenuItem(icons.getIcon(IconManager.DOWNLOAD)); downloadItem.setToolTipText("Download the Archived File(s)."); downloadItem.setText("Download..."); downloadItem.addActionListener(controller); downloadItem.setActionCommand("" + EditorControl.DOWNLOAD); downloadItem.setBackground(UIUtilities.BACKGROUND_COLOR); List<DataObject> nodes = model.getSelectedObjects(); boolean b = false; if (!CollectionUtils.isEmpty(nodes)) { Iterator<DataObject> i = nodes.iterator(); while (i.hasNext()) { if (model.isArchived(i.next())) { b = true;/* w w w .j av a 2 s . c o m*/ break; } } } downloadItem.setEnabled(b); saveAsMenu.add(downloadItem); downloadOriginalMetadataItem = new JMenuItem(icons.getIcon(IconManager.DOWNLOAD)); downloadOriginalMetadataItem.setToolTipText("Download the " + "metadata read from the image files."); downloadOriginalMetadataItem.setText("Download Original metadata..."); downloadOriginalMetadataItem.addActionListener(controller); downloadOriginalMetadataItem.setActionCommand("" + EditorControl.DOWNLOAD_METADATA); downloadOriginalMetadataItem.setBackground(UIUtilities.BACKGROUND_COLOR); downloadOriginalMetadataItem.setEnabled(model.hasOriginalMetadata()); saveAsMenu.add(downloadOriginalMetadataItem); exportAsOmeTiffItem = new JMenuItem(icons.getIcon(IconManager.EXPORT_AS_OMETIFF)); exportAsOmeTiffItem.setText("Export as OME-TIFF..."); exportAsOmeTiffItem.setToolTipText(EXPORT_AS_OME_TIFF_TOOLTIP); exportAsOmeTiffItem.addActionListener(controller); exportAsOmeTiffItem.setActionCommand("" + EditorControl.EXPORT_AS_OMETIFF); if (model.isMultiSelection()) b = false; else { b = model.getRefObject() instanceof ImageData && !model.isLargeImage(); } exportAsOmeTiffItem.setEnabled(b); saveAsMenu.add(exportAsOmeTiffItem); JMenu menu = new JMenu(); menu.setIcon(icons.getIcon(IconManager.SAVE_AS)); menu.setText("Save as..."); menu.setToolTipText("Save the images at full size as JPEG. PNG or" + "TIFF."); ActionListener l = new ActionListener() { public void actionPerformed(ActionEvent e) { int index = Integer.parseInt(e.getActionCommand()); controller.saveAs(index); } }; Map<Integer, String> formats = FigureParam.FORMATS; Entry<Integer, String> e; Iterator<Entry<Integer, String>> i = formats.entrySet().iterator(); JMenuItem item; Object ho = model.getRefObject(); boolean enabled = (ho instanceof ImageData || ho instanceof WellSampleData || ho instanceof DatasetData); while (i.hasNext()) { e = i.next(); item = new JMenuItem(); item.setText(e.getValue()); item.addActionListener(l); item.setActionCommand("" + e.getKey()); item.setEnabled(enabled); menu.add(item); } saveAsMenu.add(menu); setRootObject(); return saveAsMenu; }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.ToolBar.java
/** * Creates or recycles the view menu./* w w w . ja v a 2s . c o m*/ * * @param source The source of the mouse event. * @param p The location of the mouse pressed. */ private void showViewMenu(Component source, Point p) { JPopupMenu menu = new JPopupMenu(); IconManager icons = IconManager.getInstance(); JMenuItem item = new JMenuItem(icons.getIcon(IconManager.VIEWER)); item.setText("View..."); item.setActionCommand("" + EditorControl.VIEW_IMAGE); item.addActionListener(controller); menu.add(item); item = new JMenuItem(icons.getIcon(IconManager.VIEWER_IJ)); item.setText("View in ImageJ..."); item.setActionCommand("" + EditorControl.VIEW_IMAGE_IN_IJ); item.addActionListener(controller); menu.add(item); menu.show(source, p.x, p.y); }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.ToolBar.java
/** * Builds the menu displaying the available scripts. * //from w w w . j a v a2 s .c o m * @return See above. */ private JPopupMenu getScriptsMenu() { JPopupMenu menu = new JPopupMenu(); Collection<ScriptObject> scripts = model.getScripts(); //Scripts are sorted. if (scripts == null || scripts.size() == 0) return menu; IconManager icons = IconManager.getInstance(); JMenuItem refresh = new JMenuItem(icons.getIcon(IconManager.REFRESH)); refresh.setText("Reload Scripts"); refresh.setToolTipText("Reloads the existing scripts."); refresh.addActionListener(controller); refresh.setActionCommand("" + EditorControl.RELOAD_SCRIPT); menu.add(refresh); menu.add(new JSeparator()); Iterator<ScriptObject> i = scripts.iterator(); ScriptObject so; Map<String, ScriptSubMenu> menus = new HashMap<String, ScriptSubMenu>(); String path; ScriptSubMenu subMenu; List<ScriptSubMenu> others = new ArrayList<ScriptSubMenu>(); List<String> formattedName = new ArrayList<String>(); while (i.hasNext()) { so = i.next(); setScriptIcon(so); path = so.getPath(); subMenu = menus.get(path); if (subMenu == null) { subMenu = new ScriptSubMenu(path, formattedName); //formattedName.add(subMenu.getUnformattedText()); menus.put(path, subMenu); if (so.isOfficialScript()) menu.add(subMenu); else others.add(subMenu); } //if (!ScriptMenuItem.isScriptWithUI(so.getScriptLabel())) subMenu.addScript(so).addActionListener(controller); } if (others.size() > 0) { menu.add(new JSeparator()); JMenu uploadedMenu = new JMenu("User Scripts"); menu.add(uploadedMenu); Iterator<ScriptSubMenu> j = others.iterator(); while (j.hasNext()) uploadedMenu.add(j.next()); } return menu; }
From source file:org.openscience.jmol.app.Jmol.java
/** * This is the hook through which all menu items are * created. It registers the result with the menuitem * hashtable so that it can be fetched with getMenuItem(). * @param cmd//from ww w . j a va 2s . c o m * @return Menu item created * @see #getMenuItem */ protected JMenuItem createMenuItem(String cmd) { JMenuItem mi; if (cmd.endsWith("Check")) { mi = guimap.newJCheckBoxMenuItem(cmd, false); } else { mi = guimap.newJMenuItem(cmd); } ImageIcon f = JmolResourceHandler.getIconX(cmd + "Image"); if (f != null) { mi.setHorizontalTextPosition(SwingConstants.RIGHT); mi.setIcon(f); } if (cmd.endsWith("Script")) { mi.setActionCommand(JmolResourceHandler.getStringX(cmd)); mi.addActionListener(executeScriptAction); } else { mi.setActionCommand(cmd); Action a = getAction(cmd); if (a != null) { mi.addActionListener(a); a.addPropertyChangeListener(new ActionChangedListener(mi)); mi.setEnabled(a.isEnabled()); } else { mi.setEnabled(false); } } menuItems.put(cmd, mi); return mi; }
From source file:org.openscience.jmol.app.Jmol.java
protected void addMacrosMenuBar(JMenuBar menuBar) { // ok, here needs to be added the funny stuff JMenu macroMenu = guimap.newJMenu("macros"); File macroDir = new File(System.getProperty("user.home") + System.getProperty("file.separator") + ".jmol" + System.getProperty("file.separator") + "macros"); report("User macros dir: " + macroDir); report(" exists: " + macroDir.exists()); report(" isDirectory: " + macroDir.isDirectory()); if (macroDir.exists() && macroDir.isDirectory()) { File[] macros = macroDir.listFiles(); for (int i = 0; i < macros.length; i++) { // loop over these files and load them String macroName = macros[i].getName(); if (macroName.endsWith(".macro")) { if (Logger.debugging) { Logger.debug("Possible macro found: " + macroName); }// w ww . ja v a 2 s .c om FileInputStream macro = null; try { macro = new FileInputStream(macros[i]); Properties macroProps = new Properties(); macroProps.load(macro); String macroTitle = macroProps.getProperty("Title"); String macroScript = macroProps.getProperty("Script"); JMenuItem mi = new JMenuItem(macroTitle); mi.setActionCommand(macroScript); mi.addActionListener(executeScriptAction); macroMenu.add(mi); } catch (IOException exception) { System.err.println("Could not load macro file: "); System.err.println(exception); } finally { if (macro != null) { try { macro.close(); } catch (IOException e) { // Nothing } macro = null; } } } } } menuBar.add(macroMenu); }
From source file:org.orbisgis.mapeditor.map.mapsManager.TreeLeafMapContextFile.java
@Override public void feedPopupMenu(JPopupMenu menu) { super.feedPopupMenu(menu); if (!isLoaded()) { JMenuItem folderRemove = new JMenuItem(I18N.tr("Delete"), MapEditorIcons.getIcon("remove")); folderRemove.setToolTipText(I18N.tr("Remove permanently the map")); folderRemove.setActionCommand("delete"); folderRemove.addActionListener(EventHandler.create(ActionListener.class, this, "onDeleteFile")); MenuCommonFunctions.updateOrInsertMenuItem(menu, folderRemove); }/*from w w w . jav a 2 s . co m*/ }
From source file:org.orbisgis.sif.components.fstree.FileTree.java
/** * Fetch all selected items to make a pop-up menu * @return /* w w w . j av a 2s. com*/ */ private JPopupMenu makePopupMenu() { JPopupMenu menu = new JPopupMenu(); TreePath[] paths = getSelectionPaths(); if (paths != null) { // Generic action on single TreeNode if (paths.length == 1) { Object component = paths[0].getLastPathComponent(); if (component instanceof AbstractTreeNode) { AbstractTreeNode aTreeNode = (AbstractTreeNode) component; if (aTreeNode.isEditable()) { JMenuItem editMenu = new JMenuItem(I18N.tr("Rename")); editMenu.addActionListener(EventHandler.create(ActionListener.class, this, "onRenameItem")); editMenu.setActionCommand("rename"); menu.add(editMenu); } } } for (TreePath treePath : paths) { Object component = treePath.getLastPathComponent(); // All nodes if (component instanceof MutableTreeNode) { MutableTreeNode node = (MutableTreeNode) component; for (TreeNodeFileFactory fact : getFactories()) { fact.feedTreeNodePopupMenu(node, menu); } } // Specific nodes if (component instanceof PopupTreeNode) { PopupTreeNode treeNode = (PopupTreeNode) component; treeNode.feedPopupMenu(menu); } } } return menu; }