de.sciss.gui
Class MenuAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by de.sciss.gui.MenuAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action
Direct Known Subclasses:
BasicMenuFactory.ActionOpenRecent, BasicMenuFactory.ActionPreferences, BasicMenuFactory.ActionShowWindow, PrefMenuAction, ShowWindowAction

public abstract class MenuAction
extends javax.swing.AbstractAction

A simple extension of AbstractAction that puts a KeyStroke into its ACCELERATOR_KEY field. This field is read when the action is attached to a JMenuItem.

Version:
0.2, 01-Oct-05
Author:
Hanns Holger Rutz
See Also:
JMenuItem.setAccelerator( KeyStroke ), JMenuItem.configurePropertiesFromAction( Action ), AbstractButton.setAction( Action ), Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
MenuAction()
          Constructs a new MenuAction without name and accelerator key.
MenuAction(java.lang.String text)
          Constructs a new MenuAction without accelerator key.
MenuAction(java.lang.String text, javax.swing.KeyStroke shortcut)
          Constructs a new MenuAction with the given text and accelerator shortcut which will be used when the action is attached to a JMenuItem.
 
Method Summary
abstract  void actionPerformed(java.awt.event.ActionEvent e)
           
 void deinstallFrom(javax.swing.JComponent c, int condition)
          Deinstalls this action from the keyboard input and action map of the given component.
 void installOn(javax.swing.JComponent c, int condition)
          Installs this action on the keyboard input and action map of the given component.
 void mimic(javax.swing.Action a)
          Copies the mappings of a given Action to this Action.
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MenuAction

public MenuAction(java.lang.String text,
                  javax.swing.KeyStroke shortcut)
Constructs a new MenuAction with the given text and accelerator shortcut which will be used when the action is attached to a JMenuItem.

Parameters:
text - text to display in the menu item
shortcut - KeyStroke for the menu item's accelerator or null

MenuAction

public MenuAction(java.lang.String text)
Constructs a new MenuAction without accelerator key.

Parameters:
text - text to display in the menu item

MenuAction

public MenuAction()
Constructs a new MenuAction without name and accelerator key.

Method Detail

mimic

public void mimic(javax.swing.Action a)
Copies the mappings of a given Action to this Action. The entries which are copied are name, key short cuts and descriptions. Therefore a menu item carrying this action will look exactly like the one associated with the passed in action. Also the enabled flag is toggled accordingly.

Parameters:
a - an Action from which to copy the mapping entries

installOn

public void installOn(javax.swing.JComponent c,
                      int condition)
Installs this action on the keyboard input and action map of the given component.

Parameters:
c - the component to install the action on
condition - either of JComponent.WHEN_FOCUSED, JComponent.WHEN_IN_FOCUSED_WINDOW, or JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT.

deinstallFrom

public void deinstallFrom(javax.swing.JComponent c,
                          int condition)
Deinstalls this action from the keyboard input and action map of the given component.

Parameters:
c - the component to remove the action from
condition - either of JComponent.WHEN_FOCUSED, JComponent.WHEN_IN_FOCUSED_WINDOW, or JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT.

actionPerformed

public abstract void actionPerformed(java.awt.event.ActionEvent e)