|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.util.KeyboardManager
public class KeyboardManager
The keyboard manager observes keyboard actions on a particular component and posts commands
associated with the key presses to the Controller hierarchy. It allows specifying the
key repeat rate, and will begin repeating a key immediately after it is held down rather than
depending on the system-specific key repeat delay/rate.
| Nested Class Summary | |
|---|---|
protected class |
KeyboardManager.KeyInfo
|
static interface |
KeyboardManager.KeyObserver
An interface to be implemented by those that care to be notified whenever an event (either a key press or a key release) occurs for any key while the keyboard manager is active. |
protected static class |
KeyboardManager.KeyObserverOp
An observer operation to notify observers of a key event. |
| Field Summary | |
|---|---|
protected HashMap<Character,KeyboardManager.KeyInfo> |
_chars
A hashtable mapping characters to KeyboardManager.KeyInfo objects. |
protected static RuntimeAdjust.BooleanAdjust |
_debugTyping
A debug hook that toggles excessive logging to help debug keyTyped behavior. |
protected boolean |
_enabled
Whether the keyboard manager is accepting keyboard input. |
protected boolean |
_focus
Whether the keyboard manager currently has the keyboard focus. |
protected KeyboardManager.KeyObserverOp |
_keyOp
The operation used to notify observers of actual key events. |
protected HashIntMap<KeyboardManager.KeyInfo> |
_keys
A hashtable mapping key codes to KeyboardManager.KeyInfo objects. |
protected boolean |
_nativeRepeat
Whether native key auto-repeating was enabled when the keyboard manager was last enabled. |
protected ObserverList<KeyboardManager.KeyObserver> |
_observers
The list of key observers. |
protected long |
_repeatDelay
The expected approximate milliseconds between each key release/press event while the key is being auto-repeated. |
protected boolean |
_shouldDisableNativeRepeat
Whether we want to disable native key auto-repeating. |
protected JComponent |
_target
The component that receives keyboard events and that we associate with posted controller commands. |
protected Window |
_window
The window containing our target component whose focus events we care to observe, or null if we're not observing a window. |
protected KeyTranslator |
_xlate
The translator that maps keyboard events to controller commands. |
protected static boolean |
DEBUG_EVENTS
Whether to output debugging info for individual key events. |
protected static boolean |
DEBUG_INTERVAL
Whether to output debugging info for interval callbacks. |
protected static long |
DEFAULT_REPEAT_DELAY
The default repeat delay. |
| Constructor Summary | |
|---|---|
KeyboardManager()
Constructs a keyboard manager that is initially disabled. |
|
| Method Summary | |
|---|---|
void |
ancestorAdded(AncestorEvent e)
|
void |
ancestorMoved(AncestorEvent e)
|
void |
ancestorRemoved(AncestorEvent e)
|
boolean |
dispatchKeyEvent(KeyEvent e)
|
protected void |
gainedFocus()
Called when the keyboard manager gains focus and should begin handling keys again if it was previously enabled. |
protected boolean |
keyPressed(KeyEvent e)
Called when Swing notifies us that a key has been pressed while the keyboard manager is active. |
protected boolean |
keyReleased(KeyEvent e)
Called when Swing notifies us that a key has been released while the keyboard manager is active. |
protected boolean |
keyTyped(KeyEvent e)
Called when Swing notifies us that a key has been typed while the keyboard manager is active. |
protected void |
logKey(String msg,
KeyEvent e)
Logs the given message and key. |
protected void |
lostFocus()
Called when the keyboard manager loses focus and should cease handling keys. |
protected void |
notifyObservers(int id,
int keyCode,
long timestamp)
Notifies all registered key observers of the supplied key event. |
void |
registerKeyObserver(KeyboardManager.KeyObserver obs)
Registers a key observer that will be notified of all key events while the keyboard manager is active. |
void |
releaseAllKeys()
Releases all keys and ceases any hot repeating action that may be going on. |
void |
removeKeyObserver(KeyboardManager.KeyObserver obs)
Removes the supplied key observer from the list of observers to be notified of all key events while the keyboard manager is active. |
void |
reset()
Resets the keyboard manager, clearing any target and key translator in use and disabling the keyboard manager if it is currently active. |
void |
setEnabled(boolean enabled)
Sets whether the keyboard manager processes keyboard input. |
void |
setRepeatDelay(long delay)
Sets the expected delay in milliseconds between each key press/release event the keyboard manager should expect to receive while a key is repeating. |
void |
setTarget(JComponent target,
KeyTranslator xlate)
Initializes the keyboard manager with the supplied target component and key translator and disables the keyboard manager if it is currently active. |
void |
windowGainedFocus(WindowEvent e)
|
void |
windowLostFocus(WindowEvent e)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final boolean DEBUG_EVENTS
protected static final boolean DEBUG_INTERVAL
protected static final long DEFAULT_REPEAT_DELAY
protected long _repeatDelay
protected HashIntMap<KeyboardManager.KeyInfo> _keys
KeyboardManager.KeyInfo objects.
protected HashMap<Character,KeyboardManager.KeyInfo> _chars
KeyboardManager.KeyInfo objects.
protected boolean _focus
protected boolean _enabled
protected Window _window
protected JComponent _target
protected KeyTranslator _xlate
protected ObserverList<KeyboardManager.KeyObserver> _observers
protected KeyboardManager.KeyObserverOp _keyOp
protected boolean _nativeRepeat
protected boolean _shouldDisableNativeRepeat
protected static RuntimeAdjust.BooleanAdjust _debugTyping
| Constructor Detail |
|---|
public KeyboardManager()
setTarget(javax.swing.JComponent, com.threerings.util.KeyTranslator).
| Method Detail |
|---|
public void reset()
public void setTarget(JComponent target,
KeyTranslator xlate)
target - the component whose keyboard events are to be observed.xlate - the key translator used to map keyboard events to controller action commands.public void registerKeyObserver(KeyboardManager.KeyObserver obs)
public void removeKeyObserver(KeyboardManager.KeyObserver obs)
public void setEnabled(boolean enabled)
public void setRepeatDelay(long delay)
public void releaseAllKeys()
protected void gainedFocus()
protected void lostFocus()
public boolean dispatchKeyEvent(KeyEvent e)
dispatchKeyEvent in interface KeyEventDispatcherprotected boolean keyPressed(KeyEvent e)
protected boolean keyTyped(KeyEvent e)
protected boolean keyReleased(KeyEvent e)
protected void notifyObservers(int id,
int keyCode,
long timestamp)
KeyboardManager.KeyInfo objects do various antics from the interval manager thread whilst we may do
other notification from the AWT thread when normal key events are handled.
protected void logKey(String msg,
KeyEvent e)
public void ancestorAdded(AncestorEvent e)
ancestorAdded in interface AncestorListenerpublic void ancestorMoved(AncestorEvent e)
ancestorMoved in interface AncestorListenerpublic void ancestorRemoved(AncestorEvent e)
ancestorRemoved in interface AncestorListenerpublic void windowGainedFocus(WindowEvent e)
windowGainedFocus in interface WindowFocusListenerpublic void windowLostFocus(WindowEvent e)
windowLostFocus in interface WindowFocusListener
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||