Java Code Examples for javax.swing.JMenuItem#setActionCommand()
The following examples show how to use
javax.swing.JMenuItem#setActionCommand() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoginAsAdminDropDownButton.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
@Override public JPopupMenu getPopupMenu() { JPopupMenu menu = new JPopupMenu(); // add server items for (String serverName : remoteControllers.keySet()) { ConfigurableController controller = remoteControllers.get(serverName); // if the connection to the server is established if (controller.getModel().getSource().isConnected()) { if (!controller.getModel().hasAdminRights()) { JMenuItem newItem = new JMenuItem(I18N.getGUILabel("configurable_dialog.login_as_admin.small.item", serverName)); newItem.setActionCommand(serverName); newItem.addActionListener(actionListener); menu.add(newItem); } } } return menu; }
Example 2
Source File: MainWindow.java From wpcleaner with Apache License 2.0 | 6 votes |
/** * Action called when Special Lists button is pressed. */ public void actionSpecialLists() { // Create menu for special lists JPopupMenu menu = new JPopupMenu(); for (EnumQueryPage query : EnumQueryPage.values()) { JMenuItem item = new JMenuItem(query.getName()); item.setActionCommand(query.getCode()); item.addActionListener(EventHandler.create( ActionListener.class, this, "actionSpecialList", "actionCommand")); menu.add(item); } menu.show( buttonSpecialLists, 0, buttonSpecialLists.getHeight()); }
Example 3
Source File: WhiteRabbitMain.java From WhiteRabbit with Apache License 2.0 | 6 votes |
private JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu helpMenu = new JMenu("Help"); JMenuItem versionItem = new JMenuItem("White Rabbit v" + Version.getVersion(this.getClass())); versionItem.setEnabled(false); helpMenu.add(versionItem); menuBar.add(helpMenu); JMenuItem helpItem = new JMenuItem(ACTION_CMD_HELP); helpItem.addActionListener(this); helpItem.setActionCommand(ACTION_CMD_HELP); helpMenu.add(helpItem); return menuBar; }
Example 4
Source File: BaseChartPanel.java From nmonvisualizer with Apache License 2.0 | 6 votes |
@Override protected JPopupMenu createPopupMenu(boolean properties, boolean copy, boolean save, boolean print, boolean zoom) { JPopupMenu popup = super.createPopupMenu(properties, copy, save, print, zoom); int n = 0; // find the existing 'Copy' menu item and add an option to copy chart data after that for (MenuElement element : popup.getSubElements()) { JMenuItem item = (JMenuItem) element; if (item.getText().equals("Copy")) { JMenuItem copyData = new JMenuItem("Copy Chart Data"); copyData.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doCopyDataset(); } }); // after separator, after copy => + 2 popup.add(copyData, n + 2); popup.add(new JPopupMenu.Separator(), n + 3); } n++; } // create Save Chart item // note that the default 'Save as' item is no present since false was passed into the // BaseChartPanel constructor when creating this class' instance JMenuItem savePNG = new JMenuItem("Save Chart..."); savePNG.setActionCommand("SAVE_AS_PNG"); savePNG.addActionListener(this); popup.add(savePNG); return popup; }
Example 5
Source File: MapMenu.java From megamek with GNU General Public License v2.0 | 6 votes |
private JMenuItem createTorsoTwistJMenuItem(Coords twistCoords) { JMenuItem item = new JMenuItem("Twist"); item.setActionCommand(twistCoords.getX() + "|" + twistCoords.getY()); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { StringTokenizer result = new StringTokenizer(e .getActionCommand(), "|"); Coords coord = new Coords(Integer.parseInt(result .nextToken()), Integer.parseInt(result.nextToken())); if (currentPanel instanceof FiringDisplay) { ((FiringDisplay) currentPanel).torsoTwist(coord); } else if (currentPanel instanceof TargetingPhaseDisplay) { ((TargetingPhaseDisplay) currentPanel) .torsoTwist(coord); } } catch (Exception ex) { ex.printStackTrace(); } } }); return item; }
Example 6
Source File: MapMenu.java From megamek with GNU General Public License v2.0 | 6 votes |
private JMenuItem createFlipArmsJMenuItem() { JMenuItem item = new JMenuItem("Flip Arms"); item.setActionCommand(Integer.toString(myEntity.getId())); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { FiringDisplay display = (FiringDisplay) currentPanel; int id = Integer.parseInt(e.getActionCommand()); display.updateFlipArms(!game.getEntity(id).getArmsFlipped()); } catch (Exception ex) { ex.printStackTrace(); } } }); return item; }
Example 7
Source File: ObjectPopupMenu.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
private void setCCP() { TransferActionListener actionListener = new TransferActionListener(); cut = new JMenuItem("Cut"); cut.setActionCommand((String) TransferHandler.getCutAction().getValue(Action.NAME)); cut.addActionListener(actionListener); cut.setAccelerator(Keystroke.CUT); cut.setMnemonic(KeyEvent.VK_T); add(cut); copy = new JMenuItem("Copy"); copy.setActionCommand((String) TransferHandler.getCopyAction().getValue(Action.NAME)); copy.addActionListener(actionListener); copy.setAccelerator(Keystroke.COPY); copy.setMnemonic(KeyEvent.VK_C); add(copy); paste = new JMenuItem("Paste"); paste.setActionCommand((String) TransferHandler.getPasteAction().getValue(Action.NAME)); paste.addActionListener(actionListener); paste.setAccelerator(Keystroke.PASTE); paste.setMnemonic(KeyEvent.VK_P); add(paste); }
Example 8
Source File: JMenuReprocessed.java From jeveassets with GNU General Public License v2.0 | 6 votes |
public JMenuReprocessed(final Program program) { super(TabsReprocessed.get().title(), program); setIcon(Images.TOOL_REPROCESSED.getIcon()); ListenerClass listener = new ListenerClass(); jAdd = new JMenuItem(TabsReprocessed.get().add()); jAdd.setIcon(Images.EDIT_ADD.getIcon()); jAdd.setActionCommand(MenuReprocessedAction.ADD.name()); jAdd.addActionListener(listener); add(jAdd); jSet = new JMenuItem(TabsReprocessed.get().set()); jSet.setIcon(Images.EDIT_SET.getIcon()); jSet.setActionCommand(MenuReprocessedAction.SET.name()); jSet.addActionListener(listener); add(jSet); }
Example 9
Source File: MapMenu.java From megamek with GNU General Public License v2.0 | 6 votes |
private JMenuItem createClubJMenuItem(String clubName, int clubNumber) { JMenuItem item = new JMenuItem(clubName); item.setActionCommand(Integer.toString(clubNumber)); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Mounted club = myEntity.getClubs().get( Integer.parseInt(e.getActionCommand())); ((PhysicalDisplay) currentPanel).club(club); } catch (Exception ex) { ex.printStackTrace(); } } }); return item; }
Example 10
Source File: MapMenu.java From megamek with GNU General Public License v2.0 | 5 votes |
private JMenuItem TargetMenuItem(Targetable t) { JMenuItem item = new JMenuItem( Messages.getString("ClientGUI.targetMenuItem") + t.getDisplayName()); String targetCode = ""; if (t instanceof Entity) { targetCode = "E|" + ((Entity) t).getId(); } else if (t instanceof BuildingTarget) { targetCode = "B|" + t.getPosition().getX() + "|" + t.getPosition().getY() + "|" + t.getTargetType(); } else if (t instanceof MinefieldTarget) { targetCode = "M|" + t.getPosition().getX() + "|" + t.getPosition().getY(); } else { targetCode = "H|" + t.getPosition().getX() + "|" + t.getPosition().getY() + "|" + t.getTargetType(); } item.setActionCommand(targetCode); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myTarget = decodeTargetInfo(e.getActionCommand()); if (currentPanel instanceof FiringDisplay) { ((FiringDisplay) currentPanel).target(myTarget); } else if (currentPanel instanceof PhysicalDisplay) { ((PhysicalDisplay) currentPanel).target(myTarget); } else if (currentPanel instanceof TargetingPhaseDisplay) { ((TargetingPhaseDisplay) currentPanel).target(myTarget); } } }); return item; }
Example 11
Source File: MainWindow.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * Add an item to the generate lists menu. * * @param menu Menu. * @param mode List to be generated. */ private void addItemInInternalLinks(JPopupMenu menu, PageListWorker.Mode mode) { JMenuItem item = Utilities.createJMenuItem(mode.getTitle(), true); item.setActionCommand(mode.name()); item.addActionListener(EventHandler.create( ActionListener.class, this, "actionInternalLinks", "actionCommand")); menu.add(item); }
Example 12
Source File: PCGenMenuBar.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected JMenuItem createMenuItem(File item, int index) { JMenuItem menuItem = new JMenuItem(); menuItem.setText((index + 1) + " " + item.getName()); //$NON-NLS-1$ menuItem.setToolTipText(item.getAbsolutePath()); menuItem.setActionCommand(item.getAbsolutePath()); menuItem.setMnemonic(String.valueOf(index + 1).charAt(0)); menuItem.addActionListener(this); return menuItem; }
Example 13
Source File: MapMenu.java From megamek with GNU General Public License v2.0 | 5 votes |
private JMenuItem createModeJMenuItem(Mounted mounted, int position) { JMenuItem item = new JMenuItem(); EquipmentMode mode = mounted.getType().getMode(position); if (mode.equals(mounted.curMode())) { item.setText("* " + mode.getDisplayableName()); } else { item.setText(mode.getDisplayableName()); } item.setActionCommand(Integer.toString(position)); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { int modePosition = Integer.parseInt(e.getActionCommand()); int weaponNum = gui.mechD.wPan.getSelectedWeaponNum(); Mounted equip = myEntity.getEquipment(weaponNum); equip.setMode(modePosition); client.sendModeChange(myEntity.getId(), weaponNum, modePosition); } catch (Exception ex) { ex.printStackTrace(); } } }); return item; }
Example 14
Source File: ProtocolEditor.java From aion-germany with GNU General Public License v3.0 | 4 votes |
public ProtocolEditor(JFrame frame) { super(frame); setTitle("Packet Samurai - Protocol Editor"); setSize(800, 600); setLayout(new BorderLayout()); _clientTab = new ProtocolTab(); _serverTab = new ProtocolTab(); //menus JMenuBar menuBar = new JMenuBar(); //action listener _pel = new ProtocolEditorListener(this); // * File menu JMenu fileMenu = new JMenu("File"); // * Reload Button JMenuItem reloadButton = new JMenuItem("Reload"); reloadButton.setActionCommand("reload"); reloadButton.addActionListener(_pel); // * Save Button JMenuItem saveButton = new JMenuItem("Save"); saveButton.setActionCommand("save"); saveButton.addActionListener(_pel); fileMenu.add(reloadButton); fileMenu.add(saveButton); // * Protocol menu _protocolMenu = new JMenu("Chose Protocol"); loadProtocols(); JMenu editMenu = new JMenu("Edit"); JMenuItem protoPorpertyButton = new JMenuItem("Protocol Properties"); protoPorpertyButton.setActionCommand("properties"); protoPorpertyButton.addActionListener(_pel); editMenu.add(protoPorpertyButton); menuBar.add(fileMenu); menuBar.add(_protocolMenu); menuBar.add(editMenu ); setJMenuBar(menuBar); // tabs JTabbedPane tabPane = new JTabbedPane(); tabPane.add(_clientTab); tabPane.add(_serverTab); add(tabPane); }
Example 15
Source File: PolarChartPanel.java From ccu-historian with GNU General Public License v3.0 | 4 votes |
/** * Creates a popup menu for the panel. * * @param properties include a menu item for the chart property editor. * @param save include a menu item for saving the chart. * @param print include a menu item for printing the chart. * @param zoom include menu items for zooming. * * @return The popup menu. */ @Override protected JPopupMenu createPopupMenu(boolean properties, boolean save, boolean print, boolean zoom) { JPopupMenu result = super.createPopupMenu(properties, save, print, zoom); int zoomInIndex = getPopupMenuItem(result, localizationResources.getString("Zoom_In")); int zoomOutIndex = getPopupMenuItem(result, localizationResources.getString("Zoom_Out")); int autoIndex = getPopupMenuItem(result, localizationResources.getString("Auto_Range")); if (zoom) { JMenuItem zoomIn = new JMenuItem( localizationResources.getString("Zoom_In")); zoomIn.setActionCommand(POLAR_ZOOM_IN_ACTION_COMMAND); zoomIn.addActionListener(this); JMenuItem zoomOut = new JMenuItem( localizationResources.getString("Zoom_Out")); zoomOut.setActionCommand(POLAR_ZOOM_OUT_ACTION_COMMAND); zoomOut.addActionListener(this); JMenuItem auto = new JMenuItem( localizationResources.getString("Auto_Range")); auto.setActionCommand(POLAR_AUTO_RANGE_ACTION_COMMAND); auto.addActionListener(this); if (zoomInIndex != -1) { result.remove(zoomInIndex); } else { zoomInIndex = result.getComponentCount() - 1; } result.add(zoomIn, zoomInIndex); if (zoomOutIndex != -1) { result.remove(zoomOutIndex); } else { zoomOutIndex = zoomInIndex + 1; } result.add(zoomOut, zoomOutIndex); if (autoIndex != -1) { result.remove(autoIndex); } else { autoIndex = zoomOutIndex + 1; } result.add(auto, autoIndex); } return result; }
Example 16
Source File: DomGui.java From DominionSim with MIT License | 4 votes |
private JMenuBar createMenu() { JMenuBar bar = new JMenuBar(); JMenu fileMenu = new JMenu( "File" ); fileMenu.setMnemonic( 'f' ); JMenuItem loadPool = new JMenuItem( "Import Bots", 'I' ); loadPool.addActionListener( this ); loadPool.setActionCommand( "Load" ); fileMenu.add( loadPool ); JMenuItem saveDeck = new JMenuItem( "Export Bots", 'E' ); saveDeck.addActionListener( this ); saveDeck.setActionCommand( "Save" ); fileMenu.add( saveDeck ); fileMenu.insertSeparator( 2 ); JMenuItem exit = new JMenuItem( "Exit", 'X' ); exit.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent ae ) { shutDown(); } } ); fileMenu.add( exit ); bar.add( fileMenu ); JMenu devmodeMenu = new JMenu("Development"); JCheckBoxMenuItem devMode = new JCheckBoxMenuItem( "Development Mode" ); devMode.setSelected(DomEngine.developmentMode); devMode.addActionListener(this); devMode.setActionCommand("DevMode"); devmodeMenu.add(devMode); bar.add(devmodeMenu); JMenu helpMenu = new JMenu( "Help" ); helpMenu.setMnemonic( 'h' ); JMenuItem webHelp = new JMenuItem( "http://dominionsimulator.wordpress.com" ); webHelp.addActionListener( this ); webHelp.setActionCommand( "WebHelp" ); helpMenu.add( webHelp); helpMenu.insertSeparator( 2 ); JMenuItem about = new JMenuItem( "About", 't' ); about.addActionListener( this ); about.setActionCommand( "About" ); helpMenu.add( about ); bar.add( helpMenu ); return bar; }
Example 17
Source File: TestsetComponent.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 4 votes |
private JMenuItem create(String text, String actionCommand) { JMenuItem menuItem = Utils.createMenuItem(text, TestsetComponent.this); menuItem.setActionCommand(actionCommand); return menuItem; }
Example 18
Source File: PolarChartPanel.java From openstock with GNU General Public License v3.0 | 4 votes |
/** * Creates a popup menu for the panel. * * @param properties include a menu item for the chart property editor. * @param save include a menu item for saving the chart. * @param print include a menu item for printing the chart. * @param zoom include menu items for zooming. * * @return The popup menu. */ @Override protected JPopupMenu createPopupMenu(boolean properties, boolean save, boolean print, boolean zoom) { JPopupMenu result = super.createPopupMenu(properties, save, print, zoom); int zoomInIndex = getPopupMenuItem(result, localizationResources.getString("Zoom_In")); int zoomOutIndex = getPopupMenuItem(result, localizationResources.getString("Zoom_Out")); int autoIndex = getPopupMenuItem(result, localizationResources.getString("Auto_Range")); if (zoom) { JMenuItem zoomIn = new JMenuItem( localizationResources.getString("Zoom_In")); zoomIn.setActionCommand(POLAR_ZOOM_IN_ACTION_COMMAND); zoomIn.addActionListener(this); JMenuItem zoomOut = new JMenuItem( localizationResources.getString("Zoom_Out")); zoomOut.setActionCommand(POLAR_ZOOM_OUT_ACTION_COMMAND); zoomOut.addActionListener(this); JMenuItem auto = new JMenuItem( localizationResources.getString("Auto_Range")); auto.setActionCommand(POLAR_AUTO_RANGE_ACTION_COMMAND); auto.addActionListener(this); if (zoomInIndex != -1) { result.remove(zoomInIndex); } else { zoomInIndex = result.getComponentCount() - 1; } result.add(zoomIn, zoomInIndex); if (zoomOutIndex != -1) { result.remove(zoomOutIndex); } else { zoomOutIndex = zoomInIndex + 1; } result.add(zoomOut, zoomOutIndex); if (autoIndex != -1) { result.remove(autoIndex); } else { autoIndex = zoomOutIndex + 1; } result.add(auto, autoIndex); } return result; }
Example 19
Source File: HopActions.java From constellation with Apache License 2.0 | 4 votes |
public HopActions() { panel = new JPanel(); panel.setLayout(new BorderLayout()); menuBar = new JMenuBar(); menuBar.setOpaque(true); menu = new JMenu(); menu.setIcon(HOP_OUT_ONE_ICON); menu.setToolTipText("Hop Controls"); menu.setEnabled(false); final JMenuItem hopOutHalfItem = new JMenuItem("Hop Out Half"); hopOutHalfItem.setIcon(HOP_OUT_HALF_ICON); hopOutHalfItem.setActionCommand(HOP_OUT_HALF_ACTION); hopOutHalfItem.addActionListener(HopActions.this); menu.add(hopOutHalfItem); final JMenuItem hopOutOneItem = new JMenuItem("Hop Out One"); hopOutOneItem.setIcon(HOP_OUT_ONE_ICON); hopOutOneItem.setActionCommand(HOP_OUT_ONE_ACTION); hopOutOneItem.addActionListener(HopActions.this); menu.add(hopOutOneItem); final JMenuItem hopOutFullItem = new JMenuItem("Hop Out Full"); hopOutFullItem.setIcon(HOP_OUT_FULL_ICON); hopOutFullItem.setActionCommand(HOP_OUT_FULL_ACTION); hopOutFullItem.addActionListener(HopActions.this); menu.add(hopOutFullItem); final JPanel directionPanel = new JPanel(); directionPanel.setLayout(new BoxLayout(directionPanel, BoxLayout.Y_AXIS)); directionPanel.setBorder(new TitledBorder("Direction")); outgoing = new JCheckBox("Outgoing", true); outgoing.setToolTipText("Hop Along Outgoing Transactions"); directionPanel.add(outgoing); incoming = new JCheckBox("Incoming", true); incoming.setToolTipText("Hop Along Incoming Transactions"); directionPanel.add(incoming); undirected = new JCheckBox("Undirected", true); undirected.setToolTipText("Hop Along Undirected Transactions"); directionPanel.add(undirected); final JPanel optionsPanel = new JPanel(); optionsPanel.setBorder(new EmptyBorder(10, 0, 0, 0)); optionsPanel.setLayout(new BorderLayout()); optionsPanel.add(directionPanel, BorderLayout.CENTER); menu.add(optionsPanel); menuBar.add(menu); panel.add(menuBar, BorderLayout.CENTER); GraphManager.getDefault().addGraphManagerListener(HopActions.this); }
Example 20
Source File: CommandList.java From stendhal with GNU General Public License v2.0 | 4 votes |
/** * Populate the menu. * * @param items menu items */ private void populate(final String[] items) { ActionListener listener; Icon adminIcon; Icon icon; String label; listener = new ActionSelectedCB(); adminIcon = new AdminIcon(); for (String item : items) { // Comma separated list of commands, not a single command if (item.indexOf(',') > 0) { String[] sublist = item.split(","); populate(sublist); continue; } if (item.startsWith("(*)")) { icon = adminIcon; label = item.substring(3); } else { icon = null; label = item; } /* * Deal with '|' definitions. (Coming from server side). * Before the break is the user representation, after it is the * usual representation of the actual command. * * That is, a teddy might have a menu item definition "Hug|Use". */ int breakPoint = label.indexOf('|'); if (breakPoint >= 0) { label = item.substring(0, breakPoint); item = item.substring(breakPoint + 1); } final JMenuItem mi = createItem(label, icon); mi.setActionCommand(item); mi.addActionListener(listener); add(mi); } }