List of usage examples for javax.swing Action NAME
String NAME
To view the source code for javax.swing Action NAME.
Click Source Link
String
name for the action, used for a menu or button. From source file:DragPictureDemo2.java
public JMenuBar createMenuBar() { JMenuItem menuItem = null;/* www .j ava2 s. c om*/ JMenuBar menuBar = new JMenuBar(); JMenu mainMenu = new JMenu("Edit"); mainMenu.setMnemonic(KeyEvent.VK_E); TransferActionListener actionListener = new TransferActionListener(); menuItem = new JMenuItem("Cut"); menuItem.setActionCommand((String) TransferHandler.getCutAction().getValue(Action.NAME)); menuItem.addActionListener(actionListener); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)); menuItem.setMnemonic(KeyEvent.VK_T); mainMenu.add(menuItem); menuItem = new JMenuItem("Copy"); menuItem.setActionCommand((String) TransferHandler.getCopyAction().getValue(Action.NAME)); menuItem.addActionListener(actionListener); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); menuItem.setMnemonic(KeyEvent.VK_C); mainMenu.add(menuItem); menuItem = new JMenuItem("Paste"); menuItem.setActionCommand((String) TransferHandler.getPasteAction().getValue(Action.NAME)); menuItem.addActionListener(actionListener); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK)); menuItem.setMnemonic(KeyEvent.VK_P); mainMenu.add(menuItem); menuBar.add(mainMenu); return menuBar; }
From source file:org.pentaho.reporting.designer.core.xul.ActionSwingButton.java
protected void installAction(final Action newAction) { if (newAction != null) { setTooltiptext((String) action.getValue(Action.SHORT_DESCRIPTION)); setLabel((String) action.getValue(Action.NAME)); setDisabled(action.isEnabled() == false); setIcon((Icon) action.getValue(Action.SMALL_ICON)); getButton().setAction(newAction); newAction.addPropertyChangeListener(actionChangeHandler); final Object o = newAction.getValue(Action.ACCELERATOR_KEY); if (o instanceof KeyStroke) { final KeyStroke k = (KeyStroke) o; getButton().registerKeyboardAction(newAction, k, JComponent.WHEN_IN_FOCUSED_WINDOW); }/*from w w w .j ava2s . com*/ if (newAction instanceof ToggleStateAction) { final ToggleStateAction tsa = (ToggleStateAction) action; setSelected(tsa.isSelected()); } } }
From source file:org.jivesoftware.sparkimpl.plugin.viewer.PluginViewer.java
public void initialize() { // Add Plugins Menu JMenuBar menuBar = SparkManager.getMainWindow().getJMenuBar(); // Get last menu which is help JMenu sparkMenu = menuBar.getMenu(0); JMenuItem viewPluginsMenu = new JMenuItem(); Action viewAction = new AbstractAction() { private static final long serialVersionUID = 6518407602062984752L; public void actionPerformed(ActionEvent e) { invokeViewer();/*www. j a va2s.com*/ } }; viewAction.putValue(Action.NAME, Res.getString("menuitem.plugins")); viewAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.PLUGIN_IMAGE)); viewPluginsMenu.setAction(viewAction); sparkMenu.insert(viewPluginsMenu, 2); }
From source file:ListCutPaste.java
/** * Add the cut/copy/paste actions to the action map. */// w w w . j ava 2 s . c o m private void setMappings(JList list) { ActionMap map = list.getActionMap(); map.put(TransferHandler.getCutAction().getValue(Action.NAME), TransferHandler.getCutAction()); map.put(TransferHandler.getCopyAction().getValue(Action.NAME), TransferHandler.getCopyAction()); map.put(TransferHandler.getPasteAction().getValue(Action.NAME), TransferHandler.getPasteAction()); }
From source file:de.tbuchloh.kiskis.gui.MainFrame.java
/** * @see de.tbuchloh.kiskis.gui.systray.IMainFrame#getPopupMenu() *//*from w w w .ja v a 2s. c o m*/ @Override public PopupMenu getPopupMenu() { final PopupMenu popup = new PopupMenu(); for (final Action act : _main.getPopupActions()) { if (act == null) { popup.addSeparator(); } else { final MenuItem mi = new MenuItem((String) act.getValue(Action.NAME)); mi.setEnabled(act.isEnabled()); mi.addActionListener(act); mi.setFont(new Font("Arial", Font.BOLD, 12)); popup.add(mi); } } return popup; }
From source file:org.pentaho.reporting.designer.core.xul.ActionSwingMenuitem.java
protected void installAction(final Action newAction) { if (newAction != null) { menuitem.addActionListener(newAction); newAction.addPropertyChangeListener(actionChangeHandler); setLabel((String) (newAction.getValue(Action.NAME))); setTooltiptext((String) (newAction.getValue(Action.SHORT_DESCRIPTION))); setDisabled(this.action.isEnabled() == false); refreshMnemonic(newAction);//from w w w .j a v a 2 s . c om refreshKeystroke(newAction); final Object rawSelectedSwing = action.getValue(Action.SELECTED_KEY); if (rawSelectedSwing != null) { setSelected(Boolean.TRUE.equals(rawSelectedSwing)); } else { final Object rawSelectedPrd = action.getValue("selected"); setSelected(Boolean.TRUE.equals(rawSelectedPrd)); } final Object rawVisible = action.getValue("visible"); if (rawVisible != null) { setVisible(Boolean.TRUE.equals(rawVisible)); } } }
From source file:com.sshtools.common.ui.SshToolsApplicationPanel.java
/** * Rebuild all the action components such as toobar, context menu *//*from w w w.j av a2 s. c om*/ public void rebuildActionComponents() { // Clear the current state of the component log.debug("Rebuild action components"); toolBar.removeAll(); // Vector enabledActions = new Vector(); for (Iterator i = actions.iterator(); i.hasNext();) { StandardAction a = (StandardAction) i.next(); String n = (String) a.getValue(Action.NAME); Boolean s = (Boolean) actionsVisible.get(n); if (s == null) { s = Boolean.TRUE; } if (Boolean.TRUE.equals(s)) { log.debug("Action " + n + " is enabled."); enabledActions.add(a); } else { log.debug("Action " + n + " not enabled."); } } // Build the tool bar, grouping the actions Vector v = new Vector(); for (Iterator i = enabledActions.iterator(); i.hasNext();) { StandardAction a = (StandardAction) i.next(); if (Boolean.TRUE.equals((Boolean) a.getValue(StandardAction.ON_TOOLBAR))) { v.addElement(a); } } Collections.sort(v, new ToolBarActionComparator()); Integer grp = null; for (Iterator i = v.iterator(); i.hasNext();) { StandardAction z = (StandardAction) i.next(); if ((grp != null) && !grp.equals((Integer) z.getValue(StandardAction.TOOLBAR_GROUP))) { toolBar.add(new ToolBarSeparator()); } if (Boolean.TRUE.equals((Boolean) z.getValue(StandardAction.IS_TOGGLE_BUTTON))) { ToolToggleButton tBtn = new ToolToggleButton(z); toolBar.add(tBtn); } else { ToolButton btn = new ToolButton(z); toolBar.add(btn); } grp = (Integer) z.getValue(StandardAction.TOOLBAR_GROUP); } toolBar.revalidate(); toolBar.repaint(); // Build the context menu, grouping the actions Vector c = new Vector(); contextMenu.removeAll(); for (Iterator i = enabledActions.iterator(); i.hasNext();) { StandardAction a = (StandardAction) i.next(); if (Boolean.TRUE.equals((Boolean) a.getValue(StandardAction.ON_CONTEXT_MENU))) { c.addElement(a); } } Collections.sort(c, new ContextActionComparator()); grp = null; for (Iterator i = c.iterator(); i.hasNext();) { StandardAction z = (StandardAction) i.next(); if ((grp != null) && !grp.equals((Integer) z.getValue(StandardAction.CONTEXT_MENU_GROUP))) { contextMenu.addSeparator(); } contextMenu.add(z); grp = (Integer) z.getValue(StandardAction.CONTEXT_MENU_GROUP); } contextMenu.revalidate(); // Build the menu bar menuBar.removeAll(); v.removeAllElements(); for (Enumeration e = enabledActions.elements(); e.hasMoreElements();) { StandardAction a = (StandardAction) e.nextElement(); if (Boolean.TRUE.equals((Boolean) a.getValue(StandardAction.ON_MENUBAR))) { v.addElement(a); } } Vector menus = (Vector) actionMenus.clone(); Collections.sort(menus); HashMap map = new HashMap(); for (Iterator i = v.iterator(); i.hasNext();) { StandardAction z = (StandardAction) i.next(); String menuName = (String) z.getValue(StandardAction.MENU_NAME); if (menuName == null) { log.error("Action " + z.getName() + " doesnt specify a value for " + StandardAction.MENU_NAME); } else { String m = (String) z.getValue(StandardAction.MENU_NAME); ActionMenu menu = getActionMenu(menus.iterator(), m); if (menu == null) { log.error("Action menu " + z.getName() + " does not exist"); } else { Vector x = (Vector) map.get(menu.name); if (x == null) { x = new Vector(); map.put(menu.name, x); } x.addElement(z); } } } for (Iterator i = menus.iterator(); i.hasNext();) { ActionMenu m = (ActionMenu) i.next(); Vector x = (Vector) map.get(m.name); if (x != null) { Collections.sort(x, new MenuItemActionComparator()); JMenu menu = new JMenu(m.displayName); menu.setMnemonic(m.mnemonic); grp = null; for (Iterator j = x.iterator(); j.hasNext();) { StandardAction a = (StandardAction) j.next(); Integer g = (Integer) a.getValue(StandardAction.MENU_ITEM_GROUP); if ((grp != null) && !g.equals(grp)) { menu.addSeparator(); } grp = g; if (a instanceof MenuAction) { JMenu mnu = (JMenu) a.getValue(MenuAction.MENU); menu.add(mnu); } else { JMenuItem item = new JMenuItem(a); menu.add(item); } } menuBar.add(menu); } else { log.error("Can't find menu " + m.name); } } menuBar.validate(); menuBar.repaint(); }
From source file:net.sf.jabref.gui.ContentSelectorDialog2.java
private void setupActions() { wordList.addListSelectionListener(e -> { wordEditField.setText(wordList.getSelectedValue()); wordEditField.selectAll();//from w w w. j a va2 s . com new FocusRequester(wordEditField); }); newWord.addActionListener(e -> newWordAction()); ActionListener wordEditFieldListener = e -> actOnWordEdit(); wordEditField.addActionListener(wordEditFieldListener); removeWord.addActionListener(e -> { int index = wordList.getSelectedIndex(); if (index == -1) { return; } wordListModel.remove(index); wordEditField.setText(""); if (!wordListModel.isEmpty()) { wordList.setSelectedIndex(Math.min(index, wordListModel.size() - 1)); } }); fieldList.addListSelectionListener(e -> { currentField = fieldList.getSelectedValue(); fieldNameField.setText(""); setupWordSelector(); }); newField.addActionListener(e -> { if (!fieldListModel.get(0).equals(FIELD_FIRST_LINE)) { // only add <field name> once fieldListModel.add(0, FIELD_FIRST_LINE); } fieldList.setSelectedIndex(0); fPane.getVerticalScrollBar().setValue(0); fieldNameField.setEnabled(true); fieldNameField.setText(currentField); fieldNameField.selectAll(); new FocusRequester(fieldNameField); }); fieldNameField.addActionListener(e -> fieldNameField.transferFocus()); fieldNameField.addFocusListener(new FieldNameFocusAdapter()); removeField.addActionListener(e -> { int index = fieldList.getSelectedIndex(); if (index == -1) { return; } String fieldName = fieldListModel.get(index); removedFields.add(fieldName); fieldListModel.remove(index); wordListModels.remove(fieldName); fieldNameField.setText(""); if (!fieldListModel.isEmpty()) { fieldList.setSelectedIndex(Math.min(index, wordListModel.size() - 1)); } }); ok.addActionListener(e -> { try { applyChanges(); dispose(); } catch (Exception ex) { LOGGER.info("Could not apply changes in \"Manage content selectors\"", ex); JOptionPane.showMessageDialog(frame, Localization.lang("Could not apply changes.")); } }); apply.addActionListener(e -> { // Store if an entry is currently being edited: if (!"".equals(wordEditField.getText())) { wordEditFieldListener.actionPerformed(null); } try { applyChanges(); } catch (Exception ex) { LOGGER.info("Could not apply changes in \"Manage content selectors\"", ex); JOptionPane.showMessageDialog(frame, Localization.lang("Could not apply changes.")); } }); Action cancelAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }; cancelAction.putValue(Action.NAME, Localization.lang("Cancel")); cancel.setAction(cancelAction); }
From source file:VASSAL.launch.ModuleManagerWindow.java
public ModuleManagerWindow() { setTitle("VASSAL"); setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS)); ApplicationIcons.setFor(this); final AbstractAction shutDownAction = new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { if (!AbstractLaunchAction.shutDown()) return; final Prefs gl = Prefs.getGlobalPrefs(); try { gl.write();/* ww w . j av a 2 s. c o m*/ gl.close(); } catch (IOException ex) { WriteErrorDialog.error(ex, gl.getFile()); } finally { IOUtils.closeQuietly(gl); } logger.info("Exiting"); System.exit(0); } }; shutDownAction.putValue(Action.NAME, Resources.getString(Resources.QUIT)); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { shutDownAction.actionPerformed(null); } }); // setup menubar and actions final MenuManager mm = MenuManager.getInstance(); final MenuBarProxy mb = mm.getMenuBarProxyFor(this); // file menu final MenuProxy fileMenu = new MenuProxy(Resources.getString("General.file")); fileMenu.setMnemonic(Resources.getString("General.file.shortcut").charAt(0)); fileMenu.add(mm.addKey("Main.play_module")); fileMenu.add(mm.addKey("Main.edit_module")); fileMenu.add(mm.addKey("Main.new_module")); fileMenu.add(mm.addKey("Main.import_module")); fileMenu.addSeparator(); if (!SystemUtils.IS_OS_MAC_OSX) { fileMenu.add(mm.addKey("Prefs.edit_preferences")); fileMenu.addSeparator(); fileMenu.add(mm.addKey("General.quit")); } // tools menu final MenuProxy toolsMenu = new MenuProxy(Resources.getString("General.tools")); // Initialize Global Preferences Prefs.getGlobalPrefs().getEditor().initDialog(this); Prefs.initSharedGlobalPrefs(); final BooleanConfigurer serverStatusConfig = new BooleanConfigurer(SHOW_STATUS_KEY, null, Boolean.FALSE); Prefs.getGlobalPrefs().addOption(null, serverStatusConfig); dividerLocationConfig = new IntConfigurer(DIVIDER_LOCATION_KEY, null, -10); Prefs.getGlobalPrefs().addOption(null, dividerLocationConfig); toolsMenu.add(new CheckBoxMenuItemProxy(new AbstractAction(Resources.getString("Chat.server_status")) { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { serverStatusView.toggleVisibility(); serverStatusConfig.setValue(serverStatusConfig.booleanValue() ? Boolean.FALSE : Boolean.TRUE); if (serverStatusView.isVisible()) { setDividerLocation(getPreferredDividerLocation()); } } }, serverStatusConfig.booleanValue())); // help menu final MenuProxy helpMenu = new MenuProxy(Resources.getString("General.help")); helpMenu.setMnemonic(Resources.getString("General.help.shortcut").charAt(0)); helpMenu.add(mm.addKey("General.help")); helpMenu.add(mm.addKey("Main.tour")); helpMenu.addSeparator(); helpMenu.add(mm.addKey("UpdateCheckAction.update_check")); helpMenu.add(mm.addKey("Help.error_log")); if (!SystemUtils.IS_OS_MAC_OSX) { helpMenu.addSeparator(); helpMenu.add(mm.addKey("AboutScreen.about_vassal")); } mb.add(fileMenu); mb.add(toolsMenu); mb.add(helpMenu); // add actions mm.addAction("Main.play_module", new Player.PromptLaunchAction(this)); mm.addAction("Main.edit_module", new Editor.PromptLaunchAction(this)); mm.addAction("Main.new_module", new Editor.NewModuleLaunchAction(this)); mm.addAction("Main.import_module", new Editor.PromptImportLaunchAction(this)); mm.addAction("Prefs.edit_preferences", Prefs.getGlobalPrefs().getEditor().getEditAction()); mm.addAction("General.quit", shutDownAction); URL url = null; try { url = new File(Documentation.getDocumentationBaseDir(), "README.html").toURI().toURL(); } catch (MalformedURLException e) { ErrorDialog.bug(e); } mm.addAction("General.help", new ShowHelpAction(url, null)); mm.addAction("Main.tour", new LaunchTourAction(this)); mm.addAction("AboutScreen.about_vassal", new AboutVASSALAction(this)); mm.addAction("UpdateCheckAction.update_check", new UpdateCheckAction(this)); mm.addAction("Help.error_log", new ShowErrorLogAction(this)); setJMenuBar(mm.getMenuBarFor(this)); // Load Icons moduleIcon = new ImageIcon(getClass().getResource("/images/mm-module.png")); activeExtensionIcon = new ImageIcon(getClass().getResource("/images/mm-extension-active.png")); inactiveExtensionIcon = new ImageIcon(getClass().getResource("/images/mm-extension-inactive.png")); openGameFolderIcon = new ImageIcon(getClass().getResource("/images/mm-gamefolder-open.png")); closedGameFolderIcon = new ImageIcon(getClass().getResource("/images/mm-gamefolder-closed.png")); fileIcon = new ImageIcon(getClass().getResource("/images/mm-file.png")); // build module controls final JPanel moduleControls = new JPanel(new BorderLayout()); modulePanelLayout = new CardLayout(); moduleView = new JPanel(modulePanelLayout); buildTree(); final JScrollPane scroll = new JScrollPane(tree); moduleView.add(scroll, "modules"); final JEditorPane l = new JEditorPane("text/html", Resources.getString("ModuleManager.quickstart")); l.setEditable(false); // Try to get background color and font from LookAndFeel; // otherwise, use dummy JLabel to get color and font. Color bg = UIManager.getColor("control"); Font font = UIManager.getFont("Label.font"); if (bg == null || font == null) { final JLabel dummy = new JLabel(); if (bg == null) bg = dummy.getBackground(); if (font == null) font = dummy.getFont(); } l.setBackground(bg); ((HTMLEditorKit) l.getEditorKit()).getStyleSheet() .addRule("body { font: " + font.getFamily() + " " + font.getSize() + "pt }"); l.addHyperlinkListener(BrowserSupport.getListener()); // FIXME: use MigLayout for this! // this is necessary to get proper vertical alignment final JPanel p = new JPanel(new GridBagLayout()); final GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.CENTER; p.add(l, c); moduleView.add(p, "quickStart"); modulePanelLayout.show(moduleView, getModuleCount() == 0 ? "quickStart" : "modules"); moduleControls.add(moduleView, BorderLayout.CENTER); moduleControls.setBorder(new TitledBorder(Resources.getString("ModuleManager.recent_modules"))); add(moduleControls); // build server status controls final ServerStatusView serverStatusControls = new ServerStatusView(new CgiServerStatus()); serverStatusControls.setBorder(new TitledBorder(Resources.getString("Chat.server_status"))); serverStatusView = new ComponentSplitter().splitRight(moduleControls, serverStatusControls, false); serverStatusView.revalidate(); // show the server status controls according to the prefs if (serverStatusConfig.booleanValue()) { serverStatusView.showComponent(); } setDividerLocation(getPreferredDividerLocation()); serverStatusView.addPropertyChangeListener("dividerLocation", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { setPreferredDividerLocation((Integer) e.getNewValue()); } }); final Rectangle r = Info.getScreenBounds(this); serverStatusControls.setPreferredSize(new Dimension((int) (r.width / 3.5), 0)); setSize(3 * r.width / 4, 3 * r.height / 4); // Save/load the window position and size in prefs final PositionOption option = new PositionOption(PositionOption.key + "ModuleManager", this); Prefs.getGlobalPrefs().addOption(option); }
From source file:plugin.notes.gui.NotesView.java
/** * Searches a text component for a particular action. * *@param textComponent Text component to search for the action in *@param name name of the action to get *@return the action//from w w w . j a v a 2 s.com */ private Action getActionByName(JTextComponent textComponent, String name) { // TODO: This should be static in a GUIUtilities file for (Action a : textComponent.getActions()) { if (a.getValue(Action.NAME).equals(name)) { return a; } } return null; }