|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavoids.KeyMap
public final class KeyMap
A class to handle keyboard mappings of key presses to actions.
Nested Class Summary | |
---|---|
static class |
KeyMap.Action
A list of possible actions that can be mapped to key presses in the game. |
Field Summary | |
---|---|
protected java.util.Hashtable<KeyMap.Action,java.lang.Integer> |
actionKey
a mapping of actions to key codes |
protected static java.util.Hashtable<KeyMap.Action,java.lang.String> |
actionMnemonic
a mapping of an action to a mnemonic |
private static java.util.HashSet<KeyMap.Action> |
actions
the valid actions |
protected java.util.Hashtable<java.lang.Integer,KeyMap.Action> |
keyAction
a mapping of key codes to actions |
protected static java.util.Hashtable<java.lang.Integer,java.lang.String> |
keyMnemonic
a mapping of key code to a mnemonic |
private static java.util.HashSet<java.lang.Integer> |
keys
the valid key codes |
private static int |
MAX_KEYS
the maximum number of key presses combinations that can be stored |
private static java.util.Hashtable<java.lang.String,KeyMap.Action> |
mnemonicAction
a mapping of mnemonic to an action |
private static java.util.Hashtable<java.lang.String,java.lang.Integer> |
mnemonicKey
a mapping of mnemonic to key code |
private java.util.Set<KeyMap.Action> |
pressedButtons
a set of actions to perform |
private java.util.Set<java.lang.Integer> |
pressedKeys
a set of pressed keys to process |
private static long |
serialVersionUID
This is the version used for serializing/deserializing (storing/retrieving) this object |
Constructor Summary | |
---|---|
KeyMap()
Constructor (default) |
|
KeyMap(KeyMap keyMap)
Constructor (copy) |
Method Summary | |
---|---|
static boolean |
containsActionMnemonic(KeyMap.Action action)
|
static boolean |
containsMnemonicKey(java.lang.String mnemonic)
|
void |
copyValues(KeyMap destination,
KeyMap source)
Copy the source keymap to the destination keymap |
boolean |
depressKey(java.lang.Integer key)
Remove an action from the list of keys that were pressed (to stop processing the action) |
void |
depressMouse(KeyMap.Action action)
Remove an action from the list of mouse buttons that were pressed (to stop processing the action) |
KeyMap.Action |
getAction(java.lang.Integer key)
|
static KeyMap.Action |
getAction(java.lang.String mnemonic)
|
java.util.Collection<KeyMap.Action> |
getActions()
|
static java.lang.Integer |
getKey(java.lang.String mnemonic)
|
static java.lang.String |
getMnemonic(KeyMap.Action action)
|
boolean |
load(java.net.URL url)
Load a list of keys and actions |
(package private) void |
loadMnemonic(java.lang.String key,
java.lang.String data)
Store an action related to the mneonic in the key for the action in the data variables. |
java.util.Collection<KeyMap.Action> |
pressedButtons()
|
java.util.Collection<java.lang.Integer> |
pressedKeys()
|
void |
pressKey(java.lang.Integer key)
Add an action to the list of keys that were pressed (for processing actions) |
void |
pressMouse(KeyMap.Action action)
Add an action to the list of mouse buttons that were pressed (for processing actions) |
void |
putAction(java.lang.Integer key,
KeyMap.Action action)
|
static void |
putMnemonicAction(java.lang.String mnemonic,
KeyMap.Action action)
|
static void |
putMnemonicKey(java.lang.String mnemonic,
int key)
|
void |
reset()
reset the keymap to its default values |
void |
save(java.net.URL url)
Save a list of keys and actions |
java.lang.String |
toString()
Provide a String representation of this object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final long serialVersionUID
private static int MAX_KEYS
private static java.util.HashSet<java.lang.Integer> keys
private static java.util.HashSet<KeyMap.Action> actions
private static java.util.Hashtable<java.lang.String,java.lang.Integer> mnemonicKey
private static java.util.Hashtable<java.lang.String,KeyMap.Action> mnemonicAction
protected static java.util.Hashtable<java.lang.Integer,java.lang.String> keyMnemonic
protected static java.util.Hashtable<KeyMap.Action,java.lang.String> actionMnemonic
private transient java.util.Set<java.lang.Integer> pressedKeys
private transient java.util.Set<KeyMap.Action> pressedButtons
protected java.util.Hashtable<KeyMap.Action,java.lang.Integer> actionKey
protected java.util.Hashtable<java.lang.Integer,KeyMap.Action> keyAction
Constructor Detail |
---|
public KeyMap()
public KeyMap(KeyMap keyMap)
keyMap
- the keymap to copyMethod Detail |
---|
public void copyValues(KeyMap destination, KeyMap source)
destination
- the destination keymapsource
- the source keymappublic void reset()
public KeyMap.Action getAction(java.lang.Integer key)
key
- the key associated with the action
public static java.lang.Integer getKey(java.lang.String mnemonic)
mnemonic
- the mnemonic associated with the keycode
public static KeyMap.Action getAction(java.lang.String mnemonic)
mnemonic
- the mnemonic associated with the action
public static java.lang.String getMnemonic(KeyMap.Action action)
action
- the action associated with the mnemonic
public void putAction(java.lang.Integer key, KeyMap.Action action)
key
- the key code to associate with an actionaction
- the action that is associated to the key codepublic static void putMnemonicKey(java.lang.String mnemonic, int key)
mnemonic
- the mnemonic to associate with an actionkey
- the key code that is associated to the key codepublic static void putMnemonicAction(java.lang.String mnemonic, KeyMap.Action action)
mnemonic
- the mnemonic to associate with an actionaction
- the action that is associated to the key codepublic void pressMouse(KeyMap.Action action)
action
- the action to performpublic void depressMouse(KeyMap.Action action)
action
- the action that is not being performed anymorepublic void pressKey(java.lang.Integer key)
key
- the key code to processpublic boolean depressKey(java.lang.Integer key)
key
- the action that is not being performed anymore
public java.util.Collection<java.lang.Integer> pressedKeys()
public java.util.Collection<KeyMap.Action> pressedButtons()
public java.util.Collection<KeyMap.Action> getActions()
public static boolean containsMnemonicKey(java.lang.String mnemonic)
mnemonic
- the mnemonic to look for
public static boolean containsActionMnemonic(KeyMap.Action action)
action
- the mnemonic to look for
void loadMnemonic(java.lang.String key, java.lang.String data)
key
- the mnemonic to look updata
- the mnemonic for an actionpublic boolean load(java.net.URL url)
url
- the url to load the key bindings from
public void save(java.net.URL url)
url
- the url to save the key bindings topublic java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |