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

Last change on this file since 6388 was 6362, checked in by Don-vip, 10 years ago

Checkstyle:

  • private constructors for util classes
  • final classes
  • missing "else" statements
  • import cleanup
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 final class InputMapUtils {
19
20 private InputMapUtils() {
21 // Hide default constructor for utils classes
22 }
23
24 public static void unassignCtrlShiftUpDown(JComponent cmp, int condition) {
25 InputMap inputMap=SwingUtilities.getUIInputMap(cmp, condition);
26 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_UP,InputEvent.CTRL_MASK|InputEvent.SHIFT_MASK));
27 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,InputEvent.CTRL_MASK|InputEvent.SHIFT_MASK));
28 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_UP,InputEvent.ALT_MASK|InputEvent.SHIFT_MASK));
29 inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,InputEvent.ALT_MASK|InputEvent.SHIFT_MASK));
30 SwingUtilities.replaceUIInputMap(cmp,JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,inputMap);
31 }
32
33 /**
34 * Enable activating button on Enter (which is replaced with spacebar for certain Look-And-Feels)
35 */
36 public static void enableEnter(JButton b) {
37 b.setFocusable(true);
38 b.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");
39 b.getActionMap().put("enter",b.getAction());
40 }
41
42 public static void addEnterAction(JComponent c, Action a) {
43 c.getActionMap().put("enter", a);
44 c.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");
45 }
46
47 public static void addSpacebarAction(JComponent c, Action a) {
48 c.getActionMap().put("spacebar", a);
49 c.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "spacebar");
50 }
51}
Note: See TracBrowser for help on using the repository browser.