Changeset 4971 in josm for trunk


Ignore:
Timestamp:
2012-02-17T23:07:13+01:00 (13 years ago)
Author:
stoecker
Message:

rework Shortcut handling a bit more, replace conflict handling with 'move out of way' to fix cascading conflicts, drop old group names for more descriptive names, sadly this deprecates the old group values again :-(

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  
    126126    }
    127127
    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();
    140128    private JCheckBox cbAlt = new JCheckBox();
    141129    private JCheckBox cbCtrl = new JCheckBox();
     
    158146
    159147    private void initComponents() {
    160         JPanel editGroupPane = new JPanel();
    161         JPanel hotkeyGroupPane = new JPanel();
    162 
    163148        JPanel listPane = new JPanel();
    164149        JScrollPane listScrollPane = new JScrollPane();
    165         JPanel menuGroupPane = new JPanel();
    166         JPanel modifierTab = new JPanel();
    167150        JTabbedPane prefTabPane = new JTabbedPane();
    168151        JPanel shortcutEditPane = new JPanel();
    169152        JPanel shortcutTab = new JPanel();
    170         JPanel subwindowGroupPane = new JPanel();
    171153        JPanel infoTab = new JPanel();
    172154
    173155        CbAction action = new CbAction(this);
    174         BxAction action2 = new BxAction();
    175156
    176157        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
     
    183164        editor.setText(
    184165                tr("<h1><a name=\"top\">Keyboard Shortcuts</a></h1>")+
     166                tr("<br>")+
    185167                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>")
    203181        );
    204182        editor.setCaretPosition(0); // scroll up
     
    240218        cbMeta.setText(META); // see above for why no tr()
    241219
    242 
    243220        shortcutEditPane.add(cbDefault);
    244221        shortcutEditPane.add(new JLabel());
     
    258235
    259236        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);
    317237
    318238        add(prefTabPane);
     
    433353    }
    434354
    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 {
    485356        public void filter() {
    486357            String expr = filterField.getText().trim();
  • trunk/src/org/openstreetmap/josm/gui/preferences/shortcut/PrefJPanel.java

    r4968 r4971  
    126126    }
    127127
    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();
    140128    private JCheckBox cbAlt = new JCheckBox();
    141129    private JCheckBox cbCtrl = new JCheckBox();
     
    158146
    159147    private void initComponents() {
    160         JPanel editGroupPane = new JPanel();
    161         JPanel hotkeyGroupPane = new JPanel();
    162 
    163148        JPanel listPane = new JPanel();
    164149        JScrollPane listScrollPane = new JScrollPane();
    165         JPanel menuGroupPane = new JPanel();
    166         JPanel modifierTab = new JPanel();
    167150        JTabbedPane prefTabPane = new JTabbedPane();
    168151        JPanel shortcutEditPane = new JPanel();
    169152        JPanel shortcutTab = new JPanel();
    170         JPanel subwindowGroupPane = new JPanel();
    171153        JPanel infoTab = new JPanel();
    172154
    173155        CbAction action = new CbAction(this);
    174         BxAction action2 = new BxAction();
    175156
    176157        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
     
    183164        editor.setText(
    184165                tr("<h1><a name=\"top\">Keyboard Shortcuts</a></h1>")+
     166                tr("<br>")+
    185167                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>")
    203181        );
    204182        editor.setCaretPosition(0); // scroll up
     
    240218        cbMeta.setText(META); // see above for why no tr()
    241219
    242 
    243220        shortcutEditPane.add(cbDefault);
    244221        shortcutEditPane.add(new JLabel());
     
    258235
    259236        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);
    317237
    318238        add(prefTabPane);
     
    433353    }
    434354
    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 {
    485356        public void filter() {
    486357            String expr = filterField.getText().trim();
  • trunk/src/org/openstreetmap/josm/tools/PlatformHook.java

    r4897 r4971  
    5454
    5555    /**
    56       * The initShortcutGroups hook will be called by the
    57       * Shortcut class if it detects that there are no
    58       * groups in teh config file. So that will happen
    59       * 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 with
    65       * data, not the internal structures! Also, do not try
    66       * to register any shortcuts from within.
    67       */
    68     public HashMap<Integer, Integer> initShortcutGroups(boolean load);
    69 
    70     /**
    7156      * The initSystemShortcuts hook will be called by the
    7257      * Shortcut class after the modifier groups have been read
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r4926 r4971  
    7070        // Ain't that KISS?
    7171        Runtime.getRuntime().exec("open " + url);
    72     }
    73     @Override
    74     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;
    10972    }
    11073
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java

    r4926 r4971  
    3737            }
    3838        }
    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         else
    45             groups.put(group, value);
    46     }
    47 
    48     @Override
    49     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;
    8339    }
    8440
  • trunk/src/org/openstreetmap/josm/tools/Shortcut.java

    r4956 r4971  
    3737 */
    3838public class Shortcut {
    39     @Deprecated
    40     public static final int SHIFT_DEFAULT = 1;
    4139    private String shortText;        // the unique ID of the shortcut
    4240    private String longText;         // a human readable description that will be shown in the preferences
     
    160158    private boolean isSame(int isKey, int isModifier) {
    161159        // -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));
    163161    }
    164162
     
    176174    }
    177175
    178     private void saveDefault(int modifier) {
     176    private void saveDefault() {
    179177        Main.pref.getCollection("shortcut.entry."+shortText, Arrays.asList(new String[]{longText,
    180178        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)}));
    182180    }
    183181
     
    246244
    247245    // and here our modifier groups
    248     private static Map<Integer, Integer> groups;
     246    private static Map<Integer, Integer> groups= new HashMap<Integer, Integer>();
    249247
    250248    // check if something collides with an existing shortcut
     
    273271    }
    274272
    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;
    328299
    329300    // bootstrap
     
    332303        if (initdone) return;
    333304        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
    335347        // (1) System reserved shortcuts
    336348        Main.platform.initSystemShortcuts();
     
    401413            return null;
    402414        }
    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);
    404416        shortcuts.put(shortText, potentialShortcut);
    405417        return potentialShortcut;
     
    458470        }
    459471        else if (defaultModifier == null) { // garbage in, no shortcut out
    460             defaultModifier = getGroupModifier(GROUP_NONE + GROUPS_DEFAULT);
     472            defaultModifier = getGroupModifier(NONE);
    461473        }
    462474        return defaultModifier;
    463475    }
    464476
     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};
    465481    // and now the workhorse. same parameters as above, just one more: if originalShortcut is not null and
    466482    // is different from the shortcut that will be assigned, a popup warning will be displayed to the user.
     
    475491            Shortcut sc = shortcuts.get(shortText);
    476492            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();
    478494            return sc;
    479495        }
    480         Shortcut conflictsWith = null;
    481         Shortcut potentialShortcut = findShortcut(requestedKey, defaultModifier);
    482         if (potentialShortcut != null) { // 3 stage conflict handling
    483             conflictsWith = potentialShortcut;
    484             defaultModifier = getGroupModifier(requestedGroup + GROUPS_ALT1);
    485             if (defaultModifier == null) { // garbage in, no shortcut out
    486                 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 out
    492                     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                    }
    493509                }
    494                 potentialShortcut = findShortcut(requestedKey, defaultModifier);
    495                 if (potentialShortcut != null) { // if all 3 modifiers for a group are used, we give up
    496                     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()+"'.");
    507510            }
    508511        } 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;
    533519    }
    534520
Note: See TracChangeset for help on using the changeset viewer.