|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.sun.jaf.ui.ActionManager
The ActionManager manages sets of javax.swing.Action.
The Actions are speficied in an XML configuration file and will be lazily created
when referenced. The schema for the XML document contains three major
elements.
All of these elements have a unique id tag which is used by the ActionManager to reference the element. Refer to action-set.dtd for details on the elements and attributes.
The order of an action in an action-list will reflect to the order of the Action based component in the container. A tree is represented as an action-list that contains one or more action-lists.
Once the Actions have been created you need to register callback methods that perform the logic of the associated Action. A typical use case of the ActionManager is:
ActionManager manager = ActionManager.getInstance();
// Load an action-set XML document
manager.loadActions(new URL("my-actions.xml));
// Register a callback for a particular Action
manager.registerCallback("new-action", actionHandler, "handleNewCommand");
// 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 UIFactory uses the managed Actions in the ActionManager to create user interface components. For example, to create a JMenu based on an action-list id:
JMenu file = UIFactory.getInstance().createMenu("file-menu");
UIFactory,
action-set.dtd| Constructor Summary | |
ActionManager()
Creates the action manager |
|
| Method Summary | |
Action |
getAction(Object id)
Retrieves the action corresponding to an action id. |
Set |
getActionIDs()
Returns the ids for all the managed actions. |
Set |
getActionListIDs()
Retrieve the ids for all the managed action-lists. |
Set |
getActionSetIDs()
Retrieve the ids for all the managed actions-sets. |
static com.sun.jaf.ui.ActionManager |
getInstance()
Return the instance of the ActionManger. |
boolean |
isEnabled(Object id)
Returns the enabled state of the Action. |
boolean |
isSelected(Object id)
Gets the selected state of a toggle action. |
boolean |
isStateChangeAction(Object id)
Determines if the Action corresponding to the action id is a state changed action (toggle, group type action). |
void |
loadActions(InputStream stream)
Adds the set of actions and action-lists from an action-set document into the ActionManager. |
void |
loadActions(URL url)
Adds the set of actions and action-lists from an action-set document into the ActionManager. |
void |
registerCallback(Object id,
Object handler,
String method)
Registers a callback method when the Action corresponding to the action id is invoked. |
void |
setEnabled(Object id,
boolean enabled)
Enables or disables the state of the Action corresponding to the action id. |
static void |
setInstance(com.sun.jaf.ui.ActionManager manager)
Sets the ActionManager instance. |
void |
setSelected(Object id,
boolean selected)
Sets the selected state of a toggle action. |
void |
unloadActions(Object actionset)
Unloads the actions that are assocated with the action-set from the action manager. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public ActionManager()
| Method Detail |
public static com.sun.jaf.ui.ActionManager getInstance()
setInstance(com.sun.jaf.ui.ActionManager)public static void setInstance(com.sun.jaf.ui.ActionManager manager)
public void unloadActions(Object actionset)
actionset - the action-set idpublic Set getActionIDs()
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.
public Set getActionSetIDs()
An action set is an association between an action-set id and the action ids that it contains. For example, the actions-core.xml action-set document has the action-set id: "core-actions" that contains the actions: new-command, open-command, save-command, etc...
public Set getActionListIDs()
An action-list is an ordered collection of actions, action-lists and empty elements which could represent containers of actions. These action-list ids can be used in factory classes to construct ui action containers like menus, toolbars and popups.
public Action getAction(Object id)
id - value of the action id
public void setEnabled(Object id,
boolean enabled)
id - value of the action idenabled - true if the action is to be enabled; otherwise falsepublic boolean isEnabled(Object id)
Action. When enabled,
any component associated with this object is active and
able to fire this object's actionPerformed method.
id - value of the action id
Action is enabled; false if the
action doesn't exist or disabled.
public void setSelected(Object id,
boolean selected)
id - the value of the action idselected - true if the action is to be selected; otherwise false.public boolean isSelected(Object id)
id - the value of the action id
public void loadActions(URL url)
throws IOException
url - URL pointing to an actionSet document
IOException - If there is an error in parsing
public void loadActions(InputStream stream)
throws IOException
stream - InputStream containing an actionSet document
IOException - If there is an error in parsing
public void registerCallback(Object id,
Object handler,
String method)
If the Action represented by the action id is a StateChangeAction, then the method passed should take an int as an argument. The value of getStateChange() on the ItemEvent object will be passed as the parameter.
id - value of the action idhandler - the object which will be perform the actionmethod - the name of the method on the handler which will be called.public boolean isStateChangeAction(Object id)
id - value of the action id
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||