Changeset 10790 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2016-08-12T21:07:51+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/InputMapUtils.java
r8510 r10790 67 67 public static void enableEnter(JButton b) { 68 68 b.setFocusable(true); 69 b.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter"); 70 b.getActionMap().put("enter", b.getAction()); 69 addEnterAction(b, b.getAction()); 71 70 } 72 71 … … 75 74 * @param c The Swing component 76 75 * @param a action activated with Enter key 76 * @see JComponent#WHEN_FOCUSED 77 77 */ 78 78 public static void addEnterAction(JComponent c, Action a) { 79 addEnterAction(c, a, JComponent.WHEN_FOCUSED); 80 } 81 82 /** 83 * Add an action activated with Enter key on a component or its children. 84 * @param c The Swing component 85 * @param a action activated with Enter key 86 * @see JComponent#WHEN_ANCESTOR_OF_FOCUSED_COMPONENT 87 * @since 10790 88 */ 89 public static void addEnterActionWhenAncestor(JComponent c, Action a) { 90 addEnterAction(c, a, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 91 } 92 93 private static void addEnterAction(JComponent c, Action a, int condition) { 79 94 c.getActionMap().put("enter", a); 80 c.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter"); 95 c.getInputMap(condition).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter"); 81 96 } 82 97
Note:
See TracChangeset
for help on using the changeset viewer.