Ignore:
Timestamp:
2012-02-17T23:07:13+01:00 (12 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 :-(

File:
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();
Note: See TracChangeset for help on using the changeset viewer.