Class Action
- java.lang.Object
-
- org.apache.pivot.wtk.Action
-
public abstract class Action extends java.lang.Object
Abstract base class for "actions". Actions are common application behaviors generally triggered by buttons, menu items, and keyboard shortcuts.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Action.Callback
A callback for the GUI thread to perform the given action there, unless the action is disabled at the timerun()
is called.static class
Action.NamedActionDictionary
Action dictionary implementation.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <E extends java.lang.Enum<E>>
ActionaddNamedAction(E actionName, Action action)
Add this action to the named action dictionary.static Action
addNamedAction(java.lang.String actionName, Action action)
Add this action to the named action dictionary.static ListenerList<ActionClassListener>
getActionClassListeners()
ListenerList<ActionListener>
getActionListeners()
java.lang.String
getDescription()
Returns a text description of the action.static <E extends java.lang.Enum<E>>
ActiongetNamedAction(E actionName)
Get the named action from the dictionary.static Action
getNamedAction(java.lang.String actionName)
Get the named action from the dictionary.static Action.NamedActionDictionary
getNamedActions()
boolean
isEnabled()
Check if this action is currently enabled.abstract void
perform(Component source)
Performs the action.static <E extends java.lang.Enum<E>>
voidperformAction(E actionName, Component comp)
Perform the named action, unless the action is disabled.static void
performAction(java.lang.String actionName, Component comp)
Perform the named action, unless the action is disabled.void
setEnabled(boolean enabledState)
Set this action enabled or disabled.
-
-
-
Constructor Detail
-
Action
public Action()
Constructor which builds the action and sets it enabled to begin with.
-
Action
public Action(boolean initialEnable)
Constructor to build the action and set the enabled state at the beginning.- Parameters:
initialEnable
- Whether the action is to be initially enabled.
-
-
Method Detail
-
getDescription
public java.lang.String getDescription()
Returns a text description of the action. Subclasses should override this to return a meaningful description if one is needed.- Returns:
- The text description of the action.
-
perform
public abstract void perform(Component source)
Performs the action.- Parameters:
source
- The component that initiated the action.
-
performAction
public static void performAction(java.lang.String actionName, Component comp)
Perform the named action, unless the action is disabled.This is the equivalent of
Action.getNamedActions().get(actionName).perform(comp)
.- Parameters:
actionName
- One of the previously defined action names.comp
- The component initiating the action.- Throws:
java.lang.IllegalArgumentException
- if the actionName isnull
or if there is no action with that name.
-
performAction
public static <E extends java.lang.Enum<E>> void performAction(E actionName, Component comp)
Perform the named action, unless the action is disabled.This is the equivalent of
Action.getNamedActions().get(actionName).perform(comp)
.- Type Parameters:
E
- Enum type that gives the action name.- Parameters:
actionName
- An enum value whosetoString()
value is used as the action name.comp
- The component initiating the action.- Throws:
java.lang.IllegalArgumentException
- if the actionName isnull
or if there is no action with that name.
-
isEnabled
public boolean isEnabled()
Check if this action is currently enabled.- Returns:
- Whether or not this action is currently enabled.
- See Also:
setEnabled(boolean)
-
setEnabled
public void setEnabled(boolean enabledState)
Set this action enabled or disabled.Note: in general, the
perform(org.apache.pivot.wtk.Component)
method can be called whether or not this flag is set, so it will be incumbent on the caller to determine if this is appropriate. However, using theAction.Callback
class or theperformAction(java.lang.String, org.apache.pivot.wtk.Component)
method WILL check this flag before callingperform(org.apache.pivot.wtk.Component)
.Also note: buttons and menu items that invoke this action will automatically be enabled/disabled by setting this flag.
If the enabled state changes, the associated
ActionListener.enabledChanged(org.apache.pivot.wtk.Action)
method(s) will be called.- Parameters:
enabledState
- The new enabled state for the action.
-
addNamedAction
public static Action addNamedAction(java.lang.String actionName, Action action)
Add this action to the named action dictionary.This is equivalent to
getNamedActions().put(actionName, action)
- Parameters:
actionName
- The name to store this action under (can be referenced from button actions, etc.)action
- The action to be performed under this name.- Returns:
- The previous action (if any) listed under this name.
-
addNamedAction
public static <E extends java.lang.Enum<E>> Action addNamedAction(E actionName, Action action)
Add this action to the named action dictionary.This is equivalent to
getNamedActions().put(actionName, action)
- Type Parameters:
E
- Enum type that gives the action name.- Parameters:
actionName
- An enum whosetoString()
value is used as the ID for the action.action
- The action to be performed under this name.- Returns:
- The previous action (if any) listed under this name.
- Throws:
java.lang.IllegalArgumentException
- if the actionName isnull
.
-
getNamedAction
public static Action getNamedAction(java.lang.String actionName)
Get the named action from the dictionary.This is the equivalent of
getNamedActions().get(actionName)
- Parameters:
actionName
- The name this action was stored under in the dictionary.- Returns:
- The action currently associated with this name (or
null
if there is no saved action with that name value).
-
getNamedAction
public static <E extends java.lang.Enum<E>> Action getNamedAction(E actionName)
Get the named action from the dictionary.This is the equivalent of
getNamedActions().get(actionName)
- Type Parameters:
E
- Enum type that gives the action name.- Parameters:
actionName
- An enum whosetoString()
method is used as the ID for the action.- Returns:
- The action currently associated with this name (or
null
if there is no saved action with that name value). - Throws:
java.lang.IllegalArgumentException
- if the actionName isnull
.
-
getNamedActions
public static Action.NamedActionDictionary getNamedActions()
- Returns:
- The global named action dictionary.
-
getActionListeners
public ListenerList<ActionListener> getActionListeners()
- Returns:
- The list of listeners for this action.
-
getActionClassListeners
public static ListenerList<ActionClassListener> getActionClassListeners()
- Returns:
- The list of listeners for all action activities.
-
-