Package org.eclipse.gef
Class KeyHandler
- java.lang.Object
-
- org.eclipse.gef.KeyHandler
-
- Direct Known Subclasses:
GraphicalViewerKeyHandler
public class KeyHandler extends java.lang.ObjectThe KeyHandler should handle all normal keystrokes on anEditPartViewer. 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
KeyStrokestoActionsusing theput(KeyStroke, IAction)andremove(KeyStroke)API. The other is to subclass KeyHandler, and override various methods. A combination of the two is also useful.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description KeyHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleankeyPressed(KeyEvent event)Processes a key pressed event.booleankeyReleased(KeyEvent event)Processes a key released event.voidput(KeyStroke keystroke, IAction action)Maps a specifiedKeyStroketo anIAction.voidremove(KeyStroke keystroke)Removed a mappedIActionfor the specifiedKeyStroke.KeyHandlersetParent(KeyHandler parent)Sets a parentKeyHandlerto which this KeyHandler will forward un-consumed KeyEvents.
-
-
-
Method Detail
-
keyPressed
public boolean keyPressed(KeyEvent event)
Processes a key pressed event. This method is called by the Tool whenever a key is pressed, and the Tool is in the proper state.- Parameters:
event- the KeyEvent- Returns:
trueif KeyEvent was handled in some way
-
keyReleased
public boolean keyReleased(KeyEvent event)
Processes a key released event. This method is called by the Tool whenever a key is released, and the Tool is in the proper state.- Parameters:
event- the KeyEvent- Returns:
trueif KeyEvent was handled in some way
-
put
public void put(KeyStroke keystroke, IAction action)
Maps a specifiedKeyStroketo anIAction. When a KeyEvent occurs matching the given KeyStroke, the Action will berun()iff it is enabled.- Parameters:
keystroke- the KeyStrokeaction- the Action to run
-
remove
public void remove(KeyStroke keystroke)
Removed a mappedIActionfor the specifiedKeyStroke.- Parameters:
keystroke- the KeyStroke to be unmapped
-
setParent
public KeyHandler setParent(KeyHandler parent)
Sets a parentKeyHandlerto 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 parent- Parameters:
parent- the parent KeyHandler- Returns:
thisfor convenience
-
-