List of usage examples for javax.swing AbstractAction putValue
public void putValue(String key, Object newValue)
Value
associated with the specified key. From source file:net.schweerelos.parrot.CombinedParrotApp.java
@SuppressWarnings("serial") private JToggleButton setupNavigatorButton(final String name, final String accelerator, final NavigatorComponent navigator) { final Component component = navigator.asJComponent(); AbstractAction showNavigatorAction = new AbstractAction(name) { @Override/* ww w . j a v a 2s .c o m*/ public void actionPerformed(ActionEvent e) { if (!(e.getSource() instanceof JToggleButton)) { return; } final Window window; if (component instanceof Window) { window = (Window) component; } else { window = SwingUtilities.getWindowAncestor(component); } JToggleButton button = (JToggleButton) e.getSource(); boolean show = button.isSelected(); if (show) { if (window != CombinedParrotApp.this && preferredFrameLocations.containsKey(window)) { window.setLocation(preferredFrameLocations.get(window)); } } if (navigator.tellSelectionWhenShown()) { Collection<NodeWrapper> selectedNodes = activeMainView.getSelectedNodes(); navigator.setSelectedNodes(selectedNodes); } component.setVisible(show); if (show) { window.setVisible(true); } else if (window != CombinedParrotApp.this) { window.setVisible(false); } } }; showNavigatorAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control " + accelerator)); final JToggleButton button = new JToggleButton(showNavigatorAction); button.setToolTipText("Show " + name.toLowerCase()); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button.setToolTipText((button.isSelected() ? "Hide " : "Show ") + name.toLowerCase()); } }); final Window window; if (component instanceof Window) { window = (Window) component; } else { window = SwingUtilities.getWindowAncestor(component); } if (window != null) { window.addComponentListener(new ComponentAdapter() { @Override public void componentHidden(ComponentEvent e) { button.setSelected(false); if (window != CombinedParrotApp.this) { preferredFrameLocations.put(window, window.getLocation()); } } @Override public void componentShown(ComponentEvent e) { button.setSelected(true); } }); } return button; }
From source file:processing.app.Base.java
public void rebuildProgrammerMenu() { programmerMenus = new LinkedList<>(); ButtonGroup group = new ButtonGroup(); for (TargetPackage targetPackage : BaseNoGui.packages.values()) { for (TargetPlatform targetPlatform : targetPackage.platforms()) { for (String programmer : targetPlatform.getProgrammers().keySet()) { String id = targetPackage.getId() + ":" + programmer; @SuppressWarnings("serial") AbstractAction action = new AbstractAction( targetPlatform.getProgrammer(programmer).get("name")) { public void actionPerformed(ActionEvent actionevent) { PreferencesData.set("programmer", "" + getValue("id")); }//from w ww . j a v a 2 s . co m }; action.putValue("id", id); JMenuItem item = new JRadioButtonMenuItem(action); if (PreferencesData.get("programmer").equals(id)) { item.setSelected(true); } group.add(item); programmerMenus.add(item); } } } }
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();//from w ww. ja va 2 s . c om 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:processing.app.Base.java
protected void addLibraries(JMenu menu, LibraryList libs) throws IOException { LibraryList list = new LibraryList(libs); list.sort();//w w w . j a v a 2 s .c om for (UserLibrary lib : list) { @SuppressWarnings("serial") AbstractAction action = new AbstractAction(lib.getName()) { public void actionPerformed(ActionEvent event) { UserLibrary l = (UserLibrary) getValue("library"); try { activeEditor.getSketchController().importLibrary(l); } catch (IOException e) { showWarning(tr("Error"), I18n.format("Unable to list header files in {0}", l.getSrcFolder()), e); } } }; action.putValue("library", lib); // Add new element at the bottom JMenuItem item = new JMenuItem(action); item.putClientProperty("library", lib); menu.add(item); // XXX: DAM: should recurse here so that library folders can be nested } }
From source file:processing.app.Base.java
public void rebuildImportMenu(JMenu importMenu) { if (importMenu == null) return;/* w ww .j ava 2 s . c o m*/ importMenu.removeAll(); JMenuItem menu = new JMenuItem(tr("Manage Libraries...")); // Ctrl+Shift+I on Windows and Linux, Command+Shift+I on macOS menu.setAccelerator(KeyStroke.getKeyStroke('I', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | ActionEvent.SHIFT_MASK)); menu.addActionListener(e -> openLibraryManager("", "")); importMenu.add(menu); importMenu.addSeparator(); JMenuItem addLibraryMenuItem = new JMenuItem(tr("Add .ZIP Library...")); addLibraryMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Base.this.handleAddLibrary(); BaseNoGui.librariesIndexer.rescanLibraries(); Base.this.onBoardOrPortChange(); Base.this.rebuildImportMenu(Editor.importMenu); Base.this.rebuildExamplesMenu(Editor.examplesMenu); } }); importMenu.add(addLibraryMenuItem); importMenu.addSeparator(); // Split between user supplied libraries and IDE libraries TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform(); if (targetPlatform != null) { LibraryList libs = getSortedLibraries(); String lastLibType = null; for (UserLibrary lib : libs) { String libType = lib.getTypes().get(0); if (!libType.equals(lastLibType)) { if (lastLibType != null) { importMenu.addSeparator(); } lastLibType = libType; JMenuItem platformItem = new JMenuItem(I18n.format(tr("{0} libraries"), tr(lastLibType))); platformItem.setEnabled(false); importMenu.add(platformItem); } AbstractAction action = new AbstractAction(lib.getName()) { public void actionPerformed(ActionEvent event) { UserLibrary l = (UserLibrary) getValue("library"); try { activeEditor.getSketchController().importLibrary(l); } catch (IOException e) { showWarning(tr("Error"), I18n.format("Unable to list header files in {0}", l.getSrcFolder()), e); } } }; action.putValue("library", lib); // Add new element at the bottom JMenuItem item = new JMenuItem(action); item.putClientProperty("library", lib); importMenu.add(item); } } }
From source file:org.gtdfree.GTDFree.java
private ActionMap getActionMap() { if (actionMap == null) { actionMap = new ActionMap(); AbstractAction a = new AbstractAction(Messages.getString("GTDFree.View.Closed")) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override//from www .j av a 2 s . com public void actionPerformed(ActionEvent e) { getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_ALL_ACTIONS, !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_ALL_ACTIONS)); } }; a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Closed.desc")); //$NON-NLS-1$ actionMap.put(GlobalProperties.SHOW_ALL_ACTIONS, a); a = new AbstractAction(Messages.getString("GTDFree.View.Empty")) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_EMPTY_FOLDERS, !getEngine() .getGlobalProperties().getBoolean(GlobalProperties.SHOW_EMPTY_FOLDERS, true)); } }; a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Empty.desc")); //$NON-NLS-1$ actionMap.put(GlobalProperties.SHOW_EMPTY_FOLDERS, a); a = new AbstractAction(Messages.getString("GTDFree.View.ClosedLists")) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_CLOSED_FOLDERS, !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_CLOSED_FOLDERS)); } }; a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.ClosedLists.desc")); //$NON-NLS-1$ actionMap.put(GlobalProperties.SHOW_CLOSED_FOLDERS, a); a = new AbstractAction(Messages.getString("GTDFree.View.Overview")) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_OVERVIEW_TAB, !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_OVERVIEW_TAB)); } }; a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Overview.desc")); //$NON-NLS-1$ actionMap.put(GlobalProperties.SHOW_OVERVIEW_TAB, a); a = new AbstractAction(Messages.getString("GTDFree.View.Quick")) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_QUICK_COLLECT, !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_QUICK_COLLECT)); } }; a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Quick.desc")); //$NON-NLS-1$ actionMap.put(GlobalProperties.SHOW_QUICK_COLLECT, a); a = new AbstractAction(Messages.getString("GTDFree.View.Tray")) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { boolean b = !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_TRAY_ICON); getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_TRAY_ICON, b); if (b) { try { SystemTray.getSystemTray().add(getTrayIcon()); } catch (AWTException e1) { Logger.getLogger(this.getClass()).error("System tray icon initialization failed.", e1); //$NON-NLS-1$ } } else { SystemTray.getSystemTray().remove(getTrayIcon()); } } }; a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Tray.desc")); //$NON-NLS-1$ a.setEnabled(SystemTray.isSupported()); actionMap.put(GlobalProperties.SHOW_TRAY_ICON, a); a = new AbstractAction(Messages.getString("GTDFree.ImportExamples")) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { getImportDialog().getDialog(getJFrame()).setVisible(true); } }; a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.ImportExamples.desc")); //$NON-NLS-1$ actionMap.put("importDialog", a); //$NON-NLS-1$ } return actionMap; }