Changeset 8510 in josm for trunk/src/org/openstreetmap/josm/tools/Shortcut.java
- Timestamp:
- 2015-06-20T23:42:21+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Shortcut.java
r8509 r8510 35 35 */ 36 36 public final class Shortcut { 37 private String shortText; // the unique ID of the shortcut 38 private String longText; // a human readable description that will be shown in the preferences 39 private final int requestedKey; // the key, the caller requested 40 private final int requestedGroup;// the group, the caller requested 41 private int assignedKey; // the key that actually is used 42 private int assignedModifier; // the modifiers that are used 43 private boolean assignedDefault; // true if it got assigned what was requested. (Note: modifiers will be ignored in favour of group when loading it from the preferences then.) 44 private boolean assignedUser; // true if the user changed this shortcut 45 private boolean automatic; // true if the user cannot change this shortcut (Note: it also will not be saved into the preferences) 46 private boolean reset; // true if the user requested this shortcut to be set to its default value (will happen on next restart, as this shortcut will not be saved to the preferences) 37 /** the unique ID of the shortcut */ 38 private final String shortText; 39 /** a human readable description that will be shown in the preferences */ 40 private String longText; 41 /** the key, the caller requested */ 42 private final int requestedKey; 43 /** the group, the caller requested */ 44 private final int requestedGroup; 45 /** the key that actually is used */ 46 private int assignedKey; 47 /** the modifiers that are used */ 48 private int assignedModifier; 49 /** true if it got assigned what was requested. 50 * (Note: modifiers will be ignored in favour of group when loading it from the preferences then.) */ 51 private boolean assignedDefault; 52 /** true if the user changed this shortcut */ 53 private boolean assignedUser; 54 /** true if the user cannot change this shortcut (Note: it also will not be saved into the preferences) */ 55 private boolean automatic; 56 /** true if the user requested this shortcut to be set to its default value 57 * (will happen on next restart, as this shortcut will not be saved to the preferences) */ 58 private boolean reset; 47 59 48 60 // simple constructor … … 218 230 if (keyStroke == null) return ""; 219 231 String modifText = KeyEvent.getKeyModifiersText(keyStroke.getModifiers()); 220 if ("".equals 232 if ("".equals(modifText)) return KeyEvent.getKeyText(keyStroke.getKeyCode()); 221 233 return modifText + "+" + KeyEvent.getKeyText(keyStroke.getKeyCode()); 222 234 } … … 235 247 236 248 // and here our modifier groups 237 private static Map<Integer, Integer> groups = new HashMap<>();249 private static Map<Integer, Integer> groups = new HashMap<>(); 238 250 239 251 // check if something collides with an existing shortcut … … 301 313 groups.put(SHIFT, KeyEvent.SHIFT_DOWN_MASK); 302 314 groups.put(CTRL, commandDownMask); 303 groups.put(ALT_SHIFT, KeyEvent.ALT_DOWN_MASK |KeyEvent.SHIFT_DOWN_MASK);304 groups.put(ALT_CTRL, KeyEvent.ALT_DOWN_MASK |commandDownMask);305 groups.put(CTRL_SHIFT, commandDownMask |KeyEvent.SHIFT_DOWN_MASK);306 groups.put(ALT_CTRL_SHIFT, KeyEvent.ALT_DOWN_MASK |commandDownMask|KeyEvent.SHIFT_DOWN_MASK);315 groups.put(ALT_SHIFT, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK); 316 groups.put(ALT_CTRL, KeyEvent.ALT_DOWN_MASK | commandDownMask); 317 groups.put(CTRL_SHIFT, commandDownMask | KeyEvent.SHIFT_DOWN_MASK); 318 groups.put(ALT_CTRL_SHIFT, KeyEvent.ALT_DOWN_MASK | commandDownMask | KeyEvent.SHIFT_DOWN_MASK); 307 319 308 320 // (1) System reserved shortcuts … … 310 322 // (2) User defined shortcuts 311 323 List<Shortcut> newshortcuts = new LinkedList<>(); 312 for (String s : Main.pref.getAllPrefixCollectionKeys("shortcut.entry.")) {324 for (String s : Main.pref.getAllPrefixCollectionKeys("shortcut.entry.")) { 313 325 newshortcuts.add(new Shortcut(s)); 314 326 } 315 327 316 for (Shortcut sc : newshortcuts) {328 for (Shortcut sc : newshortcuts) { 317 329 if (sc.isAssignedUser() 318 330 && findShortcut(sc.getAssignedKey(), sc.getAssignedModifier()) == null) { … … 321 333 } 322 334 // Shortcuts at their default values 323 for (Shortcut sc : newshortcuts) {335 for (Shortcut sc : newshortcuts) { 324 336 if (!sc.isAssignedUser() && sc.isAssignedDefault() 325 337 && findShortcut(sc.getAssignedKey(), sc.getAssignedModifier()) == null) { … … 328 340 } 329 341 // Shortcuts that were automatically moved 330 for (Shortcut sc : newshortcuts) {342 for (Shortcut sc : newshortcuts) { 331 343 if (!sc.isAssignedUser() && !sc.isAssignedDefault() 332 344 && findShortcut(sc.getAssignedKey(), sc.getAssignedModifier()) == null) { … … 338 350 private static int getGroupModifier(int group) { 339 351 Integer m = groups.get(group); 340 if (m == null)352 if (m == null) 341 353 m = -1; 342 354 return m; … … 344 356 345 357 private static int findModifier(int group, Integer modifier) { 346 if (modifier == null) {358 if (modifier == null) { 347 359 modifier = getGroupModifier(group); 348 360 if (modifier == null) { // garbage in, no shortcut out … … 440 452 switch (requestedGroup) { 441 453 case CTRL: return KeyEvent.CTRL_DOWN_MASK; 442 case ALT_CTRL: return KeyEvent.ALT_DOWN_MASK |KeyEvent.CTRL_DOWN_MASK;443 case CTRL_SHIFT: return KeyEvent.CTRL_DOWN_MASK |KeyEvent.SHIFT_DOWN_MASK;444 case ALT_CTRL_SHIFT: return KeyEvent.ALT_DOWN_MASK |KeyEvent.CTRL_DOWN_MASK|KeyEvent.SHIFT_DOWN_MASK;454 case ALT_CTRL: return KeyEvent.ALT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK; 455 case CTRL_SHIFT: return KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK; 456 case ALT_CTRL_SHIFT: return KeyEvent.ALT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK; 445 457 default: return 0; 446 458 }
Note:
See TracChangeset
for help on using the changeset viewer.