Class ActionManager
- java.lang.Object
-
- javax.swing.ActionMap
-
- org.jdesktop.swingx.action.ActionManager
-
- All Implemented Interfaces:
java.io.Serializable
public class ActionManager extends javax.swing.ActionMap
The ActionManager manages sets ofjavax.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 theAction.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:
ActionContainerFactory
,TargetableAction
,BoundAction
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ActionManager()
Creates the action manager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.swing.Action
addAction(java.lang.Object id, javax.swing.Action action)
Adds an action to the ActionManagerjavax.swing.Action
addAction(javax.swing.Action action)
javax.swing.Action
getAction(java.lang.Object id)
Retrieves the action corresponding to an action id.java.util.Set
getActionIDs()
Returns the ids for all the managed actions.BoundAction
getBoundAction(java.lang.Object id)
Convenience method for returning the BoundActionCompositeAction
getCompositeAction(java.lang.Object id)
Convenience method for returning the CompositeActionstatic ActionManager
getInstance()
Return the instance of the ActionManger.ServerAction
getServerAction(java.lang.Object id)
Convenience method for returning the ServerActionTargetableAction
getTargetableAction(java.lang.Object id)
Convenience method for returning the TargetableActionboolean
isBoundAction(java.lang.Object id)
Test to determine if the action is aBoundAction
boolean
isCompositeAction(java.lang.Object id)
Test to determine if the action is aBoundAction
boolean
isEnabled(java.lang.Object id)
Returns the enabled state of theAction
.boolean
isSelected(java.lang.Object id)
Gets the selected state of a toggle action.boolean
isServerAction(java.lang.Object id)
Test to determine if the action is aServerAction
boolean
isStateAction(java.lang.Object id)
Determines if the Action corresponding to the action id is a state changed action (toggle, group type action).boolean
isTargetableAction(java.lang.Object id)
Test to determine if the action is aTargetableAction
void
registerCallback(java.lang.Object id, java.lang.Object handler, java.lang.String method)
Convenience method to register a callback method on aBoundAction
void
setEnabled(java.lang.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(java.lang.Object id, boolean selected)
Sets the selected state of a toggle action.
-
-
-
Method Detail
-
getInstance
public static ActionManager 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(org.jdesktop.swingx.action.ActionManager)
-
setInstance
public static void setInstance(ActionManager manager)
Sets the ActionManager instance.
-
getActionIDs
public java.util.Set 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
public javax.swing.Action addAction(javax.swing.Action action)
-
addAction
public javax.swing.Action addAction(java.lang.Object id, javax.swing.Action action)
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
public javax.swing.Action getAction(java.lang.Object id)
Retrieves the action corresponding to an action id.- Parameters:
id
- value of the action id- Returns:
- an Action or null if id
-
getTargetableAction
public TargetableAction getTargetableAction(java.lang.Object id)
Convenience method for returning the TargetableAction- Parameters:
id
- value of the action id- Returns:
- the TargetableAction referenced by the named id or null
-
getBoundAction
public BoundAction getBoundAction(java.lang.Object id)
Convenience method for returning the BoundAction- Parameters:
id
- value of the action id- Returns:
- the TargetableAction referenced by the named id or null
-
getServerAction
public ServerAction getServerAction(java.lang.Object id)
Convenience method for returning the ServerAction- Parameters:
id
- value of the action id- Returns:
- the TargetableAction referenced by the named id or null
-
getCompositeAction
public CompositeAction getCompositeAction(java.lang.Object id)
Convenience method for returning the CompositeAction- Parameters:
id
- value of the action id- Returns:
- the TargetableAction referenced by the named id or null
-
setEnabled
public void setEnabled(java.lang.Object id, boolean enabled)
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
public boolean isEnabled(java.lang.Object id)
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
public void setSelected(java.lang.Object id, boolean selected)
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
public boolean isSelected(java.lang.Object id)
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.
-
registerCallback
public void registerCallback(java.lang.Object id, java.lang.Object handler, java.lang.String method)
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:
BoundAction.registerCallback(java.lang.Object, java.lang.String)
-
isStateAction
public boolean isStateAction(java.lang.Object id)
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
public boolean isTargetableAction(java.lang.Object id)
Test to determine if the action is aTargetableAction
-
isBoundAction
public boolean isBoundAction(java.lang.Object id)
Test to determine if the action is aBoundAction
-
isCompositeAction
public boolean isCompositeAction(java.lang.Object id)
Test to determine if the action is aBoundAction
-
isServerAction
public boolean isServerAction(java.lang.Object id)
Test to determine if the action is aServerAction
-
-