org.openide.util.actions
Class SystemAction

java.lang.Object
  |
  +--org.openide.util.SharedClassObject
        |
        +--org.openide.util.actions.SystemAction
All Implemented Interfaces:
Action, ActionListener, EventListener, Externalizable, Serializable
Direct Known Subclasses:
BooleanStateAction, CallableSystemAction, FileSystemAction, HelpAction, ToolsAction

public abstract class SystemAction
extends SharedClassObject
implements Action

The common predecessor of callable actions in the IDE.

Also implements the Swing Action to enable use with the Swing action model.

An action class is a singleton, i.e. should generally contain no instance state. Rather, subclassing and use of abstract protected methods should be used to create variants of the action.

While it is possible to subclass this class directly--for example, if your "action" is really a placeholder for a popup menu that shows other actions--most people will prefer to use one of the subclasses, which are more convenient.

See Also:
Serialized Form

Field Summary
static String PROP_ENABLED
          Name of property indicating whether or not the action is enabled.
static String PROP_ICON
          Name of property for the action's display icon.
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
SystemAction()
           
 
Method Summary
abstract  void actionPerformed(ActionEvent ev)
          Actually perform the action.
protected  boolean clearSharedData()
          Indicate whether action state should be cleared after the last action of this class is deleted.
static JPopupMenu createPopupMenu(SystemAction[] actions)
          Create the default popup menu representation of an array of actions.
static JToolBar createToolbarPresenter(SystemAction[] actions)
          Create the default toolbar representation of an array of actions.
static SystemAction get(Class actionClass)
          Obtain a singleton instance of the action with a specified class.
abstract  HelpCtx getHelpCtx()
          Get a help context for the action.
 Icon getIcon()
          Get the action's display icon.
 Icon getIcon(boolean createLabel)
          Get the action's display icon, possibly creating a text label.
abstract  String getName()
          Get a human presentable name of the action.
 Object getValue(String name)
          Get a property in the singleton.
protected  String iconResource()
          Specify the proper resource name for the action's icon.
protected  void initialize()
          Initialize the action.
 boolean isEnabled()
          Test whether the action is currently enabled.
static SystemAction[] linkActions(SystemAction[] actions1, SystemAction[] actions2)
          Concatenate two arrays of actions.
 void putValue(String name, Object value)
          Set a property in the singleton.
 void setEnabled(boolean value)
          Set whether the action should be enabled.
 void setIcon(Icon icon)
          Set the action's display icon.
 
Methods inherited from class org.openide.util.SharedClassObject
addNotify, addPropertyChangeListener, equals, finalize, findObject, findObject, firePropertyChange, getLock, getProperty, hashCode, putProperty, putProperty, readExternal, removeNotify, removePropertyChangeListener, writeExternal, writeReplace
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.Action
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

PROP_ENABLED

public static final String PROP_ENABLED
Name of property indicating whether or not the action is enabled.

PROP_ICON

public static final String PROP_ICON
Name of property for the action's display icon.
Constructor Detail

SystemAction

public SystemAction()
Method Detail

get

public static SystemAction get(Class actionClass)
Obtain a singleton instance of the action with a specified class. If there already is a instance then it is returned, otherwise a new one is created.
Parameters:
actionClass - the class of the action to find
Returns:
the singleton action instance
Throws:
ClassCastException - if the class is not SystemAction
IllegalArgumentException - if the instance cannot be created

getName

public abstract String getName()
Get a human presentable name of the action. This may be presented as an item in a menu.

Using the normal menu presenters, an included ampersand before a letter will be treated as the name of a mnemonic.

Returns:
the name of the action

getHelpCtx

public abstract HelpCtx getHelpCtx()
Get a help context for the action.
Returns:
the help context for this action

isEnabled

public boolean isEnabled()
Test whether the action is currently enabled.
Specified by:
isEnabled in interface Action
Returns:
true if so

setEnabled

public void setEnabled(boolean value)
Set whether the action should be enabled.
Specified by:
setEnabled in interface Action
Parameters:
value - true to enable it

putValue

public final void putValue(String name,
                           Object value)
Set a property in the singleton. This property is common for all instances of the same class.
Specified by:
putValue in interface Action
Parameters:
name - the name of the property
value - the value

getValue

public final Object getValue(String name)
Get a property in the singleton. Values are shared among all instances of the same class. The special tokens Action.NAME and Action.SMALL_ICON are also recognized and delegated to getName() and getIcon(), resp.
Specified by:
getValue in interface Action
Parameters:
name - the name of the property
Returns:
the value

actionPerformed

public abstract void actionPerformed(ActionEvent ev)
Actually perform the action. Specified in ActionListener.actionPerformed(java.awt.event.ActionEvent).

In some cases, the implementation may have an empty body, if the presenters handle the performing of the action in a different way than by calling this method.

When run in the normal way from the action manager (e.g. as part of a standard menu or toolbar presenter), the action body can block and take time, but needs to explicitly ask to enter the AWT event thread if doing any GUI work. See the Threading Models document in API documentation for details.

Specified by:
actionPerformed in interface ActionListener
Parameters:
ev - the event triggering the action

initialize

protected void initialize()
Initialize the action. The default implementation just enabled it.
Overrides:
initialize in class SharedClassObject

clearSharedData

protected boolean clearSharedData()
Indicate whether action state should be cleared after the last action of this class is deleted.
Overrides:
clearSharedData in class SharedClassObject
Returns:
false in the default implementation

setIcon

public final void setIcon(Icon icon)
Set the action's display icon.
Parameters:
icon - the icon

getIcon

public final Icon getIcon()
Get the action's display icon.
Returns:
the icon
Throws:
IllegalStateException - if an icon could not be created

getIcon

public final Icon getIcon(boolean createLabel)
Get the action's display icon, possibly creating a text label.
Parameters:
createLabel - if true, create a textual icon if otherwise there would be none; if false, create a blank icon
Returns:
an icon
Throws:
IllegalStateException - if an icon could not be created

iconResource

protected String iconResource()
Specify the proper resource name for the action's icon. May be overridden by subclasses. Typically this should be a 16x16 color GIF.
Returns:
the resource name for the icon, e.g. /com/mycom/mymodule/myIcon.gif; or null to make a text label

createToolbarPresenter

public static JToolBar createToolbarPresenter(SystemAction[] actions)
Create the default toolbar representation of an array of actions. Null items in the array will add a separator to the toolbar.
Parameters:
actions - actions to show in the generated toolbar
Returns:
a toolbar instance displaying them

linkActions

public static SystemAction[] linkActions(SystemAction[] actions1,
                                         SystemAction[] actions2)
Concatenate two arrays of actions.
Parameters:
actions1 - first array of actions to link
actions1 - second array of actions to link
Returns:
an array of both sets of actions in the same order

createPopupMenu

public static JPopupMenu createPopupMenu(SystemAction[] actions)
Create the default popup menu representation of an array of actions.
Parameters:
actions - actions to show in the generated menu
Returns:
a popup menu displaying them


Built on December 12 2001.  |  Portions Copyright 1997-2001 Sun Microsystems, Inc. All rights reserved.