Class ActionManager
- All Implemented Interfaces:
Serializable
javax.swing.Action
s for an
application. There are convenience methods for getting and setting the state
of the action.
All of these elements have a unique id tag which is used by the ActionManager
to reference the action. This id maps to the Action.ACTION_COMMAND_KEY
on the Action.
The ActionManager may be used to conveniently register callback methods on BoundActions.
A typical use case of the ActionManager is:
ActionManager manager = ActionManager.getInstance(); // load Actions manager.addAction(action); // Change the state of the action: manager.setEnabled("new-action", newState);The ActionManager also supports Actions that can have a selected state associated with them. These Actions are typically represented by a JCheckBox or similar widget. For such actions the registered method is invoked with an additional parameter indicating the selected state of the widget. For example, for the callback handler:
public class Handler { public void stateChanged(boolean newState); }The registration method would look similar:
manager.registerCallback("select-action", new Handler(), "stateChanged");
The stateChanged method would be invoked as the selected state of
the widget changed. Additionally if you need to change the selected
state of the Action use the ActionManager method setSelected
.
The ActionContainerFactory
uses the managed Actions in a
ActionManager to create user interface components. It uses the shared
instance of ActionManager by default. For example, to create a JMenu based on an
action-list id:
ActionContainerFactory factory = new ActionContainerFactory(); JMenu file = factory.createMenu(list);
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static ActionManager
Shared instance of the singleton ActionManager. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds an action to the ActionManagerRetrieves the action corresponding to an action id.Returns the ids for all the managed actions.getBoundAction
(Object id) Convenience method for returning the BoundActionConvenience method for returning the CompositeActionstatic ActionManager
Return the instance of the ActionManger.Convenience method for returning the ServerActionprivate AbstractActionExt
Convenience method for returning the StateChangeActionConvenience method for returning the TargetableActionboolean
isBoundAction
(Object id) Test to determine if the action is aBoundAction
boolean
Test to determine if the action is aBoundAction
boolean
Returns the enabled state of theAction
.boolean
isSelected
(Object id) Gets the selected state of a toggle action.boolean
isServerAction
(Object id) Test to determine if the action is aServerAction
boolean
isStateAction
(Object id) Determines if the Action corresponding to the action id is a state changed action (toggle, group type action).boolean
Test to determine if the action is aTargetableAction
(package private) static void
printAction
(PrintStream stream, Action action) A diagnostic which prints the Attributes of an action on the printStreamvoid
registerCallback
(Object id, Object handler, String method) Convenience method to register a callback method on aBoundAction
void
setEnabled
(Object id, boolean enabled) Enables or disables the state of the Action corresponding to the action id.static void
setInstance
(ActionManager manager) Sets the ActionManager instance.void
setSelected
(Object id, boolean selected) Sets the selected state of a toggle action.
-
Field Details
-
INSTANCE
Shared instance of the singleton ActionManager.
-
-
Constructor Details
-
ActionManager
public ActionManager()Creates the action manager. Use this constuctor if the application should support many ActionManagers. Otherwise, using the getInstance method will return a singleton.
-
-
Method Details
-
getInstance
Return the instance of the ActionManger. If this has not been explicity set then it will be created.- Returns:
- the ActionManager instance.
- See Also:
-
setInstance
Sets the ActionManager instance. -
getActionIDs
Returns the ids for all the managed actions.An action id is a unique idenitfier which can be used to retrieve the corrspondng Action from the ActionManager. This identifier can also be used to set the properties of the action through the action manager like setting the state of the enabled or selected flags.
- Returns:
- a set which represents all the action ids
-
addAction
-
addAction
Adds an action to the ActionManager- Parameters:
id
- value of the action id - which is value of the ACTION_COMMAND_KEYaction
- Action to be managed- Returns:
- the action that was added
-
getAction
Retrieves the action corresponding to an action id.- Parameters:
id
- value of the action id- Returns:
- an Action or null if id
-
getTargetableAction
Convenience method for returning the TargetableAction- Parameters:
id
- value of the action id- Returns:
- the TargetableAction referenced by the named id or null
-
getBoundAction
Convenience method for returning the BoundAction- Parameters:
id
- value of the action id- Returns:
- the TargetableAction referenced by the named id or null
-
getServerAction
Convenience method for returning the ServerAction- Parameters:
id
- value of the action id- Returns:
- the TargetableAction referenced by the named id or null
-
getCompositeAction
Convenience method for returning the CompositeAction- Parameters:
id
- value of the action id- Returns:
- the TargetableAction referenced by the named id or null
-
getStateChangeAction
Convenience method for returning the StateChangeAction- Parameters:
id
- value of the action id- Returns:
- the StateChangeAction referenced by the named id or null
-
setEnabled
Enables or disables the state of the Action corresponding to the action id. This method should be used by application developers to ensure that all components created from an action remain in synch with respect to their enabled state.- Parameters:
id
- value of the action idenabled
- true if the action is to be enabled; otherwise false
-
isEnabled
Returns the enabled state of theAction
. When enabled, any component associated with this object is active and able to fire this object'sactionPerformed
method.- Parameters:
id
- value of the action id- Returns:
- true if this
Action
is enabled; false if the action doesn't exist or disabled.
-
setSelected
Sets the selected state of a toggle action. If the id doesn't correspond to a toggle action then it will fail silently.- Parameters:
id
- the value of the action idselected
- true if the action is to be selected; otherwise false.
-
isSelected
Gets the selected state of a toggle action. If the id doesn't correspond to a toggle action then it will fail silently.- Parameters:
id
- the value of the action id- Returns:
- true if the action is selected; false if the action doesn't exist or is disabled.
-
printAction
A diagnostic which prints the Attributes of an action on the printStream -
registerCallback
Convenience method to register a callback method on aBoundAction
- Parameters:
id
- value of the action id - which is the value of the ACTION_COMMAND_KEYhandler
- the object which will be perform the actionmethod
- the name of the method on the handler which will be called.- See Also:
-
isStateAction
Determines if the Action corresponding to the action id is a state changed action (toggle, group type action).- Parameters:
id
- value of the action id- Returns:
- true if the action id represents a multi state action; false otherwise
-
isTargetableAction
Test to determine if the action is aTargetableAction
-
isBoundAction
Test to determine if the action is aBoundAction
-
isCompositeAction
Test to determine if the action is aBoundAction
-
isServerAction
Test to determine if the action is aServerAction
-