com.threerings.util
Class KeyTranslatorImpl

java.lang.Object
  extended by com.threerings.util.KeyTranslatorImpl
All Implemented Interfaces:
KeyTranslator

public class KeyTranslatorImpl
extends Object
implements KeyTranslator

A basic implementation of the KeyTranslator interface that provides facilities for mapping key codes to action command strings for use by the KeyboardManager.


Nested Class Summary
protected static class KeyTranslatorImpl.KeyRecord
           
 
Field Summary
protected  HashMap<Character,KeyTranslatorImpl.KeyRecord> _charCommands
          Any commands we wish to perform upon key typed events for characters.
protected  HashIntMap<KeyTranslatorImpl.KeyRecord> _keys
          The keys for which commands are registered.
protected static long DEFAULT_REPEAT_DELAY
          The default delay in milliseconds before auto-repeated key presses will begin.
protected static int DEFAULT_REPEAT_RATE
          The default key press repeat rate.
 
Constructor Summary
KeyTranslatorImpl()
           
 
Method Summary
 void addPressCommand(int keyCode, String command)
          Adds a mapping from a key press to an action command string that will auto-repeat at a default repeat rate.
 void addPressCommand(int keyCode, String command, int rate)
          Adds a mapping from a key press to an action command string that will auto-repeat at the specified repeat rate.
 void addPressCommand(int keyCode, String command, int rate, long repeatDelay)
          Adds a mapping from a key press to an action command string that will auto-repeat at the specified repeat rate after the specified auto-repeat delay has expired.
 void addReleaseCommand(int keyCode, String command)
          Adds a mapping from a key release to an action command string.
 Iterator<String> enumeratePressCommands()
          Returns an iterator that iterates over the available press commands.
 Iterator<String> enumerateReleaseCommands()
          Returns an iterator that iterates over the available release commands.
protected  KeyTranslatorImpl.KeyRecord getKeyRecord(int keyCode)
          Returns the key record for the specified key, creating it and inserting it in the key table if necessary.
 String getPressCommand(char ch)
          Returns the action command string associated with a key press of the given character, or null if there is no associated command.
 String getPressCommand(int keyCode)
          Returns the action command string associated with a key press of the key corresponding to the given key code, or null if there is no associated command.
 String getReleaseCommand(char ch)
          Returns the action command string associated with a key release of the given character, or null if there is no associated command.
 String getReleaseCommand(int keyCode)
          Returns the action command string associated with a key release of the key corresponding to the given key code, or null if there is no associated command.
 long getRepeatDelay(char ch)
          Returns the delay in milliseconds before generating auto-repeated key press events for the specified key.
 long getRepeatDelay(int keyCode)
          Returns the delay in milliseconds before generating auto-repeated key press events for the specified key.
 int getRepeatRate(char ch)
          Returns the number of times each second that key presses are to be automatically repeated while the key is held down, or 0 to disable auto-repeat for the key.
 int getRepeatRate(int keyCode)
          Returns the number of times each second that key presses are to be automatically repeated while the key is held down, or 0 to disable auto-repeat for the key.
 boolean hasCommand(char ch)
          Returns whether there is an action command for the key corresponding to the given character in the case of a keyTyped event corresponding to it.
 boolean hasCommand(int keyCode)
          Returns whether there is an action command for the key corresponding to the given keycode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_keys

protected HashIntMap<KeyTranslatorImpl.KeyRecord> _keys
The keys for which commands are registered.


_charCommands

protected HashMap<Character,KeyTranslatorImpl.KeyRecord> _charCommands
Any commands we wish to perform upon key typed events for characters.


DEFAULT_REPEAT_RATE

protected static final int DEFAULT_REPEAT_RATE
The default key press repeat rate.

See Also:
Constant Field Values

DEFAULT_REPEAT_DELAY

protected static final long DEFAULT_REPEAT_DELAY
The default delay in milliseconds before auto-repeated key presses will begin.

See Also:
Constant Field Values
Constructor Detail

KeyTranslatorImpl

public KeyTranslatorImpl()
Method Detail

addPressCommand

public void addPressCommand(int keyCode,
                            String command)
Adds a mapping from a key press to an action command string that will auto-repeat at a default repeat rate.


addPressCommand

public void addPressCommand(int keyCode,
                            String command,
                            int rate)
Adds a mapping from a key press to an action command string that will auto-repeat at the specified repeat rate. Overwrites any existing mapping and repeat rate that may have already been registered.

Parameters:
rate - the number of times each second that the key press should be repeated while the key is down, or 0 to disable auto-repeat for the key.

addPressCommand

public void addPressCommand(int keyCode,
                            String command,
                            int rate,
                            long repeatDelay)
Adds a mapping from a key press to an action command string that will auto-repeat at the specified repeat rate after the specified auto-repeat delay has expired. Overwrites any existing mapping for the specified key code that may have already been registered.

Parameters:
rate - the number of times each second that the key press should be repeated while the key is down; passing 0 will result in no repeating.
repeatDelay - the delay in milliseconds before auto-repeating key press events will be generated for the key.

addReleaseCommand

public void addReleaseCommand(int keyCode,
                              String command)
Adds a mapping from a key release to an action command string. Overwrites any existing mapping that may already have been registered.


getKeyRecord

protected KeyTranslatorImpl.KeyRecord getKeyRecord(int keyCode)
Returns the key record for the specified key, creating it and inserting it in the key table if necessary.


hasCommand

public boolean hasCommand(int keyCode)
Description copied from interface: KeyTranslator
Returns whether there is an action command for the key corresponding to the given keycode. The translator may have an action command for either a key press or a key release of the key, or both.

Specified by:
hasCommand in interface KeyTranslator

hasCommand

public boolean hasCommand(char ch)
Description copied from interface: KeyTranslator
Returns whether there is an action command for the key corresponding to the given character in the case of a keyTyped event corresponding to it.

Specified by:
hasCommand in interface KeyTranslator

getPressCommand

public String getPressCommand(int keyCode)
Description copied from interface: KeyTranslator
Returns the action command string associated with a key press of the key corresponding to the given key code, or null if there is no associated command.

Specified by:
getPressCommand in interface KeyTranslator

getPressCommand

public String getPressCommand(char ch)
Description copied from interface: KeyTranslator
Returns the action command string associated with a key press of the given character, or null if there is no associated command.

Specified by:
getPressCommand in interface KeyTranslator

getReleaseCommand

public String getReleaseCommand(int keyCode)
Description copied from interface: KeyTranslator
Returns the action command string associated with a key release of the key corresponding to the given key code, or null if there is no associated command.

Specified by:
getReleaseCommand in interface KeyTranslator

getReleaseCommand

public String getReleaseCommand(char ch)
Description copied from interface: KeyTranslator
Returns the action command string associated with a key release of the given character, or null if there is no associated command.

Specified by:
getReleaseCommand in interface KeyTranslator

getRepeatRate

public int getRepeatRate(int keyCode)
Description copied from interface: KeyTranslator
Returns the number of times each second that key presses are to be automatically repeated while the key is held down, or 0 to disable auto-repeat for the key.

Specified by:
getRepeatRate in interface KeyTranslator

getRepeatRate

public int getRepeatRate(char ch)
Description copied from interface: KeyTranslator
Returns the number of times each second that key presses are to be automatically repeated while the key is held down, or 0 to disable auto-repeat for the key.

Specified by:
getRepeatRate in interface KeyTranslator

getRepeatDelay

public long getRepeatDelay(int keyCode)
Description copied from interface: KeyTranslator
Returns the delay in milliseconds before generating auto-repeated key press events for the specified key.

Specified by:
getRepeatDelay in interface KeyTranslator

getRepeatDelay

public long getRepeatDelay(char ch)
Description copied from interface: KeyTranslator
Returns the delay in milliseconds before generating auto-repeated key press events for the specified key.

Specified by:
getRepeatDelay in interface KeyTranslator

enumeratePressCommands

public Iterator<String> enumeratePressCommands()
Description copied from interface: KeyTranslator
Returns an iterator that iterates over the available press commands.

Specified by:
enumeratePressCommands in interface KeyTranslator

enumerateReleaseCommands

public Iterator<String> enumerateReleaseCommands()
Description copied from interface: KeyTranslator
Returns an iterator that iterates over the available release commands.

Specified by:
enumerateReleaseCommands in interface KeyTranslator