public class KeyHandler
extends java.lang.Object
EditPartViewer
. Normal is simply defined as keystrokes
which are not associated with an Accelerator on the Menu. The KeyHandler will
be forwarded KeyEvents by the active Tool, which is usually the
SelectionTool. The Tool may be in a state where keystrokes should not be
processed, in which case it will not forward the keystrokes. For this reason,
it is important to always handle KeyEvents by using a KeyHandler.
KeyHandlers can be chained by calling setParent(KeyHandler)
. If this
KeyHandler does not handle the keystroke, it will pass the keystroke to its
parent KeyHandler.
KeyHandlers can be implemented using two stragegies. One is to map
KeyStrokes
to Actions
using the put(KeyStroke, IAction)
and
remove(KeyStroke)
API. The other is to subclass KeyHandler, and
override various methods. A combination of the two is also useful.
Constructor and Description |
---|
KeyHandler() |
Modifier and Type | Method and Description |
---|---|
boolean |
keyPressed(KeyEvent event)
Processes a key pressed event.
|
boolean |
keyReleased(KeyEvent event)
Processes a key released event.
|
void |
put(KeyStroke keystroke,
IAction action)
Maps a specified
KeyStroke to an IAction . |
void |
remove(KeyStroke keystroke)
Removed a mapped
IAction for the specified
KeyStroke . |
KeyHandler |
setParent(KeyHandler parent)
Sets a parent
KeyHandler to which this KeyHandler
will forward un-consumed KeyEvents. |
public boolean keyPressed(KeyEvent event)
event
- the KeyEventtrue
if KeyEvent was handled in some waypublic boolean keyReleased(KeyEvent event)
event
- the KeyEventtrue
if KeyEvent was handled in some waypublic void put(KeyStroke keystroke, IAction action)
KeyStroke
to an IAction
. When
a KeyEvent occurs matching the given KeyStroke, the Action will be
run()
iff it is enabled.keystroke
- the KeyStrokeaction
- the Action to runpublic void remove(KeyStroke keystroke)
IAction
for the specified
KeyStroke
.keystroke
- the KeyStroke to be unmappedpublic KeyHandler setParent(KeyHandler parent)
KeyHandler
to which this KeyHandler
will forward un-consumed KeyEvents. This KeyHandler will first attempt to
handle KeyEvents. If it does not recognize a given KeyEvent, that event
is passed to its parentparent
- the parent KeyHandlerthis
for convenienceCopyright (c) IBM Corp. and others 2000, 2011. All Rights Reserved.