de.tkuhn.swing.actions
Class ActionManager

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<java.lang.Object,javax.swing.Action>
          extended by de.tkuhn.swing.actions.ActionManager
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,javax.swing.Action>

public class ActionManager
extends java.util.HashMap<java.lang.Object,javax.swing.Action>
implements java.util.Map<java.lang.Object,javax.swing.Action>

This class can be used for assistance with javax.swing.Actions to create Actions that forward all incoming ActionEvents to one single or multiple ActionListeners. It also can be used as a general container for Actions and will also enable forwarding for any ForwardingAction that is added

Version:
0.9.3
Author:
Tilmann Kuhn
See Also:
Action, ActionListener, ForwardingAction, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
ActionManager()
          Creates a new instance of ActionManager
ActionManager(java.awt.event.ActionListener listener)
          Creates a new instance of ActionManager and registers the ActionListener
 
Method Summary
 void addActionListener(java.awt.event.ActionListener listener)
          Registers an ActionListener with this ActionManager
 void clear()
          Removes all mapped Actions from this Manager
 javax.swing.Action getAction(java.lang.Object key)
          Get the Action associated with the given key
 java.util.Collection<javax.swing.Action> getActions()
          Get a Collection containing all Actions associated with this ActionManager
 javax.swing.Action newAction(java.lang.Object key)
          Create an new Action and associate it with the given object.
 javax.swing.Action newAction(java.lang.String command)
          Create an new Action and associate it with the given key.
 javax.swing.Action put(java.lang.Object key, javax.swing.Action value)
          Implementation of put(key,value) in interface java.util>Map.
 javax.swing.Action putAction(javax.swing.Action action)
          Allows users to put their own Actions in this ActionManager.
 javax.swing.Action putAction(java.lang.Object key, javax.swing.Action action)
          Allows users to put their own Actions in this ActionManager.
 void putAll(java.util.Map<?,? extends javax.swing.Action> map)
          This method can be used to put all Actions in the given Map into this ActionManager.
 javax.swing.Action remove(java.lang.Object key)
          Implementation of remove() in java.util.Map
 javax.swing.Action removeAction(java.lang.Object key)
          Remove the Action associated with the given key.
 void removeActionListener(java.awt.event.ActionListener listener)
          Unregister an ActionListener registered with this ActionManager
 
Methods inherited from class java.util.HashMap
clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, size, values
 

Constructor Detail

ActionManager

public ActionManager()
Creates a new instance of ActionManager


ActionManager

public ActionManager(java.awt.event.ActionListener listener)
Creates a new instance of ActionManager and registers the ActionListener

Parameters:
listener - the ActionListener to be registered with the newly created ActionManager
Method Detail

addActionListener

public void addActionListener(java.awt.event.ActionListener listener)
Registers an ActionListener with this ActionManager

Parameters:
listener - the ActionListener to be registered with this ActionManager

removeActionListener

public void removeActionListener(java.awt.event.ActionListener listener)
Unregister an ActionListener registered with this ActionManager

Parameters:
listener - the ActionListener to be unregistered

newAction

public javax.swing.Action newAction(java.lang.Object key)
Create an new Action and associate it with the given object.

Parameters:
key - the key to create an Action for.
Returns:
the Action.

newAction

public javax.swing.Action newAction(java.lang.String command)
Create an new Action and associate it with the given key. In addition the key is added to the Action using putValue(Action.ACTION_COMMAND_KEY,command)

Parameters:
command - the key to create an Action for.
Returns:
the Action.

getAction

public javax.swing.Action getAction(java.lang.Object key)
Get the Action associated with the given key

Parameters:
key - the key to retrieve the Action for
Returns:
the Action or null if key is not mapped

removeAction

public javax.swing.Action removeAction(java.lang.Object key)
Remove the Action associated with the given key.

Parameters:
key - the key the Action is associated with
Returns:
the Action.

remove

public javax.swing.Action remove(java.lang.Object key)
Implementation of remove() in java.util.Map

Specified by:
remove in interface java.util.Map<java.lang.Object,javax.swing.Action>
Overrides:
remove in class java.util.HashMap<java.lang.Object,javax.swing.Action>
Parameters:
key - the key of the Action you want to remove.
Returns:
the removed Action if key was found null otherwise.

getActions

public java.util.Collection<javax.swing.Action> getActions()
Get a Collection containing all Actions associated with this ActionManager

Returns:
all Actions in this ActionManager

putAction

public javax.swing.Action putAction(javax.swing.Action action)
                             throws java.lang.IllegalArgumentException
Allows users to put their own Actions in this ActionManager. Caution: If an Action fires, that was not created by this ActionManager listeners of this manager are not notified of the event! The Action to be put will be mapped with it's command String as key.

Parameters:
action - the Action to be mapped.
Returns:
previous action associated with specified key, or null if there was no mapping for key.
Throws:
java.lang.IllegalArgumentException - if the command String of the action or the action itself is null

putAction

public javax.swing.Action putAction(java.lang.Object key,
                                    javax.swing.Action action)
                             throws java.lang.IllegalArgumentException
Allows users to put their own Actions in this ActionManager. Caution: If an Action fires, that was not created by this ActionManager listeners of this manager are not notified of the event! The Action to be put will be mapped with the given key.

Parameters:
action - the Action to be mapped.
key - the key to map the Action with.
Returns:
previous action associated with specified key, or null if there was no mapping for key.
Throws:
java.lang.IllegalArgumentException - if the command String of the action is null

put

public javax.swing.Action put(java.lang.Object key,
                              javax.swing.Action value)
                       throws java.lang.UnsupportedOperationException,
                              java.lang.IllegalArgumentException
Implementation of put(key,value) in interface java.util>Map. Overrides put(key,value) in java.util.HashMap to deny the putting of non Action objects.

Specified by:
put in interface java.util.Map<java.lang.Object,javax.swing.Action>
Overrides:
put in class java.util.HashMap<java.lang.Object,javax.swing.Action>
Parameters:
value - an Action to be mapped in this ActionManager
key - the key the Action should be mapped with
Returns:
previous action associated with specified key, or null if there was no mapping for key.
Throws:
java.lang.UnsupportedOperationException - if the value given was not an instance of Action
java.lang.IllegalArgumentException - if an Object other than Action was given as value parameter.

putAll

public void putAll(java.util.Map<?,? extends javax.swing.Action> map)
This method can be used to put all Actions in the given Map into this ActionManager. Non Action objects are ignored as are any Actions that are associated with a null key. Caution: If an Action fires, that was not created by this ActionManager listeners of this manager are not notified of the event!

Specified by:
putAll in interface java.util.Map<java.lang.Object,javax.swing.Action>
Overrides:
putAll in class java.util.HashMap<java.lang.Object,javax.swing.Action>
Parameters:
map - a map containing actions

clear

public void clear()
Removes all mapped Actions from this Manager

Specified by:
clear in interface java.util.Map<java.lang.Object,javax.swing.Action>
Overrides:
clear in class java.util.HashMap<java.lang.Object,javax.swing.Action>


Copyright © Tilmann Kuhn