Ticket #13319: 13319.patch

File 13319.patch, 7.2 KB (added by simon04, 5 years ago)
  • src/org/openstreetmap/josm/gui/HelpAwareOptionPane.java

    commit 54004527c14fbe12f610ce4484921d3044a25752
    Author: Simon Legner <Simon.Legner@gmail.com>
    Date:   Thu Aug 11 16:05:32 2016 +0200
    
        Use InputMapUtils where applicable
    
    diff --git a/src/org/openstreetmap/josm/gui/HelpAwareOptionPane.java b/src/org/openstreetmap/josm/gui/HelpAwareOptionPane.java
    index d62b418..50aeb2e 100644
    a b public void actionPerformed(ActionEvent e) { 
    300300            for (int i = 0; i < options.length; i++) {
    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
    313311        dialog.pack();
  • src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java b/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java
    index 63e4880..34d8ecb 100644
    a b  
    5757import org.openstreetmap.josm.io.ChangesetQuery;
    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
    6263/**
    protected JPanel buildChangesetTablePanel() { 
    256257                model.getSelectionModel()
    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
    263263        // activate DEL on the table
  • src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java b/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
    index 70c3a4f..f738e7a 100644
    a b public void setFilter(final SearchCompiler.Match filter) { 
    495495    private void setupKeyboardShortcuts() {
    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
    506502        tagTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
  • src/org/openstreetmap/josm/gui/download/DownloadDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/download/DownloadDialog.java b/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
    index 8bd2e67..6e9547a 100644
    a b public static synchronized DownloadDialog getInstance() { 
    8383    private final DownloadAction actDownload = new DownloadAction();
    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());
    9388
    protected final JPanel buildButtonPanel() { 
    181176        pnl.add(btnDownload);
    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
    190185        JButton btnCancel;
  • src/org/openstreetmap/josm/tools/InputMapUtils.java

    diff --git a/src/org/openstreetmap/josm/tools/InputMapUtils.java b/src/org/openstreetmap/josm/tools/InputMapUtils.java
    index 87c6873..7e5fe41 100644
    a b public static void unassignPageUpDown(JComponent cmp, int condition) { 
    6666     */
    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
    7372    /**
    7473     * Add an action activated with Enter key on a component.
    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 10783
     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
    8398    /**