Ignore:
Timestamp:
2016-08-12T21:07:51+02:00 (3 years ago)
Author:
simon04
Message:

see #13319 - Use InputMapUtils where applicable (VK_ENTER)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/InputMapUtils.java

    r8510 r10790  
    6767    public static void enableEnter(JButton b) {
    6868         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());
    7170    }
    7271
     
    7574     * @param c The Swing component
    7675     * @param a action activated with Enter key
     76     * @see JComponent#WHEN_FOCUSED
    7777     */
    7878    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) {
    7994         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");
    8196    }
    8297
Note: See TracChangeset for help on using the changeset viewer.