javax.swing

Class InputMap

public class InputMap extends Object implements Serializable

Maps {@link KeyStroke}s to arbitrary objects, usually Strings. This is used in combination with {@link ActionMap}s. If a component receives an input event, this is looked up in the component's InputMap. The result is an object which serves as a key to the component's ActionMap. Finally the Action that is stored is executed.

Since: 1.3

Constructor Summary
InputMap()
Creates a new InputMap instance.
Method Summary
KeyStroke[]allKeys()
Returns all keys of entries in this InputMap and all its parents.
voidclear()
Clears the entries from this InputMap.
Objectget(KeyStroke keystroke)
Returns the binding for the specified keystroke, if there is one.
InputMapgetParent()
Returns the parent of this InputMap.
KeyStroke[]keys()
Returns all keys of entries in this InputMap.
voidput(KeyStroke keystroke, Object actionMapKey)
Puts a new entry into the InputMap.
voidremove(KeyStroke keystroke)
Removes an entry from this InputMap.
voidsetParent(InputMap parentMap)
Sets a parent for this InputMap.
intsize()
Returns the number of entries in this InputMap.

Constructor Detail

InputMap

public InputMap()
Creates a new InputMap instance. This default instance contains no mappings and has no parent.

Method Detail

allKeys

public KeyStroke[] allKeys()
Returns all keys of entries in this InputMap and all its parents.

Returns: An array of keys (may be null or have zero length).

clear

public void clear()
Clears the entries from this InputMap. The parent map, if there is one, is not cleared.

get

public Object get(KeyStroke keystroke)
Returns the binding for the specified keystroke, if there is one.

Parameters: keystroke the key of the entry (null is ignored).

Returns: The binding associated with the specified keystroke (or null).

getParent

public InputMap getParent()
Returns the parent of this InputMap. The default value is null.

Returns: The parent map (possibly null).

See Also: setParent

keys

public KeyStroke[] keys()
Returns all keys of entries in this InputMap. This does not include keys defined in the parent, if there is one (use the {@link #allKeys()} method for that case).

Following the behaviour of the reference implementation, this method will return null when no entries have been added to the map, and a zero length array if entries have been added but subsequently removed (or cleared) from the map.

Returns: An array of keys (may be null or have zero length).

put

public void put(KeyStroke keystroke, Object actionMapKey)
Puts a new entry into the InputMap. If actionMapKey is null any existing entry will be removed.

Parameters: keystroke the keystroke for the entry (null is ignored). actionMapKey the action (null permitted).

remove

public void remove(KeyStroke keystroke)
Removes an entry from this InputMap. Note that this will not remove any entry from the parent map, if there is one.

Parameters: keystroke the key of the entry to remove (null is ignored).

setParent

public void setParent(InputMap parentMap)
Sets a parent for this InputMap. If a parent is specified, the {@link #get(KeyStroke)} method will look in the parent if it cannot find an entry in this map.

Parameters: parentMap the new parent (null permitted).

See Also: getParent

size

public int size()
Returns the number of entries in this InputMap. This count does not include any entries from the parent map, if there is one.

Returns: The number of entries.