- Timestamp:
- 2012-02-17T23:07:13+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/PrefJPanel.java
r4967 r4971 126 126 } 127 127 128 private JComboBox bxPrim1 = new JComboBox();129 private JComboBox bxPrim2 = new JComboBox();130 private JComboBox bxPrim3 = new JComboBox();131 private JComboBox bxPrim4 = new JComboBox();132 private JComboBox bxSec1 = new JComboBox();133 private JComboBox bxSec2 = new JComboBox();134 private JComboBox bxSec3 = new JComboBox();135 private JComboBox bxSec4 = new JComboBox();136 private JComboBox bxTer1 = new JComboBox();137 private JComboBox bxTer2 = new JComboBox();138 private JComboBox bxTer3 = new JComboBox();139 private JComboBox bxTer4 = new JComboBox();140 128 private JCheckBox cbAlt = new JCheckBox(); 141 129 private JCheckBox cbCtrl = new JCheckBox(); … … 158 146 159 147 private void initComponents() { 160 JPanel editGroupPane = new JPanel();161 JPanel hotkeyGroupPane = new JPanel();162 163 148 JPanel listPane = new JPanel(); 164 149 JScrollPane listScrollPane = new JScrollPane(); 165 JPanel menuGroupPane = new JPanel();166 JPanel modifierTab = new JPanel();167 150 JTabbedPane prefTabPane = new JTabbedPane(); 168 151 JPanel shortcutEditPane = new JPanel(); 169 152 JPanel shortcutTab = new JPanel(); 170 JPanel subwindowGroupPane = new JPanel();171 153 JPanel infoTab = new JPanel(); 172 154 173 155 CbAction action = new CbAction(this); 174 BxAction action2 = new BxAction();175 156 176 157 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); … … 183 164 editor.setText( 184 165 tr("<h1><a name=\"top\">Keyboard Shortcuts</a></h1>")+ 166 tr("<br>")+ 185 167 tr("<p>Please note that shortcut keys are assigned to the actions when JOSM is started. So you need to <b>restart</b> " 186 +"JOSM to see your changes.</p>")+ 187 tr("<p>Furthermore, the shortcuts are activated when the actions are assigned to a menu entry of a button for the first " 188 +"time. So some of your changes may become active even without restart --- but also without collision handling. " 189 +"This is another reason to <b>restart</b> JOSM after making any changes here.</p>")+ 190 tr("<p>You may notice that the key selection list on the next page lists all keys that exist on all kinds of keyboards " 191 +"Java knows about, not just those keys that exist on your keyboard. Please only use values that correspond to " 192 +"a real key on your keyboard. If your keyboard has no ''Copy'' key (PC keyboard do not have them, Sun keyboards do), " 193 +"then do not use it. Also there are ''keys'' listed that correspond to a shortcut on your keyboard (e.g. '':''/Colon). " 194 +"Please do not use them either, use the base key ('';''/Semicolon on US keyboards, ''.''/Period on German keyboards, etc.) " 195 +"instead. Not doing so may result in conflicts, as there is no way for JOSM to know that Ctrl+Shift+; and Ctrl+: " 196 +"actually is the same thing on an US keyboard.</p>")+ 197 tr("<h1>Modifier Groups</h1>")+ 198 tr("<p>The last page lists the modifier keys JOSM will automatically assign to shortcuts. For every of the four kinds " 199 +"of shortcuts there are three alternatives. JOSM will try those alternatives in the listed order when managing a " 200 +"conflict. If all alternatives result in shortcuts that are already taken, it will assign a random shortcut " 201 +"instead.</p>")+ 202 tr("<p>The pseudo-modifier ''disabled'' will disable the shortcut when encountered.</p>") 168 +"JOSM to see your changes.</p>")+ 169 tr("<br>")+ 170 tr("<p>Furthermore, the shortcuts are activated when the actions are assigned to a menu entry of a button for the first " 171 +"time. So some of your changes may become active even without restart --- but also without collision handling. " 172 +"This is another reason to <b>restart</b> JOSM after making any changes here.</p>")+ 173 tr("<br>")+ 174 tr("<p>You may notice that the key selection list on the next page lists all keys that exist on all kinds of keyboards " 175 +"Java knows about, not just those keys that exist on your keyboard. Please only use values that correspond to " 176 +"a real key on your keyboard. If your keyboard has no ''Copy'' key (PC keyboard do not have them, Sun keyboards do), " 177 +"then do not use it. Also there are ''keys'' listed that correspond to a shortcut on your keyboard (e.g. '':''/Colon). " 178 +"Please do not use them either, use the base key ('';''/Semicolon on US keyboards, ''.''/Period on German keyboards, etc.) " 179 +"instead. Not doing so may result in conflicts, as there is no way for JOSM to know that Ctrl+Shift+; and Ctrl+: " 180 +"actually is the same thing on an US keyboard.</p>") 203 181 ); 204 182 editor.setCaretPosition(0); // scroll up … … 240 218 cbMeta.setText(META); // see above for why no tr() 241 219 242 243 220 shortcutEditPane.add(cbDefault); 244 221 shortcutEditPane.add(new JLabel()); … … 258 235 259 236 prefTabPane.addTab(tr("Keyboard Shortcuts"), shortcutTab); 260 261 // next is the modfier group tab.262 // Would be a nice array if I had done it by hand. But then, it would be finished next year or so...263 modifierTab.setLayout(new java.awt.GridLayout(0, 1));264 JScrollPane modifierScroller = new JScrollPane(modifierTab);265 266 editGroupPane.setBorder(BorderFactory.createTitledBorder(tr("Edit Shortcuts")));267 editGroupPane.setLayout(new java.awt.GridLayout(3, 5));268 269 JComboBox[] bxArray = new JComboBox[] {270 bxPrim1,bxSec1,bxTer1,bxPrim2,bxSec2,bxTer2,271 bxPrim3,bxSec3,bxTer3,bxPrim4,bxSec4,bxTer4};272 for (JComboBox bxi: bxArray) bxi.setModel(new DefaultComboBoxModel(modifList));273 274 editGroupPane.add(new JLabel(tr("Primary modifier:")));275 editGroupPane.add(bxPrim1);276 editGroupPane.add(new JLabel(tr("Secondary modifier:")));277 editGroupPane.add(bxSec1);278 editGroupPane.add(new JLabel(tr("Tertiary modifier:")));279 editGroupPane.add(bxTer1);280 modifierTab.add(editGroupPane);281 282 menuGroupPane.setBorder(BorderFactory.createTitledBorder(tr("Menu Shortcuts")));283 menuGroupPane.setLayout(new java.awt.GridLayout(3, 5));284 menuGroupPane.add(new JLabel(tr("Primary modifier:")));285 menuGroupPane.add(bxPrim2);286 menuGroupPane.add(new JLabel(tr("Secondary modifier:")));287 menuGroupPane.add(bxSec2);288 menuGroupPane.add(new JLabel(tr("Tertiary modifier:")));289 menuGroupPane.add(bxTer2);290 modifierTab.add(menuGroupPane);291 292 hotkeyGroupPane.setBorder(BorderFactory.createTitledBorder(tr("Hotkey Shortcuts")));293 hotkeyGroupPane.setLayout(new java.awt.GridLayout(3, 5));294 hotkeyGroupPane.add(new JLabel(tr("Primary modifier:")));295 hotkeyGroupPane.add(bxPrim3);296 hotkeyGroupPane.add(new JLabel((tr("Secondary modifier:"))));297 hotkeyGroupPane.add(bxSec3);298 hotkeyGroupPane.add(new JLabel(tr("Tertiary modifier:")));299 hotkeyGroupPane.add(bxTer3);300 modifierTab.add(hotkeyGroupPane);301 302 subwindowGroupPane.setBorder(BorderFactory.createTitledBorder(tr("Subwindow Shortcuts")));303 subwindowGroupPane.setLayout(new java.awt.GridLayout(3, 5));304 subwindowGroupPane.add(new JLabel(tr("Primary modifier:")));305 subwindowGroupPane.add(bxPrim4);306 subwindowGroupPane.add(new JLabel(tr("Secondary modifier:")));307 subwindowGroupPane.add(bxSec4);308 subwindowGroupPane.add(new JLabel(tr("Tertiary modifier:")));309 subwindowGroupPane.add(bxTer4);310 311 initbx();312 for (JComboBox bxi: bxArray) bxi.setAction(action2);313 314 modifierTab.add(subwindowGroupPane);315 316 prefTabPane.addTab(tr("Modifier Groups"), modifierScroller);317 237 318 238 add(prefTabPane); … … 433 353 } 434 354 435 // this handles the modifier groups 436 private class BxAction extends AbstractAction { 437 public void actionPerformed(java.awt.event.ActionEvent e) { 438 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_EDIT), modifInts[bxPrim1.getSelectedIndex()]); 439 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_EDIT), modifInts[ bxSec1.getSelectedIndex()]); 440 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_EDIT), modifInts[ bxTer1.getSelectedIndex()]); 441 442 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_MENU), modifInts[bxPrim2.getSelectedIndex()]); 443 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_MENU), modifInts[ bxSec2.getSelectedIndex()]); 444 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_MENU), modifInts[ bxTer2.getSelectedIndex()]); 445 446 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_HOTKEY), modifInts[bxPrim3.getSelectedIndex()]); 447 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_HOTKEY), modifInts[ bxSec3.getSelectedIndex()]); 448 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_HOTKEY), modifInts[ bxTer3.getSelectedIndex()]); 449 450 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_LAYER), modifInts[bxPrim4.getSelectedIndex()]); 451 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_LAYER), modifInts[ bxSec4.getSelectedIndex()]); 452 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_LAYER), modifInts[ bxTer4.getSelectedIndex()]); 453 } 454 } 455 456 private void initbx() { 457 HashMap<Integer, Integer> groups = Main.platform.initShortcutGroups(false); 458 setBx(bxPrim1, groups, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_EDIT); 459 setBx(bxSec1, groups, Shortcut.GROUPS_ALT1 +Shortcut.GROUP_EDIT); 460 setBx(bxTer1, groups, Shortcut.GROUPS_ALT2 +Shortcut.GROUP_EDIT); 461 462 setBx(bxPrim2, groups, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_MENU); 463 setBx(bxSec2, groups, Shortcut.GROUPS_ALT1 +Shortcut.GROUP_MENU); 464 setBx(bxTer2, groups, Shortcut.GROUPS_ALT2 +Shortcut.GROUP_MENU); 465 466 setBx(bxPrim3, groups, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_HOTKEY); 467 setBx(bxSec3, groups, Shortcut.GROUPS_ALT1 +Shortcut.GROUP_HOTKEY); 468 setBx(bxTer3, groups, Shortcut.GROUPS_ALT2 +Shortcut.GROUP_HOTKEY); 469 470 setBx(bxPrim4, groups, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_LAYER); 471 setBx(bxSec4, groups, Shortcut.GROUPS_ALT1 +Shortcut.GROUP_LAYER); 472 setBx(bxTer4, groups, Shortcut.GROUPS_ALT2 +Shortcut.GROUP_LAYER); 473 } 474 private void setBx(JComboBox bx, HashMap<Integer, Integer> groups, int key) { 475 int target = Main.pref.getInteger("shortcut.groups."+key, groups.get(key)); 476 for (int i = 0; i < modifInts.length; i++) { 477 if (modifInts[i] == target) { 478 bx.setSelectedIndex(i); 479 } 480 } 481 } 482 483 484 class FilterFieldAdapter implements DocumentListener { 355 class FilterFieldAdapter implements DocumentListener { 485 356 public void filter() { 486 357 String expr = filterField.getText().trim(); -
trunk/src/org/openstreetmap/josm/gui/preferences/shortcut/PrefJPanel.java
r4968 r4971 126 126 } 127 127 128 private JComboBox bxPrim1 = new JComboBox();129 private JComboBox bxPrim2 = new JComboBox();130 private JComboBox bxPrim3 = new JComboBox();131 private JComboBox bxPrim4 = new JComboBox();132 private JComboBox bxSec1 = new JComboBox();133 private JComboBox bxSec2 = new JComboBox();134 private JComboBox bxSec3 = new JComboBox();135 private JComboBox bxSec4 = new JComboBox();136 private JComboBox bxTer1 = new JComboBox();137 private JComboBox bxTer2 = new JComboBox();138 private JComboBox bxTer3 = new JComboBox();139 private JComboBox bxTer4 = new JComboBox();140 128 private JCheckBox cbAlt = new JCheckBox(); 141 129 private JCheckBox cbCtrl = new JCheckBox(); … … 158 146 159 147 private void initComponents() { 160 JPanel editGroupPane = new JPanel();161 JPanel hotkeyGroupPane = new JPanel();162 163 148 JPanel listPane = new JPanel(); 164 149 JScrollPane listScrollPane = new JScrollPane(); 165 JPanel menuGroupPane = new JPanel();166 JPanel modifierTab = new JPanel();167 150 JTabbedPane prefTabPane = new JTabbedPane(); 168 151 JPanel shortcutEditPane = new JPanel(); 169 152 JPanel shortcutTab = new JPanel(); 170 JPanel subwindowGroupPane = new JPanel();171 153 JPanel infoTab = new JPanel(); 172 154 173 155 CbAction action = new CbAction(this); 174 BxAction action2 = new BxAction();175 156 176 157 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); … … 183 164 editor.setText( 184 165 tr("<h1><a name=\"top\">Keyboard Shortcuts</a></h1>")+ 166 tr("<br>")+ 185 167 tr("<p>Please note that shortcut keys are assigned to the actions when JOSM is started. So you need to <b>restart</b> " 186 +"JOSM to see your changes.</p>")+ 187 tr("<p>Furthermore, the shortcuts are activated when the actions are assigned to a menu entry of a button for the first " 188 +"time. So some of your changes may become active even without restart --- but also without collision handling. " 189 +"This is another reason to <b>restart</b> JOSM after making any changes here.</p>")+ 190 tr("<p>You may notice that the key selection list on the next page lists all keys that exist on all kinds of keyboards " 191 +"Java knows about, not just those keys that exist on your keyboard. Please only use values that correspond to " 192 +"a real key on your keyboard. If your keyboard has no ''Copy'' key (PC keyboard do not have them, Sun keyboards do), " 193 +"then do not use it. Also there are ''keys'' listed that correspond to a shortcut on your keyboard (e.g. '':''/Colon). " 194 +"Please do not use them either, use the base key ('';''/Semicolon on US keyboards, ''.''/Period on German keyboards, etc.) " 195 +"instead. Not doing so may result in conflicts, as there is no way for JOSM to know that Ctrl+Shift+; and Ctrl+: " 196 +"actually is the same thing on an US keyboard.</p>")+ 197 tr("<h1>Modifier Groups</h1>")+ 198 tr("<p>The last page lists the modifier keys JOSM will automatically assign to shortcuts. For every of the four kinds " 199 +"of shortcuts there are three alternatives. JOSM will try those alternatives in the listed order when managing a " 200 +"conflict. If all alternatives result in shortcuts that are already taken, it will assign a random shortcut " 201 +"instead.</p>")+ 202 tr("<p>The pseudo-modifier ''disabled'' will disable the shortcut when encountered.</p>") 168 +"JOSM to see your changes.</p>")+ 169 tr("<br>")+ 170 tr("<p>Furthermore, the shortcuts are activated when the actions are assigned to a menu entry of a button for the first " 171 +"time. So some of your changes may become active even without restart --- but also without collision handling. " 172 +"This is another reason to <b>restart</b> JOSM after making any changes here.</p>")+ 173 tr("<br>")+ 174 tr("<p>You may notice that the key selection list on the next page lists all keys that exist on all kinds of keyboards " 175 +"Java knows about, not just those keys that exist on your keyboard. Please only use values that correspond to " 176 +"a real key on your keyboard. If your keyboard has no ''Copy'' key (PC keyboard do not have them, Sun keyboards do), " 177 +"then do not use it. Also there are ''keys'' listed that correspond to a shortcut on your keyboard (e.g. '':''/Colon). " 178 +"Please do not use them either, use the base key ('';''/Semicolon on US keyboards, ''.''/Period on German keyboards, etc.) " 179 +"instead. Not doing so may result in conflicts, as there is no way for JOSM to know that Ctrl+Shift+; and Ctrl+: " 180 +"actually is the same thing on an US keyboard.</p>") 203 181 ); 204 182 editor.setCaretPosition(0); // scroll up … … 240 218 cbMeta.setText(META); // see above for why no tr() 241 219 242 243 220 shortcutEditPane.add(cbDefault); 244 221 shortcutEditPane.add(new JLabel()); … … 258 235 259 236 prefTabPane.addTab(tr("Keyboard Shortcuts"), shortcutTab); 260 261 // next is the modfier group tab.262 // Would be a nice array if I had done it by hand. But then, it would be finished next year or so...263 modifierTab.setLayout(new java.awt.GridLayout(0, 1));264 JScrollPane modifierScroller = new JScrollPane(modifierTab);265 266 editGroupPane.setBorder(BorderFactory.createTitledBorder(tr("Edit Shortcuts")));267 editGroupPane.setLayout(new java.awt.GridLayout(3, 5));268 269 JComboBox[] bxArray = new JComboBox[] {270 bxPrim1,bxSec1,bxTer1,bxPrim2,bxSec2,bxTer2,271 bxPrim3,bxSec3,bxTer3,bxPrim4,bxSec4,bxTer4};272 for (JComboBox bxi: bxArray) bxi.setModel(new DefaultComboBoxModel(modifList));273 274 editGroupPane.add(new JLabel(tr("Primary modifier:")));275 editGroupPane.add(bxPrim1);276 editGroupPane.add(new JLabel(tr("Secondary modifier:")));277 editGroupPane.add(bxSec1);278 editGroupPane.add(new JLabel(tr("Tertiary modifier:")));279 editGroupPane.add(bxTer1);280 modifierTab.add(editGroupPane);281 282 menuGroupPane.setBorder(BorderFactory.createTitledBorder(tr("Menu Shortcuts")));283 menuGroupPane.setLayout(new java.awt.GridLayout(3, 5));284 menuGroupPane.add(new JLabel(tr("Primary modifier:")));285 menuGroupPane.add(bxPrim2);286 menuGroupPane.add(new JLabel(tr("Secondary modifier:")));287 menuGroupPane.add(bxSec2);288 menuGroupPane.add(new JLabel(tr("Tertiary modifier:")));289 menuGroupPane.add(bxTer2);290 modifierTab.add(menuGroupPane);291 292 hotkeyGroupPane.setBorder(BorderFactory.createTitledBorder(tr("Hotkey Shortcuts")));293 hotkeyGroupPane.setLayout(new java.awt.GridLayout(3, 5));294 hotkeyGroupPane.add(new JLabel(tr("Primary modifier:")));295 hotkeyGroupPane.add(bxPrim3);296 hotkeyGroupPane.add(new JLabel((tr("Secondary modifier:"))));297 hotkeyGroupPane.add(bxSec3);298 hotkeyGroupPane.add(new JLabel(tr("Tertiary modifier:")));299 hotkeyGroupPane.add(bxTer3);300 modifierTab.add(hotkeyGroupPane);301 302 subwindowGroupPane.setBorder(BorderFactory.createTitledBorder(tr("Subwindow Shortcuts")));303 subwindowGroupPane.setLayout(new java.awt.GridLayout(3, 5));304 subwindowGroupPane.add(new JLabel(tr("Primary modifier:")));305 subwindowGroupPane.add(bxPrim4);306 subwindowGroupPane.add(new JLabel(tr("Secondary modifier:")));307 subwindowGroupPane.add(bxSec4);308 subwindowGroupPane.add(new JLabel(tr("Tertiary modifier:")));309 subwindowGroupPane.add(bxTer4);310 311 initbx();312 for (JComboBox bxi: bxArray) bxi.setAction(action2);313 314 modifierTab.add(subwindowGroupPane);315 316 prefTabPane.addTab(tr("Modifier Groups"), modifierScroller);317 237 318 238 add(prefTabPane); … … 433 353 } 434 354 435 // this handles the modifier groups 436 private class BxAction extends AbstractAction { 437 public void actionPerformed(java.awt.event.ActionEvent e) { 438 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_EDIT), modifInts[bxPrim1.getSelectedIndex()]); 439 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_EDIT), modifInts[ bxSec1.getSelectedIndex()]); 440 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_EDIT), modifInts[ bxTer1.getSelectedIndex()]); 441 442 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_MENU), modifInts[bxPrim2.getSelectedIndex()]); 443 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_MENU), modifInts[ bxSec2.getSelectedIndex()]); 444 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_MENU), modifInts[ bxTer2.getSelectedIndex()]); 445 446 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_HOTKEY), modifInts[bxPrim3.getSelectedIndex()]); 447 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_HOTKEY), modifInts[ bxSec3.getSelectedIndex()]); 448 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_HOTKEY), modifInts[ bxTer3.getSelectedIndex()]); 449 450 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_LAYER), modifInts[bxPrim4.getSelectedIndex()]); 451 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_LAYER), modifInts[ bxSec4.getSelectedIndex()]); 452 Main.pref.putInteger("shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_LAYER), modifInts[ bxTer4.getSelectedIndex()]); 453 } 454 } 455 456 private void initbx() { 457 HashMap<Integer, Integer> groups = Main.platform.initShortcutGroups(false); 458 setBx(bxPrim1, groups, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_EDIT); 459 setBx(bxSec1, groups, Shortcut.GROUPS_ALT1 +Shortcut.GROUP_EDIT); 460 setBx(bxTer1, groups, Shortcut.GROUPS_ALT2 +Shortcut.GROUP_EDIT); 461 462 setBx(bxPrim2, groups, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_MENU); 463 setBx(bxSec2, groups, Shortcut.GROUPS_ALT1 +Shortcut.GROUP_MENU); 464 setBx(bxTer2, groups, Shortcut.GROUPS_ALT2 +Shortcut.GROUP_MENU); 465 466 setBx(bxPrim3, groups, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_HOTKEY); 467 setBx(bxSec3, groups, Shortcut.GROUPS_ALT1 +Shortcut.GROUP_HOTKEY); 468 setBx(bxTer3, groups, Shortcut.GROUPS_ALT2 +Shortcut.GROUP_HOTKEY); 469 470 setBx(bxPrim4, groups, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_LAYER); 471 setBx(bxSec4, groups, Shortcut.GROUPS_ALT1 +Shortcut.GROUP_LAYER); 472 setBx(bxTer4, groups, Shortcut.GROUPS_ALT2 +Shortcut.GROUP_LAYER); 473 } 474 private void setBx(JComboBox bx, HashMap<Integer, Integer> groups, int key) { 475 int target = Main.pref.getInteger("shortcut.groups."+key, groups.get(key)); 476 for (int i = 0; i < modifInts.length; i++) { 477 if (modifInts[i] == target) { 478 bx.setSelectedIndex(i); 479 } 480 } 481 } 482 483 484 class FilterFieldAdapter implements DocumentListener { 355 class FilterFieldAdapter implements DocumentListener { 485 356 public void filter() { 486 357 String expr = filterField.getText().trim(); -
trunk/src/org/openstreetmap/josm/tools/PlatformHook.java
r4897 r4971 54 54 55 55 /** 56 * The initShortcutGroups hook will be called by the57 * Shortcut class if it detects that there are no58 * groups in teh config file. So that will happen59 * once on each JOSM installation only.60 *61 * Please note that ShorCut will load its config on demand,62 * that is, at the moment the first shortcut is registered.63 *64 * In this hook, you have to fill the preferences with65 * data, not the internal structures! Also, do not try66 * to register any shortcuts from within.67 */68 public HashMap<Integer, Integer> initShortcutGroups(boolean load);69 70 /**71 56 * The initSystemShortcuts hook will be called by the 72 57 * Shortcut class after the modifier groups have been read -
trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
r4926 r4971 70 70 // Ain't that KISS? 71 71 Runtime.getRuntime().exec("open " + url); 72 }73 @Override74 public HashMap<Integer, Integer> initShortcutGroups(boolean load) {75 HashMap<Integer, Integer> groups = new HashMap<Integer, Integer>();76 77 // Everything but Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_MENU is guesswork.78 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_NONE, -1);79 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_HOTKEY, KeyEvent.CTRL_DOWN_MASK);80 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_MENU, KeyEvent.META_DOWN_MASK);81 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_EDIT, 0);82 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_LAYER, KeyEvent.ALT_DOWN_MASK);83 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_DIRECT, 0);84 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_MNEMONIC,KeyEvent.ALT_DOWN_MASK);85 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_DIRECT2, KeyEvent.ALT_DOWN_MASK);86 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_DIRECT3, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);87 88 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_NONE, -1);89 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_HOTKEY, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);90 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_MENU, KeyEvent.META_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);91 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_EDIT, KeyEvent.SHIFT_DOWN_MASK);92 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_LAYER, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);93 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_DIRECT, KeyEvent.SHIFT_DOWN_MASK);94 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_MNEMONIC, KeyEvent.ALT_DOWN_MASK);95 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_DIRECT2, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);96 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_DIRECT3, KeyEvent.ALT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);97 98 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_NONE, -1);99 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_HOTKEY, KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK);100 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_MENU, KeyEvent.META_DOWN_MASK | KeyEvent.ALT_DOWN_MASK);101 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_EDIT, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);102 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_LAYER, KeyEvent.SHIFT_DOWN_MASK);103 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_DIRECT, KeyEvent.CTRL_DOWN_MASK);104 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_MNEMONIC, KeyEvent.ALT_DOWN_MASK);105 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_DIRECT2, KeyEvent.ALT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK);106 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_DIRECT3, KeyEvent.META_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK);107 108 return groups;109 72 } 110 73 -
trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java
r4926 r4971 37 37 } 38 38 } 39 }40 41 protected void setupGroup(HashMap<Integer, Integer> groups, boolean load, int group, int value) {42 if(load)43 groups.put(group, Main.pref.getInteger("shortcut.groups."+group, value));44 else45 groups.put(group, value);46 }47 48 @Override49 public HashMap<Integer, Integer> initShortcutGroups(boolean load) {50 HashMap<Integer, Integer> groups = new HashMap<Integer, Integer>();51 52 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_NONE, -1);53 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_HOTKEY, KeyEvent.CTRL_DOWN_MASK);54 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_MENU, KeyEvent.CTRL_DOWN_MASK);55 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_EDIT, 0);56 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_LAYER, KeyEvent.ALT_DOWN_MASK);57 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_DIRECT, 0);58 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_MNEMONIC,KeyEvent.ALT_DOWN_MASK);59 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_DIRECT2, KeyEvent.ALT_DOWN_MASK);60 setupGroup(groups, load, Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_DIRECT3, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);61 62 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_NONE, -1);63 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_HOTKEY, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);64 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_MENU, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);65 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_EDIT, KeyEvent.SHIFT_DOWN_MASK);66 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_LAYER, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);67 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_DIRECT, KeyEvent.SHIFT_DOWN_MASK);68 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_MNEMONIC, KeyEvent.ALT_DOWN_MASK);69 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_DIRECT2, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);70 setupGroup(groups, load, Shortcut.GROUPS_ALT1+Shortcut.GROUP_DIRECT3, KeyEvent.ALT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);71 72 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_NONE, -1);73 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_HOTKEY, KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK);74 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_MENU, KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK);75 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_EDIT, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);76 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_LAYER, KeyEvent.SHIFT_DOWN_MASK);77 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_DIRECT, KeyEvent.CTRL_DOWN_MASK);78 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_MNEMONIC, KeyEvent.ALT_DOWN_MASK);79 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_DIRECT2, KeyEvent.ALT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK);80 setupGroup(groups, load, Shortcut.GROUPS_ALT2+Shortcut.GROUP_DIRECT3, KeyEvent.META_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK);81 82 return groups;83 39 } 84 40 -
trunk/src/org/openstreetmap/josm/tools/Shortcut.java
r4956 r4971 37 37 */ 38 38 public class Shortcut { 39 @Deprecated40 public static final int SHIFT_DEFAULT = 1;41 39 private String shortText; // the unique ID of the shortcut 42 40 private String longText; // a human readable description that will be shown in the preferences … … 160 158 private boolean isSame(int isKey, int isModifier) { 161 159 // -1 --- an unassigned shortcut is different from any other shortcut 162 return( isKey == assignedKey && isModifier == assignedModifier && assignedModifier != getGroupModifier( GROUP_NONE));160 return( isKey == assignedKey && isModifier == assignedModifier && assignedModifier != getGroupModifier(NONE)); 163 161 } 164 162 … … 176 174 } 177 175 178 private void saveDefault( int modifier) {176 private void saveDefault() { 179 177 Main.pref.getCollection("shortcut.entry."+shortText, Arrays.asList(new String[]{longText, 180 178 String.valueOf(requestedKey), String.valueOf(requestedGroup), String.valueOf(requestedKey), 181 String.valueOf( modifier), String.valueOf(true), String.valueOf(false)}));179 String.valueOf(getGroupModifier(requestedGroup)), String.valueOf(true), String.valueOf(false)})); 182 180 } 183 181 … … 246 244 247 245 // and here our modifier groups 248 private static Map<Integer, Integer> groups ;246 private static Map<Integer, Integer> groups= new HashMap<Integer, Integer>(); 249 247 250 248 // check if something collides with an existing shortcut … … 273 271 } 274 272 275 // try to find an unused shortcut 276 private static Shortcut findRandomShortcut(String shortText, String longText, int requestedKey, int requestedGroup) { 277 int[] mods = {getGroupModifier(requestedGroup + GROUPS_DEFAULT), getGroupModifier(requestedGroup + GROUPS_ALT1), getGroupModifier(requestedGroup + GROUPS_ALT2)}; 278 for (int m : mods) { 279 for (int k = KeyEvent.VK_A; k < KeyEvent.VK_Z; k++) { // we'll limit ourself to 100% safe keys 280 if ( findShortcut(k, m) == null ) 281 return new Shortcut(shortText, longText, requestedKey, requestedGroup, k, m, false, false); 282 } 283 } 284 return new Shortcut(shortText, longText, requestedKey, requestedGroup, requestedKey, getGroupModifier(GROUP_NONE), false, false); 285 } 286 287 // use these constants to request shortcuts 288 /** 289 * no shortcut. 290 */ 291 public static final int GROUP_NONE = 0; 292 /** 293 * a button action, will use another modifier than MENU on system with a meta key. 294 */ 295 public static final int GROUP_HOTKEY = 1; 296 /** 297 * a menu action, e.g. "ctrl-e" (export). 298 */ 299 public static final int GROUP_MENU = 2; 300 /** 301 * direct edit key, e.g. "a" (add). 302 */ 303 public static final int GROUP_EDIT = 3; 304 /** 305 * toggle one of the right-hand-side windows, e.g. "alt-l" (layers). 306 */ 307 public static final int GROUP_LAYER = 4; 308 /** 309 * for non-letter keys, preferable without modifier, e.g. F5. 310 */ 311 public static final int GROUP_DIRECT = 5; 312 /** 313 * for use with {@see #setMnemonic} only! 314 */ 315 public static final int GROUP_MNEMONIC = 6; 316 /** 317 * for direct access, with alt modifier. 318 */ 319 public static final int GROUP_DIRECT2 = 7; 320 /** 321 * for direct access, remaining modifiers. 322 */ 323 public static final int GROUP_DIRECT3 = 8; 324 public static final int GROUP_RESERVED = 1000; 325 public static final int GROUPS_DEFAULT = 0; 326 public static final int GROUPS_ALT1 = 100; 327 public static final int GROUPS_ALT2 = 200; 273 public static final int NONE = 5000; 274 public static final int MNEMONIC = 5001; 275 public static final int RESERVED = 5002; 276 public static final int DIRECT = 5003; 277 public static final int ALT = 5004; 278 public static final int SHIFT = 5005; 279 public static final int CTRL = 5006; 280 public static final int ALT_SHIFT = 5007; 281 public static final int ALT_CTRL = 5008; 282 public static final int CTRL_SHIFT = 5009; 283 public static final int ALT_CTRL_SHIFT = 5010; 284 285 /* old */ 286 @Deprecated public static final int GROUP_NONE = 0; 287 @Deprecated public static final int GROUP_HOTKEY = 1; 288 @Deprecated public static final int GROUP_MENU = 2; 289 @Deprecated public static final int GROUP_EDIT = 3; 290 @Deprecated public static final int GROUP_LAYER = 4; 291 @Deprecated public static final int GROUP_DIRECT = 5; 292 @Deprecated public static final int GROUP_MNEMONIC = 6; 293 @Deprecated public static final int GROUP_DIRECT2 = 7; 294 @Deprecated public static final int GROUP_DIRECT3 = 8; 295 @Deprecated public static final int GROUPS_DEFAULT = 0; 296 @Deprecated public static final int GROUPS_ALT1 = 100; 297 @Deprecated public static final int GROUPS_ALT2 = 200; 298 @Deprecated public static final int SHIFT_DEFAULT = 1; 328 299 329 300 // bootstrap … … 332 303 if (initdone) return; 333 304 initdone = true; 334 groups = Main.platform.initShortcutGroups(true); 305 groups.put(NONE, -1); 306 groups.put(MNEMONIC, KeyEvent.ALT_DOWN_MASK); 307 groups.put(DIRECT, 0); 308 groups.put(ALT, KeyEvent.ALT_DOWN_MASK); 309 groups.put(SHIFT, KeyEvent.SHIFT_DOWN_MASK); 310 groups.put(CTRL, KeyEvent.CTRL_DOWN_MASK); 311 groups.put(ALT_SHIFT, KeyEvent.ALT_DOWN_MASK|KeyEvent.SHIFT_DOWN_MASK); 312 groups.put(ALT_CTRL, KeyEvent.ALT_DOWN_MASK|KeyEvent.CTRL_DOWN_MASK); 313 groups.put(CTRL_SHIFT, KeyEvent.CTRL_DOWN_MASK|KeyEvent.SHIFT_DOWN_MASK); 314 groups.put(ALT_CTRL_SHIFT, KeyEvent.ALT_DOWN_MASK|KeyEvent.CTRL_DOWN_MASK|KeyEvent.SHIFT_DOWN_MASK); 315 316 /* old */ 317 groups.put(GROUPS_DEFAULT+GROUP_NONE, -1); 318 groups.put(GROUPS_DEFAULT+GROUP_HOTKEY, KeyEvent.CTRL_DOWN_MASK); 319 groups.put(GROUPS_DEFAULT+GROUP_MENU, KeyEvent.CTRL_DOWN_MASK); 320 groups.put(GROUPS_DEFAULT+GROUP_EDIT, 0); 321 groups.put(GROUPS_DEFAULT+GROUP_LAYER, KeyEvent.ALT_DOWN_MASK); 322 groups.put(GROUPS_DEFAULT+GROUP_DIRECT, 0); 323 groups.put(GROUPS_DEFAULT+GROUP_MNEMONIC,KeyEvent.ALT_DOWN_MASK); 324 groups.put(GROUPS_DEFAULT+GROUP_DIRECT2, KeyEvent.ALT_DOWN_MASK); 325 groups.put(GROUPS_DEFAULT+GROUP_DIRECT3, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK); 326 327 groups.put(GROUPS_ALT1+GROUP_NONE, -1); 328 groups.put(GROUPS_ALT1+GROUP_HOTKEY, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK); 329 groups.put(GROUPS_ALT1+GROUP_MENU, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK); 330 groups.put(GROUPS_ALT1+GROUP_EDIT, KeyEvent.SHIFT_DOWN_MASK); 331 groups.put(GROUPS_ALT1+GROUP_LAYER, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK); 332 groups.put(GROUPS_ALT1+GROUP_DIRECT, KeyEvent.SHIFT_DOWN_MASK); 333 groups.put(GROUPS_ALT1+GROUP_MNEMONIC, KeyEvent.ALT_DOWN_MASK); 334 groups.put(GROUPS_ALT1+GROUP_DIRECT2, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK); 335 groups.put(GROUPS_ALT1+GROUP_DIRECT3, KeyEvent.ALT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK); 336 337 groups.put(GROUPS_ALT2+GROUP_NONE, -1); 338 groups.put(GROUPS_ALT2+GROUP_HOTKEY, KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK); 339 groups.put(GROUPS_ALT2+GROUP_MENU, KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK); 340 groups.put(GROUPS_ALT2+GROUP_EDIT, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK); 341 groups.put(GROUPS_ALT2+GROUP_LAYER, KeyEvent.SHIFT_DOWN_MASK); 342 groups.put(GROUPS_ALT2+GROUP_DIRECT, KeyEvent.CTRL_DOWN_MASK); 343 groups.put(GROUPS_ALT2+GROUP_MNEMONIC, KeyEvent.ALT_DOWN_MASK); 344 groups.put(GROUPS_ALT2+GROUP_DIRECT2, KeyEvent.ALT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK); 345 groups.put(GROUPS_ALT2+GROUP_DIRECT3, KeyEvent.META_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK); 346 335 347 // (1) System reserved shortcuts 336 348 Main.platform.initSystemShortcuts(); … … 401 413 return null; 402 414 } 403 potentialShortcut = new Shortcut(shortText, longText, key, GROUP_RESERVED, key, modifier, true, false);415 potentialShortcut = new Shortcut(shortText, longText, key, RESERVED, key, modifier, true, false); 404 416 shortcuts.put(shortText, potentialShortcut); 405 417 return potentialShortcut; … … 458 470 } 459 471 else if (defaultModifier == null) { // garbage in, no shortcut out 460 defaultModifier = getGroupModifier( GROUP_NONE + GROUPS_DEFAULT);472 defaultModifier = getGroupModifier(NONE); 461 473 } 462 474 return defaultModifier; 463 475 } 464 476 477 private static int[] mods = {ALT_CTRL, ALT_SHIFT, CTRL_SHIFT, ALT_CTRL_SHIFT}; 478 private static int[] keys = {KeyEvent.VK_F1, KeyEvent.VK_F2, KeyEvent.VK_F3, KeyEvent.VK_F4, 479 KeyEvent.VK_F5, KeyEvent.VK_F6, KeyEvent.VK_F7, KeyEvent.VK_F8, 480 KeyEvent.VK_F9, KeyEvent.VK_F10, KeyEvent.VK_F11, KeyEvent.VK_F12}; 465 481 // and now the workhorse. same parameters as above, just one more: if originalShortcut is not null and 466 482 // is different from the shortcut that will be assigned, a popup warning will be displayed to the user. … … 475 491 Shortcut sc = shortcuts.get(shortText); 476 492 sc.setLongText(longText); // or set by the platformHook, in this case the original longText doesn't match the real action 477 sc.saveDefault( defaultModifier);493 sc.saveDefault(); 478 494 return sc; 479 495 } 480 Shortcut conflict sWith = null;481 Shortcut potentialShortcut = findShortcut(requestedKey, defaultModifier);482 if (potentialShortcut != null) { // 3 stage conflict handling483 conflictsWith = potentialShortcut;484 defaultModifier = getGroupModifier(requestedGroup + GROUPS_ALT1);485 if (defaultModifier == null) { // garbage in, no shortcut out486 defaultModifier = getGroupModifier(GROUP_NONE + GROUPS_DEFAULT);487 }488 potentialShortcut = findShortcut(requestedKey, defaultModifier);489 if (potentialShortcut != null) {490 defaultModifier = getGroupModifier(requestedGroup + GROUPS_ALT2);491 if (defaultModifier == null) { // garbage in, no shortcut out492 defaultModifier = getGroupModifier(GROUP_NONE + GROUPS_DEFAULT);496 Shortcut conflict = findShortcut(requestedKey, defaultModifier); 497 if (conflict != null) { 498 for (int m : mods) { 499 for (int k : keys) { 500 int newmodifier = getGroupModifier(m); 501 if ( findShortcut(k, m) == null ) { 502 Shortcut newsc = new Shortcut(shortText, longText, requestedKey, m, k, newmodifier, false, false); 503 System.out.println(tr("Silent shortcut conflict: ''{0}'' moved by ''{1}'' to ''{2}''.", 504 shortText, conflict.getShortText(), newsc.getKeyText())); 505 newsc.saveDefault(); 506 shortcuts.put(shortText, newsc); 507 return newsc; 508 } 493 509 } 494 potentialShortcut = findShortcut(requestedKey, defaultModifier);495 if (potentialShortcut != null) { // if all 3 modifiers for a group are used, we give up496 potentialShortcut = findRandomShortcut(shortText, longText, requestedKey, requestedGroup);497 } else {498 potentialShortcut = new Shortcut(shortText, longText, requestedKey, requestedGroup, requestedKey, defaultModifier, false, false);499 }500 } else {501 potentialShortcut = new Shortcut(shortText, longText, requestedKey, requestedGroup, requestedKey, defaultModifier, false, false);502 }503 if (originalShortcut != null && !originalShortcut.isSame(potentialShortcut)) {504 displayWarning(conflictsWith, potentialShortcut, shortText, longText);505 } else if (originalShortcut == null) {506 System.out.println("Silent shortcut conflict: '"+shortText+"' moved by '"+conflictsWith.getShortText()+"' to '"+potentialShortcut.getKeyText()+"'.");507 510 } 508 511 } else { 509 potentialShortcut = new Shortcut(shortText, longText, requestedKey, requestedGroup, requestedKey, defaultModifier, true, false); 510 } 511 512 potentialShortcut.saveDefault(defaultModifier); 513 shortcuts.put(shortText, potentialShortcut); 514 return potentialShortcut; 515 } 516 517 // a lengthy warning message 518 private static void displayWarning(Shortcut conflictsWith, Shortcut potentialShortcut, String shortText, String longText) { 519 JOptionPane.showMessageDialog(Main.parent, 520 tr("Setting the keyboard shortcut ''{0}'' for the action ''{1}'' ({2}) failed\n"+ 521 "because the shortcut is already taken by the action ''{3}'' ({4}).\n\n", 522 conflictsWith.getKeyText(), longText, shortText, 523 conflictsWith.getLongText(), conflictsWith.getShortText())+ 524 (potentialShortcut.getKeyText().equals("") ? 525 tr("This action will have no shortcut.\n\n") 526 : 527 tr("Using the shortcut ''{0}'' instead.\n\n", potentialShortcut.getKeyText()) 528 )+ 529 tr("(Hint: You can edit the shortcuts in the preferences.)"), 530 tr("Error"), 531 JOptionPane.ERROR_MESSAGE 532 ); 512 Shortcut newsc = new Shortcut(shortText, longText, requestedKey, requestedGroup, requestedKey, defaultModifier, true, false); 513 newsc.saveDefault(); 514 shortcuts.put(shortText, newsc); 515 return newsc; 516 } 517 518 return null; 533 519 } 534 520
Note:
See TracChangeset
for help on using the changeset viewer.