Changeset 14106 in josm


Ignore:
Timestamp:
2018-08-08T17:33:09+02:00 (6 weeks ago)
Author:
simon04
Message:

DownloadDialog, PreferenceDialog: bind Ctrl+Enter to main action

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

Legend:

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

    r13498 r14106  
    208208        InputMapUtils.addEnterActionWhenAncestor(cbStartup, btnDownload.getAction());
    209209        InputMapUtils.addEnterActionWhenAncestor(cbZoomToDownloadedData, btnDownload.getAction());
     210        InputMapUtils.addCtrlEnterAction(pnl, btnDownload.getAction());
    210211
    211212        return pnl;
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r13144 r14106  
    1212import java.awt.GridBagLayout;
    1313import java.awt.event.ActionEvent;
    14 import java.awt.event.InputEvent;
    15 import java.awt.event.KeyEvent;
    1614import java.awt.event.WindowAdapter;
    1715import java.awt.event.WindowEvent;
     
    3129
    3230import javax.swing.AbstractAction;
    33 import javax.swing.Action;
    3431import javax.swing.BorderFactory;
    3532import javax.swing.Icon;
    3633import javax.swing.JButton;
    37 import javax.swing.JComponent;
    3834import javax.swing.JOptionPane;
    3935import javax.swing.JPanel;
    4036import javax.swing.JTabbedPane;
    41 import javax.swing.KeyStroke;
    4237
    4338import org.openstreetmap.josm.Main;
     
    188183        btnUpload.setFocusable(true);
    189184        InputMapUtils.enableEnter(btnUpload);
    190         bindCtrlEnterToAction(getRootPane(), btnUpload.getAction());
     185        InputMapUtils.addCtrlEnterAction(getRootPane(), btnUpload.getAction());
    191186
    192187        // -- cancel button
     
    489484                public void setupDialog() {
    490485                    super.setupDialog();
    491                     bindCtrlEnterToAction(getRootPane(), buttons.get(buttons.size() - 1).getAction());
     486                    InputMapUtils.addCtrlEnterAction(getRootPane(), buttons.get(buttons.size() - 1).getAction());
    492487                }
    493488            };
     
    703698    }
    704699
    705     private static void bindCtrlEnterToAction(JComponent component, Action actionToBind) {
    706         final KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK);
    707         component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, "ctrl_enter");
    708         component.getActionMap().put("ctrl_enter", actionToBind);
    709     }
    710700}
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java

    r13761 r14106  
    6767        JPanel btns = new JPanel(new FlowLayout(FlowLayout.CENTER));
    6868        btns.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    69         btns.add(new JButton(new OKAction()));
     69        OKAction okAction = new OKAction();
     70        btns.add(new JButton(okAction));
    7071        btns.add(new JButton(new CancelAction()));
    7172        btns.add(new JButton(helpAction));
    7273        pnl.add(expert, GBC.std().insets(5, 0, 0, 0));
    7374        pnl.add(btns, GBC.std().fill(GBC.HORIZONTAL));
     75        InputMapUtils.addCtrlEnterAction(pnl, okAction);
    7476        return pnl;
    7577    }
  • trunk/src/org/openstreetmap/josm/tools/InputMapUtils.java

    r12520 r14106  
    117117         c.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");
    118118    }
     119
     120    /**
     121     * Add an action activated with Ctrl+Enter key on a component.
     122     * @param c The Swing component
     123     * @param a action activated with Ctrl+Enter key
     124     * @see JComponent#WHEN_IN_FOCUSED_WINDOW
     125     */
     126    public static void addCtrlEnterAction(JComponent c, Action a) {
     127        final KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK);
     128        c.getActionMap().put("ctrl_enter", a);
     129        c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, "ctrl_enter");
     130    }
    119131}
Note: See TracChangeset for help on using the changeset viewer.