站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc 5.0.0

SystemAction (NetBeans Utilities API) - NetBeans API Javadoc 5.0.0

 

org.openide.util.actions
Class SystemAction

java.lang.Object
  extended byorg.openide.util.SharedClassObject
      extended byorg.openide.util.actions.SystemAction
All Implemented Interfaces:
Action, ActionListener, EventListener, Externalizable, HelpCtx.Provider, Serializable
Direct Known Subclasses:
BooleanStateAction, CallableSystemAction

public abstract class SystemAction
extends SharedClassObject
implements Action, HelpCtx.Provider

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)
          Deprecated. Use Utilities.actionsToPopup(javax.swing.Action[], org.openide.util.Lookup)
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, reset, 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.

See Also:
Constant Field Values

PROP_ICON

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

See Also:
Constant Field Values
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.

Specified by:
getHelpCtx in interface HelpCtx.Provider
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, Action.SMALL_ICON and "iconBase" are also recognized and delegated to getName(), getIcon() and iconResource() 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.

Since 4.11, will be performed directly in the event thread.

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; the default is to have no icon. Typically this should be a 16x16 color GIF. Do not use relative paths nor an initial slash. If e.g. myIcon.gif is accompanied with myIcon_pressed.gif, myIcon_disabled.gif and/or myIcon_rollover.gif these images are used to call methods on JButton.setPressedIcon(), JButton.setDisabledIcon() and/or JButton.setRolloverIcon() with appropriate images. Please check Actions.connect for additional info how this is achieved (using special "iconBase" key for getValue). As of APIs version 3.24, this path will be used for a localized search automatically. If you do not want an icon, do not override this to return a blank icon. Leave it null, but call putValue("noIconInMenu", Boolean.TRUE) to make sure that no extra space is allotted for an icon in the menu item.

Returns:
the resource name for the icon, e.g. com/mycom/mymodule/myIcon.gif; or null to have no icon (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
actions2 - 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)
Deprecated. Use Utilities.actionsToPopup(javax.swing.Action[], org.openide.util.Lookup)

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 May 3 2007.  |  Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.