public abstract class SystemAction extends SharedClassObject implements Action, HelpCtx.Provider
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.
Modifier and Type | Field and Description |
---|---|
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.
|
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 and Description |
---|
SystemAction() |
Modifier and Type | Method and Description |
---|---|
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)
|
static JToolBar |
createToolbarPresenter(SystemAction[] actions)
Create the default toolbar representation of an array of actions.
|
static <T extends SystemAction> |
get(Class<T> 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.
|
addNotify, addPropertyChangeListener, equals, finalize, findObject, findObject, firePropertyChange, getLock, getProperty, hashCode, putProperty, putProperty, readExternal, removeNotify, removePropertyChangeListener, reset, writeExternal, writeReplace
clone, getClass, notify, notifyAll, toString, wait, wait, wait
accept, addPropertyChangeListener, removePropertyChangeListener
public static final String PROP_ENABLED
public static final String PROP_ICON
public static <T extends SystemAction> T get(Class<T> actionClass)
actionClass
- the class of the action to findClassCastException
- if the class is not SystemAction
IllegalArgumentException
- if the instance cannot be createdpublic abstract String getName()
Using the normal menu presenters, an included ampersand before a letter will be treated as the name of a mnemonic.
public abstract HelpCtx getHelpCtx()
getHelpCtx
in interface HelpCtx.Provider
public boolean isEnabled()
public void setEnabled(boolean value)
setEnabled
in interface Action
value
- true
to enable itpublic final void putValue(String name, Object value)
public final Object getValue(String name)
Action.NAME
, Action.SMALL_ICON
and "iconBase" are also recognized
and delegated to SystemAction.getName()
, SystemAction.getIcon()
and SystemAction.iconResource()
resp.public abstract void actionPerformed(ActionEvent ev)
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.
actionPerformed
in interface ActionListener
ev
- the event triggering the actionprotected void initialize()
initialize
in class SharedClassObject
protected boolean clearSharedData()
clearSharedData
in class SharedClassObject
false
in the default implementationpublic final void setIcon(Icon icon)
icon
- the iconpublic final Icon getIcon()
IllegalStateException
- if an icon could not be createdpublic final Icon getIcon(boolean createLabel)
createLabel
- if true
, create a textual icon if otherwise there
would be none; if false
, create a blank iconIllegalStateException
- if an icon could not be createdprotected String iconResource()
putValue("noIconInMenu", Boolean.TRUE)
to make sure that no extra space is allotted for an icon in the menu item.com/mycom/mymodule/myIcon.gif
; or null
to have no icon (make a text label)public static JToolBar createToolbarPresenter(SystemAction[] actions)
actions
- actions to show in the generated toolbarpublic static SystemAction[] linkActions(SystemAction[] actions1, SystemAction[] actions2)
actions1
- first array of actions to linkactions2
- second array of actions to link@Deprecated public static JPopupMenu createPopupMenu(SystemAction[] actions)
actions
- actions to show in the generated menu