|
ehsbe CommonsTM Version 1.1.0rc3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ehsbe.commons.action.ActionManager
public class ActionManager
The ActionManager manages sets of javax.swing.Action
s and lists
of actions.
All managed actions as well as action lists have a unique ID, which is used
by the ActionManager to lookup them up. For actions, this ID maps to
the Action.ACTION_COMMAND_KEY
on the Action.
The ActionManager registers itself to all added actions as a Listener automatically and delegates all action and state change events to its registered listeners. So there is no need for an [application] controller, to registers to all available actions, just register with the used ActionManager.
On removal of an action, the ActionManager also automatically removes itself from the listener list of the appropriate action.
ActionContainerFactory
,
TargetableAction
,
BoundAction
,
TriggerAction
Field Summary | |
---|---|
protected CopyOnWriteArrayList<ActionListener> |
actionListeners
all registered action listeners |
protected CopyOnWriteArrayList<ItemListener> |
itemListeners
all registered item listeners |
Constructor Summary | |
---|---|
ActionManager()
Creates the action manager. |
|
ActionManager(StreamSource src,
Translator i18n,
String resPath)
Convinience constructor. |
Method Summary | ||
---|---|---|
void |
actionPerformed(ActionEvent e)
|
|
Action |
addAction(Action action)
Add the given action to this instance. |
|
protected Action |
addAction(Object id,
Action action)
Adds an action to the ActionManager |
|
List<Object> |
addActionIDList(String id,
List<Object> actionList)
Add the given action list with the given id to this instance. |
|
void |
addActionIDs(Map<String,List<Object>> cmdLists)
Convinience method to add all the action lists in the given map to this instance. |
|
void |
addActionListener(ActionListener listener)
Register the given listener for receiving action events sent by registered actions of this instance. |
|
void |
addActionMap(Collection<Action> actions)
Convinience method to add all the actions in the given map to this instance. |
|
void |
addGroupButton(String groupId,
AbstractButton button)
Convinience method to add a button to the button group associated with the given groupId. |
|
void |
addItemListener(ItemListener listener)
Register the given listener for receiving item events sent by registered actions of this instance. |
|
|
getAction(Class<T> clazz,
Object id)
Convinience method to get the action with the given ID of the given class. |
|
Action |
getAction(Object id)
Get the action corresponding to an action id. |
|
List<Action> |
getActionCopy(List<?> src,
boolean withoutMnemonic,
ActionListener listener)
Get a list of all actions wrt. to the given possibly nested list of IDs. |
|
ManagedAction |
getActionCopy(Object id,
boolean withoutMnemonics,
ActionListener listener)
Get a copy aka clone of the action corresponding to an action id. |
|
Set<Object> |
getActionIDs()
Get the ids for all the managed actions. |
|
List<Object> |
getActionIDs(String id)
Get the possibly nested action ID list for the given id. |
|
Set<String> |
getActionListIDs()
Get the ids for all the managed action lists. |
|
ButtonGroup |
getButtonGroup(String groupId)
Get the button group associated with the given group ID |
|
Set<String> |
getGroup(String groupId)
Get all action IDs, which belong to the group with the given id. |
|
Set<String> |
getGroupIDs()
Get the IDs of all managed action groups. |
|
static ActionManager |
getInstance()
Get the instance of the ActionManger. |
|
boolean |
isEnabled(Object id)
Get the enabled state of the action with the given id. |
|
boolean |
isSelected(Object id)
Gets the selected state of a toggle action. |
|
void |
itemStateChanged(ItemEvent e)
|
|
void |
propertyChange(PropertyChangeEvent evt)
Adjust groups, when a managed action changes is group value. |
|
Action |
removeAction(Object id)
Remove the action with the given id from this instance. |
|
List<Object> |
removeActionIDList(String id)
Remove the action list with the given id from this instance. |
|
void |
removeActionListener(ActionListener listener)
Unregister the given listener for receiving action events sent by registered actions of this instance. |
|
void |
removeItemListener(ItemListener listener)
Unregister the given listener for receiving item events sent by registered actions of this instance. |
|
void |
setEnabled(Object id,
boolean enabled)
Enables or disables the state of the Action corresponding to the action id. |
|
void |
setSelected(Object id,
boolean selected)
Sets the selected state of a toggle action. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected CopyOnWriteArrayList<ActionListener> actionListeners
protected CopyOnWriteArrayList<ItemListener> itemListeners
Constructor Detail |
---|
public ActionManager()
public ActionManager(StreamSource src, Translator i18n, String resPath)
src
- stream to read and parse (passed to ActionFactory)i18n
- bundle to use for i18n (passed to ActionFactory)resPath
- base path for resolving relative pathes to icons
(passed to ActionFactory)ActionFactory.load(StreamSource, Translator, String, HashMap, HashMap)
,
addActionMap(Collection)
,
addActionIDs(Map)
Method Detail |
---|
public static ActionManager getInstance()
public Set<Object> getActionIDs()
An action id is a unique idenitfier which can be used to retrieve the corrsponding 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<String> getActionListIDs()
An action list id is a unique idenitfier which can be used to retrieve the corrsponding action lists from the ActionManager.
public Set<String> getGroupIDs()
null
if this instance does not contain any action
which belongs to a group, the IDs of all groups otherwise.public Set<String> getGroup(String groupId)
groupId
- action group ID
null
, if there is no registered
action associated with the given group ID, a set of action IDs
otherwise.public ButtonGroup getButtonGroup(String groupId)
groupId
- ID of the button group to lookup
null
if not found, the button group otherwise.public void addGroupButton(String groupId, AbstractButton button)
groupId
- group ID of the target button groupbutton
- button to add
IllegalArgumentException
- if the given groupId is not known
by this instance (i.e. there is no action with such a groupID)public Action addAction(Action action)
Action.ACTION_COMMAND_KEY
will be used as the action's ID.
action
- action to add.
public void addActionMap(Collection<Action> actions)
actions
- list of actions to add.addAction(Action)
public void addActionIDs(Map<String,List<Object>> cmdLists)
cmdLists
- action list map to add.Map.putAll(java.util.Map)
protected Action addAction(Object id, Action action)
id
- value of the action id. The action manager relies on the fact,
that the given id is the same as the ACTION_COMMAND_KEY. If
not, you may see unexpected behavior !action
- Action to be managed
public Action removeAction(Object id)
id
- id of the action to remove
null
if there is no action with the given
id, the removed action otherwise.public List<Object> addActionIDList(String id, List<Object> actionList)
An action list should contain action IDs, null
, and/or
other action lists (i.e. action sublists). Usually one does not need to
register action sublists with this instance, however it might be helpful
to do so.
Action lists might be used to create complete menu trees and/or toolbars, etc.
id
- id of the action list to add.actionList
- actionList to add.
ActionContainerFactory.createMenuBar(List, ActionManager)
,
ActionContainerFactory.createPopup(List, ActionManager)
,
ActionContainerFactory.createMenu(List, javax.swing.JComponent, ActionManager)
,
ActionContainerFactory.createToolBar(List, ActionManager)
public List<Object> removeActionIDList(String id)
id
- id fo the action list to remove
null
if no list with the given ID has been found,
the removed list otherwise.public Action getAction(Object id)
id
- value of the action id
null
if there is no action with the given id, the
appropriate action otherwise.public ManagedAction getActionCopy(Object id, boolean withoutMnemonics, ActionListener listener)
At the moment, ManagedAction
action copies are supported,
only (since they provide a public clone()
method).
id
- value of the action idwithoutMnemonics
- if true
, mnemonics are removed from the action cloned.listener
- an optional action listener, which should be added to
the action clone immediately. If null
it gets ignored.
null
if there is no action with the given id or
the action in question is not clonable, the appropriate cloned
action otherwise.ManagedAction.clone()
public List<Action> getActionCopy(List<?> src, boolean withoutMnemonic, ActionListener listener)
src
- a (possibly nested) list of action IDs or null
withoutMnemonic
- if true
, mnemonics are removed from the action clone.listener
- an optional action listener, which should be added to
the action clone immediately. If null
it gets ignored.
getActionCopy(Object, boolean, ActionListener)
public List<Object> getActionIDs(String id)
id
- ID of the action ID list to lookup
null
if there is no action list with the given id,
the appropriate action list otherwise (which might be
null
as well).public <T> T getAction(Class<T> clazz, Object id)
T
- type of the action to lookupclazz
- class of the action to lookupid
- id of the action in question
null
if the is no action with the given ID or the
found action is not of the specified type, the found action
otherwisepublic 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)
id
- value of the action id
true
if the action with the given id
has been found and is enabled.Action.isEnabled()
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
true
if the action with the given id
has been found and is selected.public void addActionListener(ActionListener listener)
listener
- listener to addpublic void addItemListener(ItemListener listener)
listener
- listener to addpublic void removeActionListener(ActionListener listener)
listener
- listener to removepublic void removeItemListener(ItemListener listener)
listener
- listener to removepublic void actionPerformed(ActionEvent e)
actionPerformed
in interface ActionListener
public void itemStateChanged(ItemEvent e)
itemStateChanged
in interface ItemListener
public void propertyChange(PropertyChangeEvent evt)
propertyChange
in interface PropertyChangeListener
evt
- action change event
|
ehsbe CommonsTM Version 1.1.0rc3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |