Changeset 10790 in josm for trunk


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

see #13319 - Use InputMapUtils where applicable (VK_ENTER)

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/HelpAwareOptionPane.java

    r10611 r10790  
    301301                final DefaultAction action = new DefaultAction(dialog, pane, i);
    302302                buttons.get(i).addActionListener(action);
    303                 buttons.get(i).getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");
    304                 buttons.get(i).getActionMap().put("enter", action);
     303                InputMapUtils.addEnterAction(buttons.get(i), action);
    305304            }
    306305        } else {
    307306            final DefaultAction action = new DefaultAction(dialog, pane, 0);
    308307            buttons.get(0).addActionListener(action);
    309             buttons.get(0).getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");
    310             buttons.get(0).getActionMap().put("enter", action);
     308            InputMapUtils.addEnterAction(buttons.get(0), action);
    311309        }
    312310
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java

    r10627 r10790  
    5858import org.openstreetmap.josm.io.OnlineResource;
    5959import org.openstreetmap.josm.tools.ImageProvider;
     60import org.openstreetmap.josm.tools.InputMapUtils;
    6061import org.openstreetmap.josm.tools.WindowGeometry;
    6162
     
    257258        );
    258259        tblChangesets.addMouseListener(new MouseEventHandler());
    259         tblChangesets.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "showDetails");
    260         tblChangesets.getActionMap().put("showDetails", new ShowDetailAction(model));
     260        InputMapUtils.addEnterAction(tblChangesets, new ShowDetailAction(model));
    261261        model.getSelectionModel().addListSelectionListener(new ChangesetDetailViewSynchronizer(model));
    262262
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r10722 r10790  
    496496
    497497        // ENTER = editAction, open "edit" dialog
    498         tagTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
    499                 .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "onTableEnter");
    500         tagTable.getActionMap().put("onTableEnter", editAction);
    501         membershipTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
    502                 .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "onTableEnter");
    503         membershipTable.getActionMap().put("onTableEnter", editAction);
     498        InputMapUtils.addEnterActionWhenAncestor(tagTable, editAction);
     499        InputMapUtils.addEnterActionWhenAncestor(membershipTable, editAction);
    504500
    505501        // INSERT button = addAction, open "add tag" dialog
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java

    r10629 r10790  
    8484    protected final JButton btnDownload = new JButton(actDownload);
    8585
    86     private void makeCheckBoxRespondToEnter(JCheckBox cb) {
    87         cb.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "doDownload");
    88         cb.getActionMap().put("doDownload", actDownload);
    89     }
    90 
    9186    protected final JPanel buildMainPanel() {
    9287        JPanel pnl = new JPanel(new GridBagLayout());
     
    182177        InputMapUtils.enableEnter(btnDownload);
    183178
    184         makeCheckBoxRespondToEnter(cbDownloadGpxData);
    185         makeCheckBoxRespondToEnter(cbDownloadOsmData);
    186         makeCheckBoxRespondToEnter(cbDownloadNotes);
    187         makeCheckBoxRespondToEnter(cbNewLayer);
     179        InputMapUtils.addEnterActionWhenAncestor(cbDownloadGpxData, actDownload);
     180        InputMapUtils.addEnterActionWhenAncestor(cbDownloadOsmData, actDownload);
     181        InputMapUtils.addEnterActionWhenAncestor(cbDownloadNotes, actDownload);
     182        InputMapUtils.addEnterActionWhenAncestor(cbNewLayer, actDownload);
    188183
    189184        // -- cancel button
  • 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.