Package org.geotools.swing.event
Class MapPaneKeyHandler
- Object
- 
- KeyAdapter
- 
- MapPaneKeyHandler
 
 
- 
- All Implemented Interfaces:
- KeyListener,- EventListener
 
 public class MapPaneKeyHandler extends KeyAdapter Handles keyboard events for a map pane. This is the default handler for classes derived from AbstractMapPane. It provides for keyboard-controlled scrolling and zooming of the display. The default key bindings for actions should be suitable for most keyboards.While the Java Swing toolkit provides its own mechanism for linking key events to actions, this class is somewhat easier to use and provides a model that could be implemented in other toolkits such as SWT. However, you are free to ignore this class and use your own key handler instead since the map pane classes only require that the handler implements the KeyListener interface. Key bindings for an individual action can be set like this: 
 Multiple bindings can be set with the setBindings(Map) or setAllBindings(Map) methods:// Bind left-scroll action to the 'h' key (for Vim fans) KeyInfo key = new KeyInfo(KeyEvent.VK_H, 0); mapPaneKeyHandler.setBinding(key, MapPaneKeyHandler.Action.SCROLL_LEFT);Map<KeyInfo, MapPaneKeyHandler.Action> bindings = new HashMap<KeyInfo, MapPaneKeyHandler.Action>(); bindings.put(new KeyInfo(KeyEvent.VK_H, 0), MapPaneKeyHandler.Action.SCROLL_LEFT); bindings.put(new KeyInfo(KeyEvent.VK_L, 0), MapPaneKeyHandler.Action.SCROLL_RIGHT); bindings.put(new KeyInfo(KeyEvent.VK_K, 0), MapPaneKeyHandler.Action.SCROLL_UP); bindings.put(new KeyInfo(KeyEvent.VK_J, 0), MapPaneKeyHandler.Action.SCROLL_DOWN); mapPaneKeyHandler.setBindings( bindings );- Since:
- 8.0
- Author:
- Michael Bedward
- See Also:
- KeyInfo,- AbstractMapPane.setKeyHandler(KeyListener)
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classMapPaneKeyHandler.ActionConstants for supported actions.
 - 
Constructor SummaryConstructors Constructor Description MapPaneKeyHandler(MapPane mapPane)Creates a new instance with the default key bindings for actions.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description KeyInfogetBindingForAction(MapPaneKeyHandler.Action action)Gets the current key binding for the given action.Map<KeyInfo,MapPaneKeyHandler.Action>getBindings()Gets the current key bindings.voidkeyPressed(KeyEvent e)Handles a key-pressed event.voidsetAllBindings(Map<KeyInfo,MapPaneKeyHandler.Action> newBindings)Sets the bindings to those specified innewBindings.voidsetBinding(KeyInfo keyInfo, MapPaneKeyHandler.Action action)Sets the key binding for a single action.voidsetBindings(Map<KeyInfo,MapPaneKeyHandler.Action> newBindings)Sets one or more key bindings for actions.voidsetDefaultBindings()Sets all key bindings to their default value.- 
Methods inherited from class KeyAdapterkeyReleased, keyTyped
 
- 
 
- 
- 
- 
Constructor Detail- 
MapPaneKeyHandlerpublic MapPaneKeyHandler(MapPane mapPane) Creates a new instance with the default key bindings for actions.- Parameters:
- mapPane- the map pane associated with this handler
 
 
- 
 - 
Method Detail- 
setDefaultBindingspublic void setDefaultBindings() Sets all key bindings to their default value.
 - 
getBindingspublic Map<KeyInfo,MapPaneKeyHandler.Action> getBindings() Gets the current key bindings. The bindings are copied into the destinationMap, so subsequent changes to it will not affect this handler.- Returns:
- the current key bindings
 
 - 
getBindingForActionpublic KeyInfo getBindingForAction(MapPaneKeyHandler.Action action) Gets the current key binding for the given action. The object returned is a copy.- Parameters:
- action- the action
- Returns:
- the key binding; or nullif there is no binding
- Throws:
- IllegalArgumentException- if- actionis- null
 
 - 
setBindingpublic void setBinding(KeyInfo keyInfo, MapPaneKeyHandler.Action action) Sets the key binding for a single action.- Parameters:
- keyInfo- the key binding
- action- the action
- Throws:
- IllegalArgumentException- if either argument is- null
 
 - 
setBindingspublic void setBindings(Map<KeyInfo,MapPaneKeyHandler.Action> newBindings) Sets one or more key bindings for actions. This method can be used to set a subset of the key bindings while leaving others unchanged.- Parameters:
- newBindings- new key bindings
- Throws:
- IllegalArgumentException- if- newBindingsis- null
 
 - 
setAllBindingspublic void setAllBindings(Map<KeyInfo,MapPaneKeyHandler.Action> newBindings) Sets the bindings to those specified innewBindings. This method differs to setBindings(java.util.Map) in that any actions which do not appear in the input map are disabled.- Parameters:
- newBindings- new key bindings
- Throws:
- IllegalArgumentException- if- newBindingsis- null
 
 - 
keyPressedpublic void keyPressed(KeyEvent e) Handles a key-pressed event.- Specified by:
- keyPressedin interface- KeyListener
- Overrides:
- keyPressedin class- KeyAdapter
- Parameters:
- e- input key event
 
 
- 
 
-