1 | package org.openstreetmap.josm.tools;
|
---|
2 |
|
---|
3 | import java.awt.event.InputEvent;
|
---|
4 | import java.awt.event.KeyEvent;
|
---|
5 | import javax.swing.Action;
|
---|
6 | import javax.swing.InputMap;
|
---|
7 | import javax.swing.JButton;
|
---|
8 | import javax.swing.JComponent;
|
---|
9 | import javax.swing.KeyStroke;
|
---|
10 | import javax.swing.SwingUtilities;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Tools to work with Swing InputMap
|
---|
14 | *
|
---|
15 | */
|
---|
16 | public 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 | }
|
---|