1 | /*
|
---|
2 | * prefJPanel.java
|
---|
3 | *
|
---|
4 | * Created on 28. September 2008, 17:47
|
---|
5 | */
|
---|
6 |
|
---|
7 | package org.openstreetmap.josm.gui.preferences;
|
---|
8 |
|
---|
9 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
10 |
|
---|
11 | import java.awt.event.KeyEvent;
|
---|
12 | import java.util.LinkedHashMap;
|
---|
13 | import java.util.Map;
|
---|
14 |
|
---|
15 | import javax.swing.JEditorPane;
|
---|
16 | import javax.swing.JScrollPane;
|
---|
17 | import javax.swing.ListSelectionModel;
|
---|
18 | import javax.swing.event.ListSelectionEvent;
|
---|
19 | import javax.swing.event.ListSelectionListener;
|
---|
20 | import javax.swing.table.TableModel;
|
---|
21 |
|
---|
22 | import org.openstreetmap.josm.Main;
|
---|
23 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * This is the keyboard preferences content.
|
---|
27 | * If someone wants to merge it with ShortcutPreference.java, feel free.
|
---|
28 | */
|
---|
29 | public class PrefJPanel extends javax.swing.JPanel {
|
---|
30 |
|
---|
31 | // table of shortcuts
|
---|
32 | private TableModel model;
|
---|
33 | // comboboxes of modifier groups, mapping selectedIndex to real data
|
---|
34 | private static int[] modifInts = new int[]{
|
---|
35 | -1,
|
---|
36 | 0,
|
---|
37 | KeyEvent.SHIFT_DOWN_MASK,
|
---|
38 | KeyEvent.CTRL_DOWN_MASK,
|
---|
39 | KeyEvent.ALT_DOWN_MASK,
|
---|
40 | KeyEvent.META_DOWN_MASK,
|
---|
41 | KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK,
|
---|
42 | KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK,
|
---|
43 | KeyEvent.META_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK,
|
---|
44 | KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK,
|
---|
45 | KeyEvent.CTRL_DOWN_MASK | KeyEvent.META_DOWN_MASK,
|
---|
46 | KeyEvent.ALT_DOWN_MASK | KeyEvent.META_DOWN_MASK,
|
---|
47 | KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK | KeyEvent.ALT_DOWN_MASK,
|
---|
48 | KeyEvent.META_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK | KeyEvent.ALT_DOWN_MASK
|
---|
49 | };
|
---|
50 | // and here are the texts fro the comboboxes
|
---|
51 | private static String[] modifList = new String[] {
|
---|
52 | tr("disabled"),
|
---|
53 | tr("no modifier"),
|
---|
54 | KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[2]).getModifiers()),
|
---|
55 | KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[3]).getModifiers()),
|
---|
56 | KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[4]).getModifiers()),
|
---|
57 | KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[5]).getModifiers()),
|
---|
58 | KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[6]).getModifiers()),
|
---|
59 | KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[7]).getModifiers()),
|
---|
60 | KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[8]).getModifiers()),
|
---|
61 | KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[9]).getModifiers()),
|
---|
62 | KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[10]).getModifiers()),
|
---|
63 | KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[11]).getModifiers()),
|
---|
64 | KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[12]).getModifiers()),
|
---|
65 | KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, modifInts[13]).getModifiers())
|
---|
66 | };
|
---|
67 | // this are the display(!) texts for the checkboxes. Let the JVM do the i18n for us <g>.
|
---|
68 | // Ok, there's a real reason for this: The JVM should know best how the keys are labelled
|
---|
69 | // on the physical keyboard. What language pack is installed in JOSM is completely
|
---|
70 | // independent from the keyboard's labelling. But the operation system's locale
|
---|
71 | // usually matches the keyboard. This even works with my English Windows and my German
|
---|
72 | // keyboard.
|
---|
73 | private static String SHIFT = KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.SHIFT_DOWN_MASK).getModifiers());
|
---|
74 | private static String CTRL = KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK).getModifiers());
|
---|
75 | private static String ALT = KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.ALT_DOWN_MASK).getModifiers());
|
---|
76 | private static String META = KeyEvent.getKeyModifiersText(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.META_DOWN_MASK).getModifiers());
|
---|
77 |
|
---|
78 | // A list of keys to present the user. Sadly this really is a list of keys Java knows about,
|
---|
79 | // not a list of real physical keys. If someone knows how to get that list?
|
---|
80 | private static Map<Integer, String> keyList = setKeyList();
|
---|
81 |
|
---|
82 | private static Map<Integer, String> setKeyList() {
|
---|
83 | Map<Integer, String> list = new LinkedHashMap<Integer, String>();
|
---|
84 | // I hate this, but I found no alternative...
|
---|
85 | for (int i = 0; i < 65534; i++) {
|
---|
86 | String s = KeyEvent.getKeyText(i);
|
---|
87 | if (s != null && s.length() > 0 && !s.contains("Unknown")) {
|
---|
88 | list.put(Integer.valueOf(i), s);
|
---|
89 | //System.out.println(i+": "+s);
|
---|
90 | }
|
---|
91 | }
|
---|
92 | list.put(Integer.valueOf(-1), "");
|
---|
93 | return list;
|
---|
94 | }
|
---|
95 |
|
---|
96 | /** Creates new form prefJPanel */
|
---|
97 | // Ain't those auto-generated comments helpful or what? <g>
|
---|
98 | public PrefJPanel(TableModel model) {
|
---|
99 | this.model = model;
|
---|
100 | initComponents();
|
---|
101 | }
|
---|
102 |
|
---|
103 | private void initComponents() {
|
---|
104 |
|
---|
105 | // Did I mention auto-generated? That's the reason we
|
---|
106 | // have lots of properties here and not some arrays...
|
---|
107 | prefTabPane = new javax.swing.JTabbedPane();
|
---|
108 | shortcutTab = new javax.swing.JPanel();
|
---|
109 | listPane = new javax.swing.JPanel();
|
---|
110 | listScrollPane = new javax.swing.JScrollPane();
|
---|
111 | shortcutTable = new javax.swing.JTable();
|
---|
112 | shortcutEditPane = new javax.swing.JPanel();
|
---|
113 | cbDefault = new javax.swing.JCheckBox();
|
---|
114 | jLabel4 = new javax.swing.JLabel();
|
---|
115 | cbShift = new javax.swing.JCheckBox();
|
---|
116 | cbDisable = new javax.swing.JCheckBox();
|
---|
117 | cbCtrl = new javax.swing.JCheckBox();
|
---|
118 | tfKeyLabel = new javax.swing.JLabel();
|
---|
119 | cbAlt = new javax.swing.JCheckBox();
|
---|
120 | tfKey = new javax.swing.JComboBox();
|
---|
121 | cbMeta = new javax.swing.JCheckBox();
|
---|
122 | jLabel6 = new javax.swing.JLabel();
|
---|
123 | modifierTab = new javax.swing.JPanel();
|
---|
124 | editGroupPane = new javax.swing.JPanel();
|
---|
125 | jLabel1 = new javax.swing.JLabel();
|
---|
126 | bxPrim1 = new javax.swing.JComboBox();
|
---|
127 | jLabel2 = new javax.swing.JLabel();
|
---|
128 | bxSec1 = new javax.swing.JComboBox();
|
---|
129 | jLabel3 = new javax.swing.JLabel();
|
---|
130 | bxTer1 = new javax.swing.JComboBox();
|
---|
131 | menuGroupPane = new javax.swing.JPanel();
|
---|
132 | jLabel7 = new javax.swing.JLabel();
|
---|
133 | bxPrim2 = new javax.swing.JComboBox();
|
---|
134 | jLabel8 = new javax.swing.JLabel();
|
---|
135 | bxSec2 = new javax.swing.JComboBox();
|
---|
136 | jLabel9 = new javax.swing.JLabel();
|
---|
137 | bxTer2 = new javax.swing.JComboBox();
|
---|
138 | hotkeyGroupPane = new javax.swing.JPanel();
|
---|
139 | jLabel10 = new javax.swing.JLabel();
|
---|
140 | bxPrim3 = new javax.swing.JComboBox();
|
---|
141 | jLabel11 = new javax.swing.JLabel();
|
---|
142 | bxSec3 = new javax.swing.JComboBox();
|
---|
143 | jLabel12 = new javax.swing.JLabel();
|
---|
144 | bxTer3 = new javax.swing.JComboBox();
|
---|
145 | subwindowGroupPane = new javax.swing.JPanel();
|
---|
146 | jLabel13 = new javax.swing.JLabel();
|
---|
147 | bxPrim4 = new javax.swing.JComboBox();
|
---|
148 | jLabel14 = new javax.swing.JLabel();
|
---|
149 | bxSec4 = new javax.swing.JComboBox();
|
---|
150 | jLabel15 = new javax.swing.JLabel();
|
---|
151 | bxTer4 = new javax.swing.JComboBox();
|
---|
152 | infoTab = new javax.swing.JPanel();
|
---|
153 | cbAction action = new cbAction(this);
|
---|
154 | bxAction action2 = new bxAction();
|
---|
155 |
|
---|
156 | setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
|
---|
157 |
|
---|
158 | // If someone wants to move this text into some resource, feel free.
|
---|
159 | infoTab.setLayout(new javax.swing.BoxLayout(shortcutTab, javax.swing.BoxLayout.Y_AXIS));
|
---|
160 | JEditorPane editor = new JEditorPane();
|
---|
161 | editor.setEditable(false);
|
---|
162 | editor.setContentType("text/html");
|
---|
163 | editor.setText(
|
---|
164 | tr("<h1><a name=\"top\">Keyboard Shortcuts</a></h1>")+
|
---|
165 | tr("<p>Please note that shortcut keys are assigned to the actions when JOSM is started. So you need to <b>restart</b> "
|
---|
166 | +"JOSM to see your changes.</p>")+
|
---|
167 | tr("<p>Furthermore, the shortcuts are activated when the actions are assigned to a menu entry of a button for the first "
|
---|
168 | +"time. So some of your changes may become active even without restart --- but also without collision handling. "
|
---|
169 | +"This is another reason to <b>restart</b> JOSM after making any changes here.</p>")+
|
---|
170 | tr("<p>You may notice that the key selection list on the next page lists all keys that exist on all kinds of keyboards "
|
---|
171 | +"Java knows about, not just those keys that exist on your keyboard. Please only use values that correspond to "
|
---|
172 | +"a real key on your keyboard. If your keyboard has no ''Copy'' key (PC keyboard do not have them, Sun keyboards do), "
|
---|
173 | +"then do not use it. Also there are ''keys'' listed that correspond to a shortcut on your keyboard (e.g. '':''/Colon). "
|
---|
174 | +"Please do not use them either, use the base key ('';''/Semicolon on US keyboards, ''.''/Period on German keyboards, etc.) "
|
---|
175 | +"instead. Not doing so may result in conflicts, as there is no way for JOSM to know that Ctrl+Shift+; and Ctrl+: "
|
---|
176 | +"actually is the same thing on an US keyboard.</p>")+
|
---|
177 | tr("<h1>Modifier Groups</h1>")+
|
---|
178 | tr("<p>The last page lists the modifier keys JOSM will automatically assign to shortcuts. For every of the four kinds "
|
---|
179 | +"of shortcuts there are three alternatives. JOSM will try those alternatives in the listed order when managing a "
|
---|
180 | +"conflict. If all alternatives result in shortcuts that are already taken, it will assign a random shortcut "
|
---|
181 | +"instead.</p>")+
|
---|
182 | tr("<p>The pseudo-modifier ''disabled'' will disable the shortcut when encountered.</p>")
|
---|
183 | );
|
---|
184 | editor.setCaretPosition(0); // scroll up
|
---|
185 | prefTabPane.addTab(tr("Read First"), new JScrollPane(editor));
|
---|
186 |
|
---|
187 | shortcutTab.setLayout(new javax.swing.BoxLayout(shortcutTab, javax.swing.BoxLayout.Y_AXIS));
|
---|
188 |
|
---|
189 | listPane.setLayout(new java.awt.GridLayout());
|
---|
190 |
|
---|
191 | // This is the list of shortcuts:
|
---|
192 | shortcutTable.setModel(model);
|
---|
193 | shortcutTable.getSelectionModel().addListSelectionListener(new cbAction(this));
|
---|
194 | //shortcutTable.setFillsViewportHeight(true); Java 1.6
|
---|
195 | shortcutTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
---|
196 | listScrollPane.setViewportView(shortcutTable);
|
---|
197 |
|
---|
198 | listPane.add(listScrollPane);
|
---|
199 |
|
---|
200 | shortcutTab.add(listPane);
|
---|
201 |
|
---|
202 | // and here follows the edit area. I won't object to someone re-designing it, it looks, um, "minimalistic" ;)
|
---|
203 | shortcutEditPane.setLayout(new java.awt.GridLayout(5, 2));
|
---|
204 |
|
---|
205 | cbDefault.setAction(action);
|
---|
206 | cbDefault.setText(tr("Use default"));
|
---|
207 | shortcutEditPane.add(cbDefault);
|
---|
208 |
|
---|
209 | shortcutEditPane.add(jLabel4);
|
---|
210 |
|
---|
211 | cbShift.setAction(action);
|
---|
212 | cbShift.setText(SHIFT); // see above for why no tr()
|
---|
213 | shortcutEditPane.add(cbShift);
|
---|
214 |
|
---|
215 | cbDisable.setAction(action);
|
---|
216 | cbDisable.setText(tr("Disable"));
|
---|
217 | shortcutEditPane.add(cbDisable);
|
---|
218 |
|
---|
219 | cbCtrl.setAction(action);
|
---|
220 | cbCtrl.setText(CTRL); // see above for why no tr()
|
---|
221 | shortcutEditPane.add(cbCtrl);
|
---|
222 |
|
---|
223 | tfKeyLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
|
---|
224 | tfKeyLabel.setText(tr("Key:"));
|
---|
225 | shortcutEditPane.add(tfKeyLabel);
|
---|
226 |
|
---|
227 | cbAlt.setAction(action);
|
---|
228 | cbAlt.setText(ALT); // see above for why no tr()
|
---|
229 | shortcutEditPane.add(cbAlt);
|
---|
230 |
|
---|
231 | tfKey.setAction(action);
|
---|
232 | tfKey.setModel(new javax.swing.DefaultComboBoxModel(keyList.values().toArray()));
|
---|
233 | shortcutEditPane.add(tfKey);
|
---|
234 |
|
---|
235 | cbMeta.setAction(action);
|
---|
236 | cbMeta.setText(META); // see above for why no tr()
|
---|
237 | shortcutEditPane.add(cbMeta);
|
---|
238 |
|
---|
239 | jLabel6.setText(tr("Attention: Use real keyboard keys only!"));
|
---|
240 | shortcutEditPane.add(jLabel6);
|
---|
241 |
|
---|
242 | action.actionPerformed(null); // init checkboxes
|
---|
243 |
|
---|
244 | shortcutTab.add(shortcutEditPane);
|
---|
245 |
|
---|
246 | prefTabPane.addTab(tr("Keyboard Shortcuts"), shortcutTab);
|
---|
247 |
|
---|
248 | // next is the modfier group tab.
|
---|
249 | // Would be a nice array if I had done it by hand. But then, it would be finished next year or so...
|
---|
250 | modifierTab.setLayout(new java.awt.GridLayout(0, 1));
|
---|
251 | JScrollPane modifierScroller = new JScrollPane(modifierTab);
|
---|
252 |
|
---|
253 | editGroupPane.setBorder(javax.swing.BorderFactory.createTitledBorder(tr("Edit Shortcuts")));
|
---|
254 | editGroupPane.setLayout(new java.awt.GridLayout(3, 5));
|
---|
255 |
|
---|
256 | jLabel1.setText(tr("Primary modifier:"));
|
---|
257 | editGroupPane.add(jLabel1);
|
---|
258 |
|
---|
259 | bxPrim1.setModel(new javax.swing.DefaultComboBoxModel(modifList));
|
---|
260 | editGroupPane.add(bxPrim1);
|
---|
261 |
|
---|
262 | jLabel2.setText(tr("Secondary modifier:"));
|
---|
263 | editGroupPane.add(jLabel2);
|
---|
264 |
|
---|
265 | bxSec1.setModel(new javax.swing.DefaultComboBoxModel(modifList));
|
---|
266 | editGroupPane.add(bxSec1);
|
---|
267 |
|
---|
268 | jLabel3.setText(tr("Tertiary modifier:"));
|
---|
269 | editGroupPane.add(jLabel3);
|
---|
270 |
|
---|
271 | bxTer1.setModel(new javax.swing.DefaultComboBoxModel(modifList));
|
---|
272 | editGroupPane.add(bxTer1);
|
---|
273 |
|
---|
274 | modifierTab.add(editGroupPane);
|
---|
275 |
|
---|
276 | menuGroupPane.setBorder(javax.swing.BorderFactory.createTitledBorder(tr("Menu Shortcuts")));
|
---|
277 | menuGroupPane.setLayout(new java.awt.GridLayout(3, 5));
|
---|
278 |
|
---|
279 | jLabel7.setText(tr("Primary modifier:"));
|
---|
280 | menuGroupPane.add(jLabel7);
|
---|
281 |
|
---|
282 | bxPrim2.setModel(new javax.swing.DefaultComboBoxModel(modifList));
|
---|
283 | menuGroupPane.add(bxPrim2);
|
---|
284 |
|
---|
285 | jLabel8.setText(tr("Secondary modifier:"));
|
---|
286 | menuGroupPane.add(jLabel8);
|
---|
287 |
|
---|
288 | bxSec2.setModel(new javax.swing.DefaultComboBoxModel(modifList));
|
---|
289 | menuGroupPane.add(bxSec2);
|
---|
290 |
|
---|
291 | jLabel9.setText(tr("Tertiary modifier:"));
|
---|
292 | menuGroupPane.add(jLabel9);
|
---|
293 |
|
---|
294 | bxTer2.setModel(new javax.swing.DefaultComboBoxModel(modifList));
|
---|
295 | menuGroupPane.add(bxTer2);
|
---|
296 |
|
---|
297 | modifierTab.add(menuGroupPane);
|
---|
298 |
|
---|
299 | hotkeyGroupPane.setBorder(javax.swing.BorderFactory.createTitledBorder(tr("Hotkey Shortcuts")));
|
---|
300 | hotkeyGroupPane.setLayout(new java.awt.GridLayout(3, 5));
|
---|
301 |
|
---|
302 | jLabel10.setText(tr("Primary modifier:"));
|
---|
303 | hotkeyGroupPane.add(jLabel10);
|
---|
304 |
|
---|
305 | bxPrim3.setModel(new javax.swing.DefaultComboBoxModel(modifList));
|
---|
306 | hotkeyGroupPane.add(bxPrim3);
|
---|
307 |
|
---|
308 | jLabel11.setText(tr("Secondary modifier:"));
|
---|
309 | hotkeyGroupPane.add(jLabel11);
|
---|
310 |
|
---|
311 | bxSec3.setModel(new javax.swing.DefaultComboBoxModel(modifList));
|
---|
312 | hotkeyGroupPane.add(bxSec3);
|
---|
313 |
|
---|
314 | jLabel12.setText(tr("Tertiary modifier:"));
|
---|
315 | hotkeyGroupPane.add(jLabel12);
|
---|
316 |
|
---|
317 | bxTer3.setModel(new javax.swing.DefaultComboBoxModel(modifList));
|
---|
318 | hotkeyGroupPane.add(bxTer3);
|
---|
319 |
|
---|
320 | modifierTab.add(hotkeyGroupPane);
|
---|
321 |
|
---|
322 | subwindowGroupPane.setBorder(javax.swing.BorderFactory.createTitledBorder(tr("Subwindow Shortcuts")));
|
---|
323 | subwindowGroupPane.setLayout(new java.awt.GridLayout(3, 5));
|
---|
324 |
|
---|
325 | jLabel13.setText(tr("Primary modifier:"));
|
---|
326 | subwindowGroupPane.add(jLabel13);
|
---|
327 |
|
---|
328 | bxPrim4.setModel(new javax.swing.DefaultComboBoxModel(modifList));
|
---|
329 | subwindowGroupPane.add(bxPrim4);
|
---|
330 |
|
---|
331 | jLabel14.setText(tr("Secondary modifier:"));
|
---|
332 | subwindowGroupPane.add(jLabel14);
|
---|
333 |
|
---|
334 | bxSec4.setModel(new javax.swing.DefaultComboBoxModel(modifList));
|
---|
335 | subwindowGroupPane.add(bxSec4);
|
---|
336 |
|
---|
337 | jLabel15.setText(tr("Tertiary modifier:"));
|
---|
338 | subwindowGroupPane.add(jLabel15);
|
---|
339 |
|
---|
340 | bxTer4.setModel(new javax.swing.DefaultComboBoxModel(modifList));
|
---|
341 | subwindowGroupPane.add(bxTer4);
|
---|
342 |
|
---|
343 | initbx();
|
---|
344 | bxPrim1.setAction(action2);
|
---|
345 | bxSec1.setAction(action2);
|
---|
346 | bxTer1.setAction(action2);
|
---|
347 | bxPrim2.setAction(action2);
|
---|
348 | bxSec2.setAction(action2);
|
---|
349 | bxTer2.setAction(action2);
|
---|
350 | bxPrim3.setAction(action2);
|
---|
351 | bxSec3.setAction(action2);
|
---|
352 | bxTer3.setAction(action2);
|
---|
353 | bxPrim4.setAction(action2);
|
---|
354 | bxSec4.setAction(action2);
|
---|
355 | bxTer4.setAction(action2);
|
---|
356 |
|
---|
357 | modifierTab.add(subwindowGroupPane);
|
---|
358 |
|
---|
359 | prefTabPane.addTab(tr("Modifier Groups"), modifierScroller);
|
---|
360 |
|
---|
361 | add(prefTabPane);
|
---|
362 | }
|
---|
363 |
|
---|
364 | // this allows to edit shortcuts. it:
|
---|
365 | // * sets the edit controls to the selected shortcut
|
---|
366 | // * enabled/disables the controls as needed
|
---|
367 | // * writes the user's changes to the shortcut
|
---|
368 | // And after I finally had it working, I realized that those two methods
|
---|
369 | // are playing ping-pong (politically correct: table tennis, I know) and
|
---|
370 | // even have some duplicated code. Feel free to refactor, If you have
|
---|
371 | // more expirience with GUI coding than I have.
|
---|
372 | private class cbAction extends javax.swing.AbstractAction implements ListSelectionListener {
|
---|
373 | private PrefJPanel panel;
|
---|
374 | public cbAction (PrefJPanel panel) {
|
---|
375 | this.panel = panel;
|
---|
376 | }
|
---|
377 | public void valueChanged(ListSelectionEvent e) {
|
---|
378 | ListSelectionModel lsm = panel.shortcutTable.getSelectionModel(); // can't use e here
|
---|
379 | if (!lsm.isSelectionEmpty()) {
|
---|
380 | int row = lsm.getMinSelectionIndex();
|
---|
381 | Shortcut sc = (Shortcut)panel.model.getValueAt(row, -1);
|
---|
382 | panel.cbDefault.setSelected(!sc.getAssignedUser());
|
---|
383 | panel.cbDisable.setSelected(sc.getKeyStroke() == null);
|
---|
384 | panel.cbShift.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.SHIFT_DOWN_MASK) != 0);
|
---|
385 | panel.cbCtrl.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.CTRL_DOWN_MASK) != 0);
|
---|
386 | panel.cbAlt.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.ALT_DOWN_MASK) != 0);
|
---|
387 | panel.cbMeta.setSelected(sc.getAssignedModifier() != -1 && (sc.getAssignedModifier() & KeyEvent.META_DOWN_MASK) != 0);
|
---|
388 | if (sc.getKeyStroke() != null) {
|
---|
389 | tfKey.setSelectedItem(keyList.get(sc.getKeyStroke().getKeyCode()));
|
---|
390 | } else {
|
---|
391 | tfKey.setSelectedItem(keyList.get(-1));
|
---|
392 | }
|
---|
393 | if (!sc.isChangeable()) {
|
---|
394 | panel.cbDefault.setEnabled(false);
|
---|
395 | panel.cbDisable.setEnabled(false);
|
---|
396 | panel.cbShift.setEnabled(false);
|
---|
397 | panel.cbCtrl.setEnabled(false);
|
---|
398 | panel.cbAlt.setEnabled(false);
|
---|
399 | panel.cbMeta.setEnabled(false);
|
---|
400 | panel.tfKey.setEnabled(false);
|
---|
401 | } else {
|
---|
402 | panel.cbDefault.setEnabled(true);
|
---|
403 | actionPerformed(null);
|
---|
404 | }
|
---|
405 | } else {
|
---|
406 | panel.cbDefault.setEnabled(false);
|
---|
407 | panel.cbDisable.setEnabled(false);
|
---|
408 | panel.cbShift.setEnabled(false);
|
---|
409 | panel.cbCtrl.setEnabled(false);
|
---|
410 | panel.cbAlt.setEnabled(false);
|
---|
411 | panel.cbMeta.setEnabled(false);
|
---|
412 | panel.tfKey.setEnabled(false);
|
---|
413 | }
|
---|
414 | }
|
---|
415 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
416 | ListSelectionModel lsm = panel.shortcutTable.getSelectionModel();
|
---|
417 | if (lsm != null && !lsm.isSelectionEmpty()) {
|
---|
418 | if (e != null) { // only if we've been called by a user action
|
---|
419 | int row = lsm.getMinSelectionIndex();
|
---|
420 | Shortcut sc = (Shortcut)panel.model.getValueAt(row, -1);
|
---|
421 | sc.setAssignedUser(!panel.cbDefault.isSelected());
|
---|
422 | if (panel.cbDisable.isSelected()) {
|
---|
423 | sc.setAssignedModifier(-1);
|
---|
424 | } else if (panel.tfKey.getSelectedItem().equals("")) {
|
---|
425 | sc.setAssignedModifier(KeyEvent.VK_CANCEL);
|
---|
426 | } else {
|
---|
427 | sc.setAssignedModifier(
|
---|
428 | (panel.cbShift.isSelected() ? KeyEvent.SHIFT_DOWN_MASK : 0) |
|
---|
429 | (panel.cbCtrl.isSelected() ? KeyEvent.CTRL_DOWN_MASK : 0) |
|
---|
430 | (panel.cbAlt.isSelected() ? KeyEvent.ALT_DOWN_MASK : 0) |
|
---|
431 | (panel.cbMeta.isSelected() ? KeyEvent.META_DOWN_MASK : 0)
|
---|
432 | );
|
---|
433 | for (Map.Entry<Integer, String> entry : keyList.entrySet()) {
|
---|
434 | if (entry.getValue().equals(panel.tfKey.getSelectedItem())) {
|
---|
435 | sc.setAssignedKey(entry.getKey());
|
---|
436 | }
|
---|
437 | }
|
---|
438 | }
|
---|
439 | valueChanged(null);
|
---|
440 | }
|
---|
441 | boolean state = !panel.cbDefault.isSelected();
|
---|
442 | panel.cbDisable.setEnabled(state);
|
---|
443 | state = state && !panel.cbDisable.isSelected();
|
---|
444 | panel.cbShift.setEnabled(state);
|
---|
445 | panel.cbCtrl.setEnabled(state);
|
---|
446 | panel.cbAlt.setEnabled(state);
|
---|
447 | panel.cbMeta.setEnabled(state);
|
---|
448 | panel.tfKey.setEnabled(state);
|
---|
449 | } else {
|
---|
450 | panel.cbDefault.setEnabled(false);
|
---|
451 | panel.cbDisable.setEnabled(false);
|
---|
452 | panel.cbShift.setEnabled(false);
|
---|
453 | panel.cbCtrl.setEnabled(false);
|
---|
454 | panel.cbAlt.setEnabled(false);
|
---|
455 | panel.cbMeta.setEnabled(false);
|
---|
456 | panel.tfKey.setEnabled(false);
|
---|
457 | }
|
---|
458 | }
|
---|
459 | }
|
---|
460 |
|
---|
461 | // this handles the modifier groups
|
---|
462 | private class bxAction extends javax.swing.AbstractAction {
|
---|
463 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
464 | Main.pref.put("shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_EDIT), Integer.toString( modifInts[bxPrim1.getSelectedIndex()] ));
|
---|
465 | Main.pref.put("shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_EDIT), Integer.toString( modifInts[ bxSec1.getSelectedIndex()] ));
|
---|
466 | Main.pref.put("shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_EDIT), Integer.toString( modifInts[ bxTer1.getSelectedIndex()] ));
|
---|
467 |
|
---|
468 | Main.pref.put("shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_MENU), Integer.toString( modifInts[bxPrim2.getSelectedIndex()] ));
|
---|
469 | Main.pref.put("shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_MENU), Integer.toString( modifInts[ bxSec2.getSelectedIndex()] ));
|
---|
470 | Main.pref.put("shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_MENU), Integer.toString( modifInts[ bxTer2.getSelectedIndex()] ));
|
---|
471 |
|
---|
472 | Main.pref.put("shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_HOTKEY), Integer.toString( modifInts[bxPrim3.getSelectedIndex()] ));
|
---|
473 | Main.pref.put("shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_HOTKEY), Integer.toString( modifInts[ bxSec3.getSelectedIndex()] ));
|
---|
474 | Main.pref.put("shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_HOTKEY), Integer.toString( modifInts[ bxTer3.getSelectedIndex()] ));
|
---|
475 |
|
---|
476 | Main.pref.put("shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_LAYER), Integer.toString( modifInts[bxPrim4.getSelectedIndex()] ));
|
---|
477 | Main.pref.put("shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_LAYER), Integer.toString( modifInts[ bxSec4.getSelectedIndex()] ));
|
---|
478 | Main.pref.put("shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_LAYER), Integer.toString( modifInts[ bxTer4.getSelectedIndex()] ));
|
---|
479 | }
|
---|
480 | }
|
---|
481 |
|
---|
482 | private void initbx() {
|
---|
483 | setBx(bxPrim1, "shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_EDIT));
|
---|
484 | setBx(bxSec1, "shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_EDIT));
|
---|
485 | setBx(bxTer1, "shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_EDIT));
|
---|
486 |
|
---|
487 | setBx(bxPrim2, "shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_MENU));
|
---|
488 | setBx(bxSec2, "shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_MENU));
|
---|
489 | setBx(bxTer2, "shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_MENU));
|
---|
490 |
|
---|
491 | setBx(bxPrim3, "shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_HOTKEY));
|
---|
492 | setBx(bxSec3, "shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_HOTKEY));
|
---|
493 | setBx(bxTer3, "shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_HOTKEY));
|
---|
494 |
|
---|
495 | setBx(bxPrim4, "shortcut.groups."+(Shortcut.GROUPS_DEFAULT+Shortcut.GROUP_LAYER));
|
---|
496 | setBx(bxSec4, "shortcut.groups."+(Shortcut.GROUPS_ALT1 +Shortcut.GROUP_LAYER));
|
---|
497 | setBx(bxTer4, "shortcut.groups."+(Shortcut.GROUPS_ALT2 +Shortcut.GROUP_LAYER));
|
---|
498 | }
|
---|
499 | private void setBx(javax.swing.JComboBox bx, String key) {
|
---|
500 | int target = Main.pref.getInteger(key, -1);
|
---|
501 | for (int i = 0; i < modifInts.length; i++) {
|
---|
502 | if (modifInts[i] == target) {
|
---|
503 | bx.setSelectedIndex(i);
|
---|
504 | }
|
---|
505 | }
|
---|
506 | }
|
---|
507 |
|
---|
508 | private javax.swing.JComboBox bxPrim1;
|
---|
509 | private javax.swing.JComboBox bxPrim2;
|
---|
510 | private javax.swing.JComboBox bxPrim3;
|
---|
511 | private javax.swing.JComboBox bxPrim4;
|
---|
512 | private javax.swing.JComboBox bxSec1;
|
---|
513 | private javax.swing.JComboBox bxSec2;
|
---|
514 | private javax.swing.JComboBox bxSec3;
|
---|
515 | private javax.swing.JComboBox bxSec4;
|
---|
516 | private javax.swing.JComboBox bxTer1;
|
---|
517 | private javax.swing.JComboBox bxTer2;
|
---|
518 | private javax.swing.JComboBox bxTer3;
|
---|
519 | private javax.swing.JComboBox bxTer4;
|
---|
520 | private javax.swing.JCheckBox cbAlt;
|
---|
521 | private javax.swing.JCheckBox cbCtrl;
|
---|
522 | private javax.swing.JCheckBox cbDefault;
|
---|
523 | private javax.swing.JCheckBox cbDisable;
|
---|
524 | private javax.swing.JCheckBox cbMeta;
|
---|
525 | private javax.swing.JCheckBox cbShift;
|
---|
526 | private javax.swing.JPanel editGroupPane;
|
---|
527 | private javax.swing.JPanel hotkeyGroupPane;
|
---|
528 | private javax.swing.JLabel jLabel1;
|
---|
529 | private javax.swing.JLabel jLabel10;
|
---|
530 | private javax.swing.JLabel jLabel11;
|
---|
531 | private javax.swing.JLabel jLabel12;
|
---|
532 | private javax.swing.JLabel jLabel13;
|
---|
533 | private javax.swing.JLabel jLabel14;
|
---|
534 | private javax.swing.JLabel jLabel15;
|
---|
535 | private javax.swing.JLabel jLabel2;
|
---|
536 | private javax.swing.JLabel jLabel3;
|
---|
537 | private javax.swing.JLabel jLabel4;
|
---|
538 | private javax.swing.JLabel jLabel6;
|
---|
539 | private javax.swing.JLabel jLabel7;
|
---|
540 | private javax.swing.JLabel jLabel8;
|
---|
541 | private javax.swing.JLabel jLabel9;
|
---|
542 | private javax.swing.JPanel listPane;
|
---|
543 | private javax.swing.JScrollPane listScrollPane;
|
---|
544 | private javax.swing.JPanel menuGroupPane;
|
---|
545 | private javax.swing.JPanel modifierTab;
|
---|
546 | private javax.swing.JTabbedPane prefTabPane;
|
---|
547 | private javax.swing.JPanel shortcutEditPane;
|
---|
548 | private javax.swing.JPanel shortcutTab;
|
---|
549 | private javax.swing.JTable shortcutTable;
|
---|
550 | private javax.swing.JPanel subwindowGroupPane;
|
---|
551 | private javax.swing.JComboBox tfKey;
|
---|
552 | private javax.swing.JLabel tfKeyLabel;
|
---|
553 | private javax.swing.JPanel infoTab;
|
---|
554 | }
|
---|