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

Last change on this file since 6070 was 6070, checked in by stoecker, 11 years ago

see #8853 remove tabs, trailing spaces, windows line ends, strange characters

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