Class SystemAction
- All Implemented Interfaces:
ActionListener, Externalizable, Serializable, EventListener, Action, HelpCtx.Provider
- Direct Known Subclasses:
BooleanStateAction, CallableSystemAction
Implements the Swing Action interface 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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of property indicating whether or not the action is enabled.static final StringName of property for the action's display icon.Fields inherited from interface Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidActually perform the action.protected booleanIndicate whether action state should be cleared after the last action of this class is deleted.static JPopupMenucreatePopupMenu(SystemAction[] actions) Deprecated.static JToolBarcreateToolbarPresenter(SystemAction[] actions) Create the default toolbar representation of an array of actions.static <T extends SystemAction>
TObtain a singleton instance of the action with a specified class.abstract HelpCtxGet a help context for the action.final IcongetIcon()Get the action's display icon.final IcongetIcon(boolean createLabel) Get the action's display icon, possibly creating a text label.abstract StringgetName()Get a human presentable name of the action.final ObjectGet a property in the singleton.protected StringSpecify the proper resource name for the action's icon.protected voidInitialize the action.booleanTest whether the action is currently enabled.static SystemAction[]linkActions(SystemAction[] actions1, SystemAction[] actions2) Concatenate two arrays of actions.final voidSet a property in the singleton.voidsetEnabled(boolean value) Set whether the action should be enabled.final voidSet the action's display icon.Methods inherited from class SharedClassObject
addNotify, addPropertyChangeListener, equals, finalize, findObject, findObject, firePropertyChange, getLock, getProperty, hashCode, putProperty, putProperty, readExternal, removeNotify, removePropertyChangeListener, reset, writeExternal, writeReplaceMethods inherited from interface Action
accept, addPropertyChangeListener, removePropertyChangeListener
-
Field Details
-
PROP_ENABLED
Name of property indicating whether or not the action is enabled.- See Also:
-
PROP_ICON
-
-
Constructor Details
-
SystemAction
public SystemAction()
-
-
Method Details
-
get
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 notSystemActionIllegalArgumentException- if the instance cannot be created
-
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
Get a help context for the action.- Specified by:
getHelpCtxin interfaceHelpCtx.Provider- Returns:
- the help context for this action
-
isEnabled
-
setEnabled
public void setEnabled(boolean value) Set whether the action should be enabled.- Specified by:
setEnabledin interfaceAction- Parameters:
value-trueto enable it
-
putValue
-
getValue
Get a property in the singleton. Values are shared among all instances of the same class. The special tokensAction.NAME,Action.SMALL_ICONand "iconBase" are also recognized and delegated togetName(),getIcon()andiconResource()resp. -
actionPerformed
Actually perform the action. Specified inActionListener.actionPerformed(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:
actionPerformedin interfaceActionListener- Parameters:
ev- the event triggering the action
-
initialize
protected void initialize()Initialize the action. The default implementation just enabled it.- Overrides:
initializein classSharedClassObject
-
setIcon
-
getIcon
Get the action's display icon.- Returns:
- the icon
- Throws:
IllegalStateException- if an icon could not be created
-
getIcon
Get the action's display icon, possibly creating a text label.- Parameters:
createLabel- iftrue, create a textual icon if otherwise there would be none; iffalse, create a blank icon- Returns:
- an icon
- Throws:
IllegalStateException- if an icon could not be created
-
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 callputValue("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; ornullto have no icon (make a text label)
-
createToolbarPresenter
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
Concatenate two arrays of actions.- Parameters:
actions1- first array of actions to linkactions2- second array of actions to link- Returns:
- an array of both sets of actions in the same order
-
createPopupMenu
Deprecated.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
-
Utilities.actionsToPopup(Action[], Lookup)