Changeset 4604 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2011-11-21T22:16:25+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/MultikeyActionsHandler.java
r4595 r4604 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.tools; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.awt.KeyEventDispatcher; … … 21 23 public class MultikeyActionsHandler { 22 24 23 private static final long DIALOG_DELAY = 2000; 25 private static final long DIALOG_DELAY = 1000; 26 private static final String STATUS_BAR_ID = new String("multikeyShortcut"); 24 27 25 28 private class MyKeyEventDispatcher implements KeyEventDispatcher { … … 31 34 32 35 if (lastAction != null && e.getID() == KeyEvent.KEY_PRESSED) { 33 if (e.getKeyCode() == lastAction.shortcut.getKeyCode()) { 34 lastAction.action.repeateLastMultikeyAction(); 35 } else { 36 int index = getIndex(e.getKeyChar()); 37 if (index >= 0) { 38 lastAction.action.executeMultikeyAction(index); 39 } 36 int index = getIndex(e.getKeyCode()); 37 if (index >= 0) { 38 lastAction.action.executeMultikeyAction(index, e.getKeyCode() == lastAction.shortcut.getKeyCode()); 40 39 } 41 40 lastAction = null; 41 Main.map.statusLine.resetHelpText(STATUS_BAR_ID); 42 42 return true; 43 43 } … … 45 45 } 46 46 47 private int getIndex(char lastKey) { 48 if (lastKey >= KeyEvent.VK_0 && lastKey <= KeyEvent.VK_9) 49 return lastKey - KeyEvent.VK_0; 47 private int getIndex(int lastKey) { 48 if (lastKey >= KeyEvent.VK_1 && lastKey <= KeyEvent.VK_9) 49 return lastKey - KeyEvent.VK_1; 50 else if (lastKey == KeyEvent.VK_0) 51 return 9; 50 52 else if (lastKey >= KeyEvent.VK_A && lastKey <= KeyEvent.VK_Z) 51 53 return lastKey - KeyEvent.VK_A + 10; … … 70 72 lastAction = this; 71 73 timer.schedule(new MyTimerTask(lastTimestamp, lastAction), DIALOG_DELAY); 74 Main.map.statusLine.setHelpText(STATUS_BAR_ID, tr("{0}... [please type its number]", (String) action.getValue(SHORT_DESCRIPTION))); 72 75 } 73 76 … … 132 135 layers.add(lbTitle); 133 136 137 char repeatKey = (char) action.shortcut.getKeyCode(); 138 boolean repeatKeyUsed = false; 139 134 140 135 141 for (final MultikeyInfo info: action.action.getMultikeyCombinations()) { 142 143 if (info.getShortcut() == repeatKey) { 144 repeatKeyUsed = true; 145 } 146 136 147 JMenuItem item = new JMenuItem(formatMenuText(action.shortcut, String.valueOf(info.getShortcut()), info.getDescription())); 137 148 item.setMnemonic(info.getShortcut()); … … 139 150 @Override 140 151 public void actionPerformed(ActionEvent e) { 141 action.action.executeMultikeyAction(info.getIndex()); 152 Main.map.statusLine.resetHelpText(STATUS_BAR_ID); 153 action.action.executeMultikeyAction(info.getIndex(), false); 142 154 } 143 155 }); … … 145 157 } 146 158 147 MultikeyInfo lastLayer = action.action.getLastMultikeyAction(); 148 if (lastLayer != null) { 149 JMenuItem repeateItem = new JMenuItem(formatMenuText(action.shortcut, 150 KeyEvent.getKeyText(action.shortcut.getKeyCode()), 151 "Repeat " + lastLayer.getDescription())); 152 repeateItem.addActionListener(new ActionListener() { 153 @Override 154 public void actionPerformed(ActionEvent e) { 155 action.action.repeateLastMultikeyAction(); 156 } 157 }); 158 layers.add(repeateItem); 159 if (!repeatKeyUsed) { 160 MultikeyInfo lastLayer = action.action.getLastMultikeyAction(); 161 if (lastLayer != null) { 162 JMenuItem repeateItem = new JMenuItem(formatMenuText(action.shortcut, 163 KeyEvent.getKeyText(action.shortcut.getKeyCode()), 164 "Repeat " + lastLayer.getDescription())); 165 repeateItem.setMnemonic(action.shortcut.getKeyCode()); 166 repeateItem.addActionListener(new ActionListener() { 167 @Override 168 public void actionPerformed(ActionEvent e) { 169 Main.map.statusLine.resetHelpText(STATUS_BAR_ID); 170 action.action.executeMultikeyAction(-1, true); 171 } 172 }); 173 layers.add(repeateItem); 174 } 159 175 } 160 176 -
trunk/src/org/openstreetmap/josm/tools/MultikeyShortcutAction.java
r4595 r4604 22 22 23 23 public char getShortcut() { 24 if (index < 10) 25 return (char)('0' + index); 24 if (index < 9) 25 return (char)('1' + index); 26 else if (index == 9) 27 return '0'; 26 28 else 27 29 return (char)('A' + index - 10); … … 33 35 } 34 36 35 void executeMultikeyAction(int index); 36 void repeateLastMultikeyAction(); 37 void executeMultikeyAction(int index, boolean repeatLastAction); 37 38 List<MultikeyInfo> getMultikeyCombinations(); 38 39 MultikeyInfo getLastMultikeyAction();
Note:
See TracChangeset
for help on using the changeset viewer.