java.awt.event.ActionListener, java.util.EventListener, javax.swing.Action, HelpCtx.ProviderBooleanStateAction, CallableSystemActionpublic abstract class SystemAction extends SharedClassObject implements javax.swing.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 | Description |
|---|---|---|
static java.lang.String |
PROP_ENABLED |
Name of property indicating whether or not the action is enabled.
|
static java.lang.String |
PROP_ICON |
Name of property for the action's display icon.
|
| Constructor | Description |
|---|---|
SystemAction() |
| Modifier and Type | Method | Description |
|---|---|---|
abstract void |
actionPerformed(java.awt.event.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 javax.swing.JPopupMenu |
createPopupMenu(SystemAction[] actions) |
|
static javax.swing.JToolBar |
createToolbarPresenter(SystemAction[] actions) |
Create the default toolbar representation of an array of actions.
|
static <T extends SystemAction> |
get(java.lang.Class<T> actionClass) |
Obtain a singleton instance of the action with a specified class.
|
abstract HelpCtx |
getHelpCtx() |
Get a help context for the action.
|
javax.swing.Icon |
getIcon() |
Get the action's display icon.
|
javax.swing.Icon |
getIcon(boolean createLabel) |
Get the action's display icon, possibly creating a text label.
|
abstract java.lang.String |
getName() |
Get a human presentable name of the action.
|
java.lang.Object |
getValue(java.lang.String name) |
Get a property in the singleton.
|
protected java.lang.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(java.lang.String name,
java.lang.Object value) |
Set a property in the singleton.
|
void |
setEnabled(boolean value) |
Set whether the action should be enabled.
|
void |
setIcon(javax.swing.Icon icon) |
Set the action's display icon.
|
accept, addPropertyChangeListener, removePropertyChangeListenerclone, getClass, notify, notifyAll, toString, wait, wait, waitaddNotify, addPropertyChangeListener, equals, finalize, findObject, findObject, firePropertyChange, getLock, getProperty, hashCode, putProperty, putProperty, readExternal, removeNotify, removePropertyChangeListener, reset, writeExternal, writeReplacepublic static final java.lang.String PROP_ENABLED
public static final java.lang.String PROP_ICON
public static <T extends SystemAction> T get(java.lang.Class<T> actionClass)
actionClass - the class of the action to findjava.lang.ClassCastException - if the class is not SystemActionjava.lang.IllegalArgumentException - if the instance cannot be createdpublic abstract java.lang.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.Providerpublic boolean isEnabled()
isEnabled in interface javax.swing.Actiontrue if sopublic void setEnabled(boolean value)
setEnabled in interface javax.swing.Actionvalue - true to enable itpublic final void putValue(java.lang.String name,
java.lang.Object value)
putValue in interface javax.swing.Actionname - the name of the propertyvalue - the valuepublic final java.lang.Object getValue(java.lang.String name)
Action.NAME, Action.SMALL_ICON and "iconBase" are also recognized
and delegated to getName(), getIcon() and iconResource() resp.getValue in interface javax.swing.Actionname - the name of the propertypublic abstract void actionPerformed(java.awt.event.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 java.awt.event.ActionListenerev - the event triggering the actionprotected void initialize()
initialize in class SharedClassObjectprotected boolean clearSharedData()
clearSharedData in class SharedClassObjectfalse in the default implementationpublic final void setIcon(javax.swing.Icon icon)
icon - the iconpublic final javax.swing.Icon getIcon()
java.lang.IllegalStateException - if an icon could not be createdpublic final javax.swing.Icon getIcon(boolean createLabel)
createLabel - if true, create a textual icon if otherwise there
would be none; if false, create a blank iconjava.lang.IllegalStateException - if an icon could not be createdprotected java.lang.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 javax.swing.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 javax.swing.JPopupMenu createPopupMenu(SystemAction[] actions)
actions - actions to show in the generated menuBuilt on April 24 2018. | Portions Copyright 1997-2018 Oracle. All rights reserved.