ActionMap (Java SE 15 & JDK 15) (original) (raw)
All Implemented Interfaces:
[Serializable](../../../java.base/java/io/Serializable.html "interface in java.io")
Direct Known Subclasses:
[ActionMapUIResource](plaf/ActionMapUIResource.html "class in javax.swing.plaf")
public class ActionMap extends Object implements Serializable
ActionMap
provides mappings fromObject
s (called keys or Action
names) to Action
s. An ActionMap
is usually used with an InputMap
to locate a particular action when a key is pressed. As with InputMap
, an ActionMap
can have a parent that is searched for keys not defined in the ActionMap
.
As with InputMap
if you create a cycle, eg:
ActionMap am = new ActionMap(); ActionMap bm = new ActionMap(): am.setParent(bm); bm.setParent(am);
some of the methods will cause a StackOverflowError to be thrown.
Since:
1.3
See Also:
Constructor Summary
Constructors
Constructor | Description |
---|---|
ActionMap() | Creates an ActionMap with no parent and no mappings. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
Object[] | allKeys() | Returns an array of the keys defined in this ActionMap and its parent. |
void | clear() | Removes all the mappings from this ActionMap. |
Action | get(Object key) | Returns the binding for key, messaging the parent ActionMap if the binding is not locally defined. |
ActionMap | getParent() | Returns this ActionMap's parent. |
Object[] | keys() | Returns the Action names that are bound in this ActionMap. |
void | put(Object key,Action action) | Adds a binding for key to action. |
void | remove(Object key) | Removes the binding for key from this ActionMap. |
void | setParent(ActionMap map) | Sets this ActionMap's parent. |
int | size() | Returns the number of bindings in this ActionMap. |
Methods declared in class java.lang.Object
[clone](../../../java.base/java/lang/Object.html#clone%28%29), [equals](../../../java.base/java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../../java.base/java/lang/Object.html#finalize%28%29), [getClass](../../../java.base/java/lang/Object.html#getClass%28%29), [hashCode](../../../java.base/java/lang/Object.html#hashCode%28%29), [notify](../../../java.base/java/lang/Object.html#notify%28%29), [notifyAll](../../../java.base/java/lang/Object.html#notifyAll%28%29), [toString](../../../java.base/java/lang/Object.html#toString%28%29), [wait](../../../java.base/java/lang/Object.html#wait%28%29), [wait](../../../java.base/java/lang/Object.html#wait%28long%29), [wait](../../../java.base/java/lang/Object.html#wait%28long,int%29)
Constructor Details
ActionMap
public ActionMap()
Creates anActionMap
with no parent and no mappings.Method Details
setParent
public void setParent(ActionMap map)
Sets thisActionMap
's parent.
Parameters:
map
- theActionMap
that is the parent of this onegetParent
Returns this
ActionMap
's parent.
Returns:
theActionMap
that is the parent of this one, or null if thisActionMap
has no parentput
Adds a binding for
key
toaction
. Ifaction
is null, this removes the current binding forkey
.
In most instances,key
will beaction.getValue(NAME)
.
Parameters:
key
- a key
action
- a binding forkey
get
Returns the binding for
key
, messaging the parentActionMap
if the binding is not locally defined.
Parameters:
key
- a key
Returns:
the binding forkey
remove
public void remove(Object key)
Removes the binding forkey
from thisActionMap
.
Parameters:
key
- a keyclear
public void clear()
Removes all the mappings from thisActionMap
.keys
Returns the
Action
names that are bound in thisActionMap
.
Returns:
an array of the keyssize
public int size()
Returns the number of bindings in thisActionMap
.
Returns:
the number of bindings in thisActionMap
allKeys
public Object[] allKeys()
Returns an array of the keys defined in thisActionMap
and its parent. This method differs fromkeys()
in that this method includes the keys defined in the parent.
Returns:
an array of the keys