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) { |
300 | 300 | for (int i = 0; i < options.length; i++) { |
301 | 301 | final DefaultAction action = new DefaultAction(dialog, pane, i); |
302 | 302 | 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); |
305 | 304 | } |
306 | 305 | } else { |
307 | 306 | final DefaultAction action = new DefaultAction(dialog, pane, 0); |
308 | 307 | 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); |
311 | 309 | } |
312 | 310 | |
313 | 311 | dialog.pack(); |
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
|
|
57 | 57 | import org.openstreetmap.josm.io.ChangesetQuery; |
58 | 58 | import org.openstreetmap.josm.io.OnlineResource; |
59 | 59 | import org.openstreetmap.josm.tools.ImageProvider; |
| 60 | import org.openstreetmap.josm.tools.InputMapUtils; |
60 | 61 | import org.openstreetmap.josm.tools.WindowGeometry; |
61 | 62 | |
62 | 63 | /** |
… |
… |
protected JPanel buildChangesetTablePanel() { |
256 | 257 | model.getSelectionModel() |
257 | 258 | ); |
258 | 259 | 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)); |
261 | 261 | model.getSelectionModel().addListSelectionListener(new ChangesetDetailViewSynchronizer(model)); |
262 | 262 | |
263 | 263 | // activate DEL on the table |
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) { |
495 | 495 | private void setupKeyboardShortcuts() { |
496 | 496 | |
497 | 497 | // 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); |
504 | 500 | |
505 | 501 | // INSERT button = addAction, open "add tag" dialog |
506 | 502 | tagTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) |
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() { |
83 | 83 | private final DownloadAction actDownload = new DownloadAction(); |
84 | 84 | protected final JButton btnDownload = new JButton(actDownload); |
85 | 85 | |
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 | | |
91 | 86 | protected final JPanel buildMainPanel() { |
92 | 87 | JPanel pnl = new JPanel(new GridBagLayout()); |
93 | 88 | |
… |
… |
protected final JPanel buildButtonPanel() { |
181 | 176 | pnl.add(btnDownload); |
182 | 177 | InputMapUtils.enableEnter(btnDownload); |
183 | 178 | |
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); |
188 | 183 | |
189 | 184 | // -- cancel button |
190 | 185 | JButton btnCancel; |
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) { |
66 | 66 | */ |
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 | |
73 | 72 | /** |
74 | 73 | * Add an action activated with Enter key on a component. |
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 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) { |
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 | |
83 | 98 | /** |