source: josm/trunk/src/org/openstreetmap/josm/tools/InputMapUtils.java@ 5299

Last change on this file since 5299 was 5200, checked in by akks, 12 years ago

see #7626, fix #7463: keys Ctrl-Shift-Up/Down, Enter, Spacebar work better in toggle dialogs
Enter and Spacebar = useful actions for list items (select, toggle, etc.)

File size: 1.8 KB
Line 
1package org.openstreetmap.josm.tools;
2
3import java.awt.event.InputEvent;
4import java.awt.event.KeyEvent;
5import javax.swing.Action;
6import javax.swing.InputMap;
7import javax.swing.JButton;
8import javax.swing.JComponent;
9import javax.swing.KeyStroke;
10import javax.swing.SwingUtilities;
11
12/**
13 * Tools to work with Swing InputMap
14 *
15 */
16public class InputMapUtils {
17 public static void unassignCtrlShiftUpDown(JComponent cmp, int condition) {
18 InputMap inputMap=SwingUtilities.getUIInputMap(cmp, condition);
19 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_UP,InputEvent.CTRL_MASK|InputEvent.SHIFT_MASK));
20 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,InputEvent.CTRL_MASK|InputEvent.SHIFT_MASK));
21 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_UP,InputEvent.ALT_MASK|InputEvent.SHIFT_MASK));
22 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,InputEvent.ALT_MASK|InputEvent.SHIFT_MASK));
23 SwingUtilities.replaceUIInputMap(cmp,JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,inputMap);
24 }
25
26
27 /**
28 * Enable activating button on Enter (which is replaced with spacebar for certain Look-And-Feels)
29 */
30 public static void enableEnter(JButton b) {
31 b.setFocusable(true);
32 b.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_Q,0), "enter");
33 b.getActionMap().put("enter",b.getAction());
34 }
35
36 public static void addEnterAction(JComponent c, Action a) {
37 c.getActionMap().put("enter", a);
38 c.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");
39 }
40
41 public static void addSpacebarAction(JComponent c, Action a) {
42 c.getActionMap().put("spacebar", a);
43 c.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "spacebar");
44 }
45
46}
Note: See TracBrowser for help on using the repository browser.