source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/PrefJPanel.java@ 4956

Last change on this file since 4956 was 4956, checked in by stoecker, 12 years ago

shortcut fixes, a lot of code cleanup in DrawAction

  • Property svn:eol-style set to native
File size: 25.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences;
3
4import java.awt.Dimension;
5import java.awt.GridBagConstraints;
6import java.awt.GridBagLayout;
7import java.awt.Insets;
8import java.awt.Toolkit;
9
10import static org.openstreetmap.josm.tools.I18n.tr;
11
12import java.awt.event.KeyEvent;
13import java.lang.reflect.Field;
14import java.util.ArrayList;
15import java.util.LinkedHashMap;
16import java.util.HashMap;
17import java.util.Map;
18
19import java.util.regex.PatternSyntaxException;
20import javax.swing.AbstractAction;
21import javax.swing.BorderFactory;
22import javax.swing.BoxLayout;
23import javax.swing.DefaultComboBoxModel;
24import javax.swing.JCheckBox;
25import javax.swing.JComboBox;
26import javax.swing.JEditorPane;
27import javax.swing.JLabel;
28import javax.swing.JPanel;
29import javax.swing.JScrollPane;
30import javax.swing.JTabbedPane;
31import javax.swing.JTable;
32import javax.swing.JTextField;
33import javax.swing.KeyStroke;
34import javax.swing.ListSelectionModel;
35import javax.swing.RowFilter;
36import javax.swing.SwingConstants;
37import javax.swing.event.DocumentEvent;
38import javax.swing.event.DocumentListener;
39import javax.swing.event.ListSelectionEvent;
40import javax.swing.event.ListSelectionListener;
41import javax.swing.table.AbstractTableModel;
42import javax.swing.table.TableModel;
43
44import javax.swing.table.TableRowSorter;
45import org.openstreetmap.josm.Main;
46import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
47import org.openstreetmap.josm.tools.Shortcut;
48
49/**
50 * This is the keyboard preferences content.
51 * If someone wants to merge it with ShortcutPreference.java, feel free.
52 */
53public class PrefJPanel extends JPanel {
54
55 // table of shortcuts
56 private AbstractTableModel model;
57 // comboboxes of modifier groups, mapping selectedIndex to real data
58 private static int[] modifInts = new int[]{
59 -1,
60 0,
61 KeyEvent.SHIFT_DOWN_MASK,
62 KeyEvent.CTRL_DOWN_MASK,
63 KeyEvent.ALT_DOWN_MASK,
64 KeyEvent.META_DOWN_MASK,
65 KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK,
66 KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK,
67 KeyEvent.META_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK,
68 KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK,
69 KeyEvent.CTRL_DOWN_MASK | KeyEvent.META_DOWN_MASK,
70 KeyEvent.ALT_DOWN_MASK | KeyEvent.META_DOWN_MASK,
71 KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK | KeyEvent.ALT_DOWN_MASK,
72 KeyEvent.META_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK | KeyEvent.ALT_DOWN_MASK
73 };
74 // and here are the texts fro the comboboxes
75 private static String[] modifList = new String[] {
76 tr("disabled"),
77 tr("no modifier"),
78 KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[2]).getModifiers()),
79 KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[3]).getModifiers()),
80 KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[4]).getModifiers()),
81 KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[5]).getModifiers()),
82 KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[6]).getModifiers()),
83 KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[7]).getModifiers()),
84 KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[8]).getModifiers()),
85 KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[9]).getModifiers()),
86 KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[10]).getModifiers()),
87 KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[11]).getModifiers()),
88 KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[12]).getModifiers()),
89 KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[13]).getModifiers())
90 };
91 // this are the display(!) texts for the checkboxes. Let the JVM do the i18n for us <g>.
92 // Ok, there's a real reason for this: The JVM should know best how the keys are labelled
93 // on the physical keyboard. What language pack is installed in JOSM is completely
94 // independent from the keyboard's labelling. But the operation system's locale
95 // usually matches the keyboard. This even works with my English Windows and my German
96 // keyboard.
97 private static String SHIFT = KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.SHIFT_DOWN_MASK).getModifiers());
98 private static String CTRL = KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK).getModifiers());
99 private static String ALT = KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.ALT_DOWN_MASK).getModifiers());
100 private static String META = KeyEvent.getKeyModifiersText(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.META_DOWN_MASK).getModifiers());
101
102 // A list of keys to present the user. Sadly this really is a list of keys Java knows about,
103 // not a list of real physical keys. If someone knows how to get that list?
104 private static Map<Integer, String> keyList = setKeyList();
105
106 private static Map<Integer, String> setKeyList() {
107 Map<Integer, String> list = new LinkedHashMap<Integer, String>();
108 String unknown = Toolkit.getProperty("AWT.unknown", "Unknown");
109 // Assume all known keys are declared in KeyEvent as "public static int VK_*"
110 for (Field field : KeyEvent.class.getFields()) {
111 if (field.getName().startsWith("VK_")) {
112 try {
113 int i = field.getInt(null);
114 String s = KeyEvent.getKeyText(i);
115 if (s != null && s.length() > 0 && !s.contains(unknown)) {
116 list.put(Integer.valueOf(i), s);
117 //System.out.println(i+": "+s);
118 }
119 } catch (Exception e) {
120 e.printStackTrace();
121 }
122 }
123 }
124 list.put(Integer.valueOf(-1), "");
125 return list;
126 }
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 private JCheckBox cbAlt = new JCheckBox();
141 private JCheckBox cbCtrl = new JCheckBox();
142 private JCheckBox cbMeta = new JCheckBox();
143 private JCheckBox cbShift = new JCheckBox();
144 private JCheckBox cbDefault = new JCheckBox();
145 private JCheckBox cbDisable = new JCheckBox();
146 private JComboBox tfKey = new JComboBox();
147
148 JTable shortcutTable = new JTable();
149
150 private JTextField filterField = new JTextField();
151
152 /** Creates new form prefJPanel */
153 // Ain't those auto-generated comments helpful or what? <g>
154 public PrefJPanel(AbstractTableModel model) {
155 this.model = model;
156 initComponents();
157 }
158
159 private void initComponents() {
160 JPanel editGroupPane = new JPanel();
161 JPanel hotkeyGroupPane = new JPanel();
162
163 JPanel listPane = new JPanel();
164 JScrollPane listScrollPane = new JScrollPane();
165 JPanel menuGroupPane = new JPanel();
166 JPanel modifierTab = new JPanel();
167 JTabbedPane prefTabPane = new JTabbedPane();
168 JPanel shortcutEditPane = new JPanel();
169 JPanel shortcutTab = new JPanel();
170 JPanel subwindowGroupPane = new JPanel();
171 JPanel infoTab = new JPanel();
172
173 CbAction action = new CbAction(this);
174 BxAction action2 = new BxAction();
175
176 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
177
178 // If someone wants to move this text into some resource, feel free.
179 infoTab.setLayout(new BoxLayout(shortcutTab, BoxLayout.Y_AXIS));
180 JEditorPane editor = new JEditorPane();
181 editor.setEditable(false);
182 editor.setContentType("text/html");
183 editor.setText(
184 tr("<h1><a name=\"top\">Keyboard Shortcuts</a></h1>")+
185 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>")
203 );
204 editor.setCaretPosition(0); // scroll up
205 prefTabPane.addTab(tr("Read First"), new JScrollPane(editor));
206
207 shortcutTab.setLayout(new BoxLayout(shortcutTab, BoxLayout.Y_AXIS));
208
209 shortcutTab.add(buildFilterPanel());
210 listPane.setLayout(new java.awt.GridLayout());
211
212 // This is the list of shortcuts:
213 shortcutTable.setModel(model);
214 shortcutTable.getSelectionModel().addListSelectionListener(new CbAction(this));
215 shortcutTable.setFillsViewportHeight(true);
216 shortcutTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
217 shortcutTable.setAutoCreateRowSorter(true);
218 listScrollPane.setViewportView(shortcutTable);
219
220 listPane.add(listScrollPane);
221
222 shortcutTab.add(listPane);
223
224 // and here follows the edit area. I won't object to someone re-designing it, it looks, um, "minimalistic" ;)
225 shortcutEditPane.setLayout(new java.awt.GridLayout(5, 2));
226
227 cbDefault.setAction(action);
228 cbDefault.setText(tr("Use default"));
229 cbShift.setAction(action);
230 cbShift.setText(SHIFT); // see above for why no tr()
231 cbDisable.setAction(action);
232 cbDisable.setText(tr("Disable"));
233 cbCtrl.setAction(action);
234 cbCtrl.setText(CTRL); // see above for why no tr()
235 cbAlt.setAction(action);
236 cbAlt.setText(ALT); // see above for why no tr()
237 tfKey.setAction(action);
238 tfKey.setModel(new DefaultComboBoxModel(keyList.values().toArray()));
239 cbMeta.setAction(action);
240 cbMeta.setText(META); // see above for why no tr()
241
242
243 shortcutEditPane.add(cbDefault);
244 shortcutEditPane.add(new JLabel());
245 shortcutEditPane.add(cbShift);
246 shortcutEditPane.add(cbDisable);
247 shortcutEditPane.add(cbCtrl);
248 shortcutEditPane.add(new JLabel(tr("Key:"), SwingConstants.LEFT));
249 shortcutEditPane.add(cbAlt);
250 shortcutEditPane.add(tfKey);
251 shortcutEditPane.add(cbMeta);
252
253 shortcutEditPane.add(new JLabel(tr("Attention: Use real keyboard keys only!")));
254
255 action.actionPerformed(null); // init checkboxes
256
257 shortcutTab.add(shortcutEditPane);
258
259 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
318 add(prefTabPane);
319 }
320
321 private JPanel buildFilterPanel() {
322 // copied from PluginPreference
323 JPanel pnl = new JPanel(new GridBagLayout());
324 pnl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
325 GridBagConstraints gc = new GridBagConstraints();
326
327 gc.anchor = GridBagConstraints.NORTHWEST;
328 gc.fill = GridBagConstraints.HORIZONTAL;
329 gc.weightx = 0.0;
330 gc.insets = new Insets(0,0,0,5);
331 pnl.add(new JLabel(tr("Search:")), gc);
332
333 gc.gridx = 1;
334 gc.weightx = 1.0;
335 pnl.add(filterField, gc);
336 filterField.setToolTipText(tr("Enter a search expression"));
337 SelectAllOnFocusGainedDecorator.decorate(filterField);
338 filterField.getDocument().addDocumentListener(new FilterFieldAdapter());
339 pnl.setMaximumSize(new Dimension(300,10));
340 return pnl;
341 }
342
343 private void disableAllModifierCheckboxes() {
344 cbDefault.setEnabled(false);
345 cbDisable.setEnabled(false);
346 cbShift.setEnabled(false);
347 cbCtrl.setEnabled(false);
348 cbAlt.setEnabled(false);
349 cbMeta.setEnabled(false);
350 }
351
352 // this allows to edit shortcuts. it:
353 // * sets the edit controls to the selected shortcut
354 // * enabled/disables the controls as needed
355 // * writes the user's changes to the shortcut
356 // And after I finally had it working, I realized that those two methods
357 // are playing ping-pong (politically correct: table tennis, I know) and
358 // even have some duplicated code. Feel free to refactor, If you have
359 // more expirience with GUI coding than I have.
360 private class CbAction extends AbstractAction implements ListSelectionListener {
361 private PrefJPanel panel;
362 public CbAction (PrefJPanel panel) {
363 this.panel = panel;
364 }
365 public void valueChanged(ListSelectionEvent e) {
366 ListSelectionModel lsm = panel.shortcutTable.getSelectionModel(); // can't use e here
367 if (!lsm.isSelectionEmpty()) {
368 int row = panel.shortcutTable.convertRowIndexToModel(lsm.getMinSelectionIndex());
369 Shortcut sc = (Shortcut)panel.model.getValueAt(row, -1);
370 panel.cbDefault.setSelected(!sc.getAssignedUser());
371 panel.cbDisable.setSelected(sc.getKeyStroke() == null);
372 panel.cbShift.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.SHIFT_DOWN_MASK) != 0);
373 panel.cbCtrl.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.CTRL_DOWN_MASK) != 0);
374 panel.cbAlt.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.ALT_DOWN_MASK) != 0);
375 panel.cbMeta.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.META_DOWN_MASK) != 0);
376 if (sc.getKeyStroke() != null) {
377 tfKey.setSelectedItem(keyList.get(sc.getKeyStroke().getKeyCode()));
378 } else {
379 tfKey.setSelectedItem(keyList.get(-1));
380 }
381 if (!sc.isChangeable()) {
382 disableAllModifierCheckboxes();
383 panel.tfKey.setEnabled(false);
384 } else {
385 panel.cbDefault.setEnabled(true);
386 actionPerformed(null);
387 }
388 model.fireTableCellUpdated(row, 1);
389 } else {
390 panel.disableAllModifierCheckboxes();
391 panel.tfKey.setEnabled(false);
392 }
393 }
394 public void actionPerformed(java.awt.event.ActionEvent e) {
395 ListSelectionModel lsm = panel.shortcutTable.getSelectionModel();
396 if (lsm != null && !lsm.isSelectionEmpty()) {
397 if (e != null) { // only if we've been called by a user action
398 int row = panel.shortcutTable.convertRowIndexToModel(lsm.getMinSelectionIndex());
399 Shortcut sc = (Shortcut)panel.model.getValueAt(row, -1);
400 if (panel.cbDisable.isSelected()) {
401 sc.setAssignedModifier(-1);
402 } else if (panel.tfKey.getSelectedItem().equals("")) {
403 sc.setAssignedModifier(KeyEvent.VK_CANCEL);
404 } else {
405 sc.setAssignedModifier(
406 (panel.cbShift.isSelected() ? KeyEvent.SHIFT_DOWN_MASK : 0) |
407 (panel.cbCtrl.isSelected() ? KeyEvent.CTRL_DOWN_MASK : 0) |
408 (panel.cbAlt.isSelected() ? KeyEvent.ALT_DOWN_MASK : 0) |
409 (panel.cbMeta.isSelected() ? KeyEvent.META_DOWN_MASK : 0)
410 );
411 for (Map.Entry<Integer, String> entry : keyList.entrySet()) {
412 if (entry.getValue().equals(panel.tfKey.getSelectedItem())) {
413 sc.setAssignedKey(entry.getKey());
414 }
415 }
416 }
417 sc.setAssignedUser(!panel.cbDefault.isSelected());
418 valueChanged(null);
419 }
420 boolean state = !panel.cbDefault.isSelected();
421 panel.cbDisable.setEnabled(state);
422 state = state && !panel.cbDisable.isSelected();
423 panel.cbShift.setEnabled(state);
424 panel.cbCtrl.setEnabled(state);
425 panel.cbAlt.setEnabled(state);
426 panel.cbMeta.setEnabled(state);
427 panel.tfKey.setEnabled(state);
428 } else {
429 panel.disableAllModifierCheckboxes();
430 panel.tfKey.setEnabled(false);
431 }
432 }
433 }
434
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 {
485 public void filter() {
486 String expr = filterField.getText().trim();
487 if (expr.length()==0) { expr=null; }
488 try {
489 final TableRowSorter<? extends TableModel> sorter =
490 ((TableRowSorter<? extends TableModel> )shortcutTable.getRowSorter());
491 if (expr == null) {
492 sorter.setRowFilter(null);
493 } else {
494 // split search string on whitespace, do case-insensitive AND search
495 ArrayList<RowFilter<Object, Object>> andFilters = new ArrayList<RowFilter<Object, Object>>();
496 for (String word : expr.split("\\s+")) {
497 andFilters.add(RowFilter.regexFilter("(?i)" + word));
498 }
499 sorter.setRowFilter(RowFilter.andFilter(andFilters));
500 }
501 }
502 catch (PatternSyntaxException ex) { }
503 catch (ClassCastException ex2) { /* eliminate warning */ }
504 }
505
506 public void changedUpdate(DocumentEvent arg0) { filter(); }
507 public void insertUpdate(DocumentEvent arg0) { filter(); }
508 public void removeUpdate(DocumentEvent arg0) { filter(); }
509 }
510
511}
Note: See TracBrowser for help on using the repository browser.