List of usage examples for javax.swing Action addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener);
PropertyChange
listener. From source file:edu.ku.brc.ui.UIHelper.java
/** * Creates a JMenuItem./*ww w. j av a 2s. c om*/ * @param menu parent menu * @param label the label of the menu item * @param mnemonic the mnemonic * @param accessibleDescription the accessible Description * @param enabled enabled * @param action the aciton * @return menu item */ public static JMenuItem createMenuItemWithAction(final JPopupMenu menu, final String label, final String mnemonic, final String accessibleDescription, final boolean enabled, final Action action) { JMenuItem mi = new JMenuItem(action); mi.setText(label); if (menu != null) { menu.add(mi); } if (isNotEmpty(mnemonic)) { mi.setMnemonic(mnemonic.charAt(0)); } if (isNotEmpty(accessibleDescription)) { mi.getAccessibleContext().setAccessibleDescription(accessibleDescription); } if (action != null) { action.addPropertyChangeListener(new MenuItemPropertyChangeListener(mi)); action.setEnabled(enabled); } return mi; }
From source file:edu.ku.brc.ui.UIHelper.java
/** * Creates a JMenuItem.//from www. j a va2 s . c o m * @param menu parent menu * @param label the label of the menu item * @param mnemonic the mnemonic * @param accessibleDescription the accessible Description * @param enabled enabled * @param action the aciton * @return menu item */ public static JMenuItem createMenuItemWithAction(final JMenu menu, final String label, final String mnemonic, final String accessibleDescription, final boolean enabled, final Action action) { JMenuItem mi = new JMenuItem(action); mi.setText(label); if (menu != null) { menu.add(mi); } if (isNotEmpty(mnemonic)) { mi.setMnemonic(mnemonic.charAt(0)); } if (isNotEmpty(accessibleDescription)) { mi.getAccessibleContext().setAccessibleDescription(accessibleDescription); } if (action != null) { action.addPropertyChangeListener(new MenuItemPropertyChangeListener(mi)); action.setEnabled(enabled); } return mi; }
From source file:org.apache.log4j.chainsaw.LogUI.java
/** * Activates itself as a viewer by configuring Size, and location of itself, * and configures the default Tabbed Pane elements with the correct layout, * table columns, and sets itself viewable. *//*w w w . j a v a 2 s .c o m*/ public void activateViewer() { LoggerRepository repo = LogManager.getLoggerRepository(); if (repo instanceof LoggerRepositoryEx) { this.pluginRegistry = ((LoggerRepositoryEx) repo).getPluginRegistry(); } initGUI(); initPrefModelListeners(); /** * We add a simple appender to the MessageCenter logger * so that each message is displayed in the Status bar */ MessageCenter.getInstance().getLogger().addAppender(new AppenderSkeleton() { protected void append(LoggingEvent event) { getStatusBar().setMessage(event.getMessage().toString()); } public void close() { } public boolean requiresLayout() { return false; } }); initSocketConnectionListener(); if (pluginRegistry.getPlugins(Receiver.class).size() == 0) { noReceiversDefined = true; } getFilterableColumns().add(ChainsawConstants.LEVEL_COL_NAME); getFilterableColumns().add(ChainsawConstants.LOGGER_COL_NAME); getFilterableColumns().add(ChainsawConstants.THREAD_COL_NAME); getFilterableColumns().add(ChainsawConstants.NDC_COL_NAME); getFilterableColumns().add(ChainsawConstants.PROPERTIES_COL_NAME); getFilterableColumns().add(ChainsawConstants.CLASS_COL_NAME); getFilterableColumns().add(ChainsawConstants.METHOD_COL_NAME); getFilterableColumns().add(ChainsawConstants.FILE_COL_NAME); getFilterableColumns().add(ChainsawConstants.NONE_COL_NAME); JPanel panePanel = new JPanel(); panePanel.setLayout(new BorderLayout(2, 2)); getContentPane().setLayout(new BorderLayout()); getTabbedPane().addChangeListener(getToolBarAndMenus()); getTabbedPane().addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { LogPanel thisLogPanel = getCurrentLogPanel(); if (thisLogPanel != null) { thisLogPanel.updateStatusBar(); } } }); KeyStroke ksRight = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); KeyStroke ksLeft = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); KeyStroke ksGotoLine = KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ksRight, "MoveRight"); getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ksLeft, "MoveLeft"); getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ksGotoLine, "GotoLine"); Action moveRight = new AbstractAction() { public void actionPerformed(ActionEvent e) { int temp = getTabbedPane().getSelectedIndex(); ++temp; if (temp != getTabbedPane().getTabCount()) { getTabbedPane().setSelectedTab(temp); } } }; Action moveLeft = new AbstractAction() { public void actionPerformed(ActionEvent e) { int temp = getTabbedPane().getSelectedIndex(); --temp; if (temp > -1) { getTabbedPane().setSelectedTab(temp); } } }; Action gotoLine = new AbstractAction() { public void actionPerformed(ActionEvent e) { String inputLine = JOptionPane.showInputDialog(LogUI.this, "Enter the line number to go:", "Goto Line", -1); try { int lineNumber = Integer.parseInt(inputLine); int row = getCurrentLogPanel().setSelectedEvent(lineNumber); if (row == -1) { JOptionPane.showMessageDialog(LogUI.this, "You have entered an invalid line number", "Error", 0); } } catch (NumberFormatException nfe) { JOptionPane.showMessageDialog(LogUI.this, "You have entered an invalid line number", "Error", 0); } } }; getTabbedPane().getActionMap().put("MoveRight", moveRight); getTabbedPane().getActionMap().put("MoveLeft", moveLeft); getTabbedPane().getActionMap().put("GotoLine", gotoLine); /** * We listen for double clicks, and auto-undock currently selected Tab if * the mouse event location matches the currently selected tab */ getTabbedPane().addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { super.mouseClicked(e); if ((e.getClickCount() > 1) && ((e.getModifiers() & InputEvent.BUTTON1_MASK) > 0)) { int tabIndex = getTabbedPane().getSelectedIndex(); if ((tabIndex != -1) && (tabIndex == getTabbedPane().getSelectedIndex())) { LogPanel logPanel = getCurrentLogPanel(); if (logPanel != null) { logPanel.undock(); } } } } }); panePanel.add(getTabbedPane()); addWelcomePanel(); getContentPane().add(toolbar, BorderLayout.NORTH); getContentPane().add(statusBar, BorderLayout.SOUTH); mainReceiverSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panePanel, receiversPanel); dividerSize = mainReceiverSplitPane.getDividerSize(); mainReceiverSplitPane.setDividerLocation(-1); getContentPane().add(mainReceiverSplitPane, BorderLayout.CENTER); /** * We need to make sure that all the internal GUI components have been added to the * JFrame so that any plugns that get activated during initPlugins(...) method * have access to inject menus */ initPlugins(pluginRegistry); mainReceiverSplitPane.setResizeWeight(1.0); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { exit(); } }); preferencesFrame.setTitle("'Application-wide Preferences"); preferencesFrame.setIconImage(((ImageIcon) ChainsawIcons.ICON_PREFERENCES).getImage()); preferencesFrame.getContentPane().add(applicationPreferenceModelPanel); preferencesFrame.setSize(750, 520); Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); preferencesFrame.setLocation(new Point((screenDimension.width / 2) - (preferencesFrame.getSize().width / 2), (screenDimension.height / 2) - (preferencesFrame.getSize().height / 2))); pack(); final JPopupMenu tabPopup = new JPopupMenu(); final Action hideCurrentTabAction = new AbstractAction("Hide") { public void actionPerformed(ActionEvent e) { Component selectedComp = getTabbedPane().getSelectedComponent(); if (selectedComp instanceof LogPanel) { displayPanel(getCurrentLogPanel().getIdentifier(), false); tbms.stateChange(); } else { getTabbedPane().remove(selectedComp); } } }; final Action hideOtherTabsAction = new AbstractAction("Hide Others") { public void actionPerformed(ActionEvent e) { Component selectedComp = getTabbedPane().getSelectedComponent(); String currentName; if (selectedComp instanceof LogPanel) { currentName = getCurrentLogPanel().getIdentifier(); } else if (selectedComp instanceof WelcomePanel) { currentName = ChainsawTabbedPane.WELCOME_TAB; } else { currentName = ChainsawTabbedPane.ZEROCONF; } int count = getTabbedPane().getTabCount(); int index = 0; for (int i = 0; i < count; i++) { String name = getTabbedPane().getTitleAt(index); if (getPanelMap().keySet().contains(name) && !name.equals(currentName)) { displayPanel(name, false); tbms.stateChange(); } else { index++; } } } }; Action showHiddenTabsAction = new AbstractAction("Show All Hidden") { public void actionPerformed(ActionEvent e) { for (Iterator iter = getPanels().entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); Boolean docked = (Boolean) entry.getValue(); if (docked.booleanValue()) { String identifier = (String) entry.getKey(); int count = getTabbedPane().getTabCount(); boolean found = false; for (int i = 0; i < count; i++) { String name = getTabbedPane().getTitleAt(i); if (name.equals(identifier)) { found = true; break; } } if (!found) { displayPanel(identifier, true); tbms.stateChange(); } } } } }; tabPopup.add(hideCurrentTabAction); tabPopup.add(hideOtherTabsAction); tabPopup.addSeparator(); tabPopup.add(showHiddenTabsAction); final PopupListener tabPopupListener = new PopupListener(tabPopup); getTabbedPane().addMouseListener(tabPopupListener); this.handler.addPropertyChangeListener("dataRate", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { double dataRate = ((Double) evt.getNewValue()).doubleValue(); statusBar.setDataRate(dataRate); } }); getSettingsManager().addSettingsListener(this); getSettingsManager().addSettingsListener(MRUFileListPreferenceSaver.getInstance()); getSettingsManager().addSettingsListener(receiversPanel); try { //if an uncaught exception is thrown, allow the UI to continue to load getSettingsManager().loadSettings(); } catch (Exception e) { e.printStackTrace(); } //app preferences have already been loaded (and configuration url possibly set to blank if being overridden) //but we need a listener so the settings will be saved on exit (added after loadsettings was called) getSettingsManager().addSettingsListener(new ApplicationPreferenceModelSaver(applicationPreferenceModel)); setVisible(true); if (applicationPreferenceModel.isReceivers()) { showReceiverPanel(); } else { hideReceiverPanel(); } removeSplash(); synchronized (initializationLock) { isGUIFullyInitialized = true; initializationLock.notifyAll(); } if (noReceiversDefined && applicationPreferenceModel.isShowNoReceiverWarning()) { SwingHelper.invokeOnEDT(new Runnable() { public void run() { showReceiverConfigurationPanel(); } }); } Container container = tutorialFrame.getContentPane(); final JEditorPane tutorialArea = new JEditorPane(); tutorialArea.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); tutorialArea.setEditable(false); container.setLayout(new BorderLayout()); try { tutorialArea.setPage(ChainsawConstants.TUTORIAL_URL); JTextComponentFormatter.applySystemFontAndSize(tutorialArea); container.add(new JScrollPane(tutorialArea), BorderLayout.CENTER); } catch (Exception e) { MessageCenter.getInstance().getLogger().error("Error occurred loading the Tutorial", e); } tutorialFrame.setIconImage(new ImageIcon(ChainsawIcons.HELP).getImage()); tutorialFrame.setSize(new Dimension(640, 480)); final Action startTutorial = new AbstractAction("Start Tutorial", new ImageIcon(ChainsawIcons.ICON_RESUME_RECEIVER)) { public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(null, "This will start 3 \"Generator\" receivers for use in the Tutorial. Is that ok?", "Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { new Thread(new Tutorial()).start(); putValue("TutorialStarted", Boolean.TRUE); } else { putValue("TutorialStarted", Boolean.FALSE); } } }; final Action stopTutorial = new AbstractAction("Stop Tutorial", new ImageIcon(ChainsawIcons.ICON_STOP_RECEIVER)) { public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(null, "This will stop all of the \"Generator\" receivers used in the Tutorial, but leave any other Receiver untouched. Is that ok?", "Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { new Thread(new Runnable() { public void run() { LoggerRepository repo = LogManager.getLoggerRepository(); if (repo instanceof LoggerRepositoryEx) { PluginRegistry pluginRegistry = ((LoggerRepositoryEx) repo).getPluginRegistry(); List list = pluginRegistry.getPlugins(Generator.class); for (Iterator iter = list.iterator(); iter.hasNext();) { Plugin plugin = (Plugin) iter.next(); pluginRegistry.stopPlugin(plugin.getName()); } } } }).start(); setEnabled(false); startTutorial.putValue("TutorialStarted", Boolean.FALSE); } } }; stopTutorial.putValue(Action.SHORT_DESCRIPTION, "Removes all of the Tutorials Generator Receivers, leaving all other Receivers untouched"); startTutorial.putValue(Action.SHORT_DESCRIPTION, "Begins the Tutorial, starting up some Generator Receivers so you can see Chainsaw in action"); stopTutorial.setEnabled(false); final SmallToggleButton startButton = new SmallToggleButton(startTutorial); PropertyChangeListener pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { stopTutorial.setEnabled(((Boolean) startTutorial.getValue("TutorialStarted")).equals(Boolean.TRUE)); startButton.setSelected(stopTutorial.isEnabled()); } }; startTutorial.addPropertyChangeListener(pcl); stopTutorial.addPropertyChangeListener(pcl); pluginRegistry.addPluginListener(new PluginListener() { public void pluginStarted(PluginEvent e) { } public void pluginStopped(PluginEvent e) { List list = pluginRegistry.getPlugins(Generator.class); if (list.size() == 0) { startTutorial.putValue("TutorialStarted", Boolean.FALSE); } } }); final SmallButton stopButton = new SmallButton(stopTutorial); final JToolBar tutorialToolbar = new JToolBar(); tutorialToolbar.setFloatable(false); tutorialToolbar.add(startButton); tutorialToolbar.add(stopButton); container.add(tutorialToolbar, BorderLayout.NORTH); tutorialArea.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (e.getDescription().equals("StartTutorial")) { startTutorial.actionPerformed(null); } else if (e.getDescription().equals("StopTutorial")) { stopTutorial.actionPerformed(null); } else { try { tutorialArea.setPage(e.getURL()); } catch (IOException e1) { MessageCenter.getInstance().getLogger() .error("Failed to change the URL for the Tutorial", e1); } } } } }); /** * loads the saved tab settings and if there are hidden tabs, * hide those tabs out of currently loaded tabs.. */ if (!getTabbedPane().tabSetting.isWelcome()) { displayPanel(ChainsawTabbedPane.WELCOME_TAB, false); } if (!getTabbedPane().tabSetting.isZeroconf()) { displayPanel(ChainsawTabbedPane.ZEROCONF, false); } tbms.stateChange(); }
From source file:org.nuclos.client.common.NuclosCollectController.java
/** * @todo this method is misused - it sets shortcuts for many things other than tabs... * @param frame/*from ww w .jav a 2 s. c o m*/ */ @Override protected void setupShortcutsForTabs(MainFrameTab frame) { final CollectPanel<Clct> pnlCollect = this.getCollectPanel(); final DetailsPanel pnlDetails = this.getDetailsPanel(); final Action actSelectSearchTab = new AbstractAction() { @Override public void actionPerformed(ActionEvent ev) { if (pnlCollect.isTabbedPaneEnabledAt(CollectPanel.TAB_SEARCH)) { pnlCollect.setTabbedPaneSelectedComponent(getSearchPanel()); } } }; KeyBindingProvider.bindActionToComponent(KeyBindingProvider.ACTIVATE_SEARCH_PANEL_1, actSelectSearchTab, pnlCollect); KeyBindingProvider.bindActionToComponent(KeyBindingProvider.ACTIVATE_SEARCH_PANEL_2, actSelectSearchTab, pnlCollect); //TODO This is a workaround. The detailpanel should keep the focus final Action actGrabFocus = new AbstractAction() { @Override public void actionPerformed(ActionEvent ev) { pnlDetails.grabFocus(); } }; /** * A <code>ChainedAction</code> is an action composed of a primary and a secondary action. * It behaves exactly like the primary action, except that additionally, the secondary action is performed * after the primary action. */ class ChainedAction implements Action { private final Action actPrimary; private final Action actSecondary; public ChainedAction(Action actPrimary, Action actSecondary) { this.actPrimary = actPrimary; this.actSecondary = actSecondary; } @Override public void addPropertyChangeListener(PropertyChangeListener listener) { actPrimary.addPropertyChangeListener(listener); } @Override public Object getValue(String sKey) { return actPrimary.getValue(sKey); } @Override public boolean isEnabled() { return actPrimary.isEnabled(); } @Override public void putValue(String sKey, Object oValue) { actPrimary.putValue(sKey, oValue); } @Override public void removePropertyChangeListener(PropertyChangeListener listener) { actPrimary.removePropertyChangeListener(listener); } @Override public void setEnabled(boolean bEnabled) { actPrimary.setEnabled(bEnabled); } @Override public void actionPerformed(ActionEvent ev) { actPrimary.actionPerformed(ev); actSecondary.actionPerformed(ev); } } //final Action actRefresh = new ChainedAction(this.getRefreshCurrentCollectableAction(), actGrabFocus); this.getCollectPanel().setTabbedPaneToolTipTextAt(CollectPanel.TAB_SEARCH, getSpringLocaleDelegate().getMessage("NuclosCollectController.13", "Suche (F7) (Strg+F)")); this.getCollectPanel().setTabbedPaneToolTipTextAt(CollectPanel.TAB_RESULT, getSpringLocaleDelegate().getMessage("NuclosCollectController.7", "Ergebnis (F8)")); this.getCollectPanel().setTabbedPaneToolTipTextAt(CollectPanel.TAB_DETAILS, getSpringLocaleDelegate().getMessage("NuclosCollectController.3", "Details (F2)")); // the search action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.START_SEARCH, this.getSearchAction(), pnlCollect); KeyBinding keybinding = KeyBindingProvider.REFRESH; // the refresh action KeyBindingProvider.removeActionFromComponent(keybinding, pnlDetails); pnlDetails.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keybinding.getKeystroke(), keybinding.getKey()); pnlDetails.getActionMap().put(keybinding.getKey(), this.getRefreshCurrentCollectableAction()); KeyBindingProvider.removeActionFromComponent(keybinding, getResultPanel()); getResultPanel().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keybinding.getKeystroke(), keybinding.getKey()); getResultPanel().getActionMap().put(keybinding.getKey(), getResultPanel().btnRefresh.getAction()); // the new action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.NEW, this.getNewAction(), pnlDetails); // the new with search values action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.NEW_SEARCHVALUE, this.getNewWithSearchValuesAction(), pnlCollect); // the save action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.SAVE_1, this.getSaveAction(), pnlCollect); KeyBindingProvider.bindActionToComponent(KeyBindingProvider.SAVE_2, this.getSaveAction(), pnlCollect); // first the navigation actions are performed and then the focus is grabbed: final Action actFirst = new ChainedAction(this.getFirstAction(), actGrabFocus); final Action actLast = new ChainedAction(this.getLastAction(), actGrabFocus); final Action actPrevious = new ChainedAction(this.getPreviousAction(), actGrabFocus); final Action actNext = new ChainedAction(this.getNextAction(), actGrabFocus); // the first action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.FIRST, actFirst, pnlDetails); pnlDetails.btnFirst.setAction(actFirst); // the last action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.LAST, actLast, pnlDetails); pnlDetails.btnLast.setAction(actLast); // the previous action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.PREVIOUS_1, actPrevious, pnlDetails); KeyBindingProvider.bindActionToComponent(KeyBindingProvider.PREVIOUS_2, actPrevious, pnlDetails); pnlDetails.btnPrevious.setAction(actPrevious); // the next action KeyBindingProvider.bindActionToComponent(KeyBindingProvider.NEXT_1, actNext, pnlDetails); KeyBindingProvider.bindActionToComponent(KeyBindingProvider.NEXT_2, actNext, pnlDetails); pnlDetails.btnNext.setAction(actNext); Action actClose = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { getTab().dispose(); } }; KeyBindingProvider.bindActionToComponent(KeyBindingProvider.CLOSE_CHILD, actClose, pnlCollect); if (getResultPanel() != null && getResultTable() != null) { final JButton btnEdit = getResultPanel().btnEdit; KeyBindingProvider.bindActionToComponent(KeyBindingProvider.EDIT_1, btnEdit.getAction(), getResultTable()); if (getResultTable().getActionMap().get(KeyBindingProvider.EDIT_2.getKey()) == null) KeyBindingProvider.bindActionToComponent(KeyBindingProvider.EDIT_2, btnEdit.getAction(), getResultTable()); } }
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/* w ww. jav a 2 s.co 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
/** * Create a button to go inside of the toolbar. By default this * will load an image resource. The image filename is relative to * the classpath (including the '.' directory if its a part of the * classpath), and may either be in a JAR file or a separate file. * * @param key The key in the resource file to serve as the basis * of lookups.//from w w w. j av a 2 s.c o m * @return Button */ protected AbstractButton createToolbarButton(String key) { ImageIcon ii = JmolResourceHandler.getIconX(key + "Image"); AbstractButton b = new JButton(ii); String isToggleString = JmolResourceHandler.getStringX(key + "Toggle"); if (isToggleString != null) { boolean isToggle = Boolean.valueOf(isToggleString).booleanValue(); if (isToggle) { b = new JToggleButton(ii); if (key.equals("rotate")) buttonRotate = b; toolbarButtonGroup.add(b); String isSelectedString = JmolResourceHandler.getStringX(key + "ToggleSelected"); if (isSelectedString != null) { boolean isSelected = Boolean.valueOf(isSelectedString).booleanValue(); b.setSelected(isSelected); } } } b.setRequestFocusEnabled(false); b.setMargin(new Insets(1, 1, 1, 1)); Action a = null; String actionCommand = null; if (key.endsWith("Script")) { actionCommand = JmolResourceHandler.getStringX(key); a = executeScriptAction; } else { actionCommand = key; a = getAction(key); } if (a != null) { b.setActionCommand(actionCommand); b.addActionListener(a); a.addPropertyChangeListener(new ActionChangedListener(b)); b.setEnabled(a.isEnabled()); } else { b.setEnabled(false); } String tip = guimap.getLabel(key + "Tip"); if (tip != null) { b.setToolTipText(tip); } return b; }
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 a va 2 s. co m if (newAction instanceof ToggleStateAction) { final ToggleStateAction tsa = (ToggleStateAction) action; setSelected(tsa.isSelected()); } } }
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);/* w w w . j a v a 2s .co m*/ 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:tk.tomby.tedit.gui.MenuItem.java
/** * DOCUMENT ME!/*from w w w. j a v a 2 s . co m*/ * * @param action DOCUMENT ME! */ public void setAction(Action action) { action.addPropertyChangeListener(createActionPropertyChangeListener(action)); this.setEnabled(action.isEnabled()); this.addActionListener(action); }