Changeset 4916 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2012-02-11T16:28:18+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/PrefJPanel.java
r4914 r4916 15 15 16 16 import java.util.regex.PatternSyntaxException; 17 import javax.swing.*; 17 import javax.swing.AbstractAction; 18 import javax.swing.BorderFactory; 19 import javax.swing.BoxLayout; 20 import javax.swing.DefaultComboBoxModel; 21 import javax.swing.JCheckBox; 22 import javax.swing.JComboBox; 23 import javax.swing.JEditorPane; 24 import javax.swing.JLabel; 25 import javax.swing.JPanel; 26 import javax.swing.JScrollPane; 27 import javax.swing.JTabbedPane; 28 import javax.swing.JTable; 29 import javax.swing.JTextField; 30 import javax.swing.KeyStroke; 31 import javax.swing.ListSelectionModel; 32 import javax.swing.RowFilter; 33 import javax.swing.SwingConstants; 18 34 import javax.swing.event.DocumentEvent; 19 35 import javax.swing.event.DocumentListener; 20 36 import javax.swing.event.ListSelectionEvent; 21 37 import javax.swing.event.ListSelectionListener; 38 import javax.swing.table.AbstractTableModel; 22 39 import javax.swing.table.TableModel; 23 40 … … 34 51 35 52 // table of shortcuts 36 private TableModel model; 53 private AbstractTableModel model; 37 54 // comboboxes of modifier groups, mapping selectedIndex to real data 38 55 private static int[] modifInts = new int[]{ … … 124 141 /** Creates new form prefJPanel */ 125 142 // Ain't those auto-generated comments helpful or what? <g> 126 public PrefJPanel(TableModel model) { 143 public PrefJPanel(AbstractTableModel model) { 127 144 this.model = model; 128 145 initComponents(); … … 130 147 131 148 private void initComponents() { 132 133 // Did I mention auto-generated? That's the reason we134 // have lots of properties here and not some arrays...135 136 // r4914 - autogenerated code rearranged manually137 138 149 JPanel editGroupPane = new JPanel(); 139 150 JPanel hotkeyGroupPane = new JPanel(); … … 191 202 shortcutTable.setModel(model); 192 203 shortcutTable.getSelectionModel().addListSelectionListener(new CbAction(this)); 193 //shortcutTable.setFillsViewportHeight(true);Java 1.6204 shortcutTable.setFillsViewportHeight(true); 194 205 shortcutTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 195 206 shortcutTable.setAutoCreateRowSorter(true); … … 364 375 actionPerformed(null); 365 376 } 377 model.fireTableCellUpdated(row, 1); 366 378 } else { 367 379 panel.disableAllModifierCheckboxes(); … … 375 387 int row = panel.shortcutTable.convertRowIndexToModel(lsm.getMinSelectionIndex()); 376 388 Shortcut sc = (Shortcut)panel.model.getValueAt(row, -1); 377 sc.setAssignedUser(!panel.cbDefault.isSelected());378 389 if (panel.cbDisable.isSelected()) { 379 390 sc.setAssignedModifier(-1); … … 393 404 } 394 405 } 406 sc.setAssignedUser(!panel.cbDefault.isSelected()); 395 407 valueChanged(null); 396 408 } … … 464 476 if (expr.length()==0) { expr=null; } 465 477 try { 466 final TableRowSorter<TableModel> sorter = 467 ((TableRowSorter<TableModel> )shortcutTable.getRowSorter()); 478 final TableRowSorter<? extends TableModel> sorter = 479 ((TableRowSorter<? extends TableModel> )shortcutTable.getRowSorter()); 468 480 if (expr == null) { 469 481 sorter.setRowFilter(null); -
trunk/src/org/openstreetmap/josm/tools/Shortcut.java
r4900 r4916 138 138 */ 139 139 public void setAssignedUser(boolean assignedUser) { 140 this.reset = ( !this.assignedUser&&assignedUser);140 this.reset = (this.assignedUser || reset) && !assignedUser; 141 141 if (assignedUser) { 142 142 assignedDefault = false; 143 } else if (reset) { 144 assignedKey = requestedKey; 145 assignedModifier = findModifier(requestedGroup, null); 143 146 } 144 147 this.assignedUser = assignedUser; … … 172 175 } 173 176 174 private void saveDefault() { 177 private void saveDefault(int modifier) { 175 178 Main.pref.getCollection("shortcut.entry."+shortText, Arrays.asList(new String[]{longText, 176 String.valueOf(requestedKey), String.valueOf(requestedGroup), String.valueOf( assignedKey),177 String.valueOf( assignedModifier), String.valueOf(true), String.valueOf(false)}));179 String.valueOf(requestedKey), String.valueOf(requestedGroup), String.valueOf(requestedKey), 180 String.valueOf(modifier), String.valueOf(true), String.valueOf(false)})); 178 181 } 179 182 180 183 // get a string that can be put into the preferences 181 184 private boolean save() { 182 return Main.pref.putCollection("shortcut.entry."+shortText, Arrays.asList(new String[]{longText, 183 String.valueOf(requestedKey), String.valueOf(requestedGroup), String.valueOf(assignedKey), 184 String.valueOf(assignedModifier), String.valueOf(assignedDefault), String.valueOf(assignedUser)})); 185 if (getAutomatic() || getReset() || !getAssignedUser()) { 186 return Main.pref.putCollection("shortcut.entry."+shortText, null); 187 } else { 188 return Main.pref.putCollection("shortcut.entry."+shortText, Arrays.asList(new String[]{longText, 189 String.valueOf(requestedKey), String.valueOf(requestedGroup), String.valueOf(assignedKey), 190 String.valueOf(assignedModifier), String.valueOf(assignedDefault), String.valueOf(assignedUser)})); 191 } 185 192 } 186 193 … … 347 354 boolean changed = false; 348 355 for (Shortcut sc : shortcuts.values()) { 349 if (!sc.getAutomatic() && !sc.getReset() && sc.getAssignedUser()) { 350 changed = changed | sc.save(); 351 } 356 changed = changed | sc.save(); 352 357 } 353 358 return changed; … … 427 432 } 428 433 434 private static int findModifier(int group, Integer modifier) { 435 Integer defaultModifier = getGroupModifier(group + GROUPS_DEFAULT); 436 if(modifier != null) { 437 if(modifier == SHIFT_DEFAULT) { 438 defaultModifier |= KeyEvent.SHIFT_DOWN_MASK; 439 } else { 440 defaultModifier = modifier; 441 } 442 } 443 else if (defaultModifier == null) { // garbage in, no shortcut out 444 defaultModifier = getGroupModifier(GROUP_NONE + GROUPS_DEFAULT); 445 } 446 return defaultModifier; 447 } 448 429 449 // and now the workhorse. same parameters as above, just one more: if originalShortcut is not null and 430 450 // is different from the shortcut that will be assigned, a popup warning will be displayed to the user. … … 435 455 Shortcut originalShortcut) { 436 456 doInit(); 457 Integer defaultModifier = findModifier(requestedGroup, modifier); 437 458 if (shortcuts.containsKey(shortText)) { // a re-register? maybe a sc already read from the preferences? 438 459 Shortcut sc = shortcuts.get(shortText); 439 460 sc.setLongText(longText); // or set by the platformHook, in this case the original longText doesn't match the real action 461 sc.saveDefault(defaultModifier); 440 462 return sc; 441 }442 Integer defaultModifier = getGroupModifier(requestedGroup + GROUPS_DEFAULT);443 if(modifier != null) {444 if(modifier == SHIFT_DEFAULT) {445 defaultModifier |= KeyEvent.SHIFT_DOWN_MASK;446 } else {447 defaultModifier = modifier;448 }449 }450 else if (defaultModifier == null) { // garbage in, no shortcut out451 defaultModifier = getGroupModifier(GROUP_NONE + GROUPS_DEFAULT);452 463 } 453 464 Shortcut conflictsWith = null; … … 483 494 } 484 495 485 potentialShortcut.saveDefault(); 496 potentialShortcut.saveDefault(defaultModifier); 486 497 shortcuts.put(shortText, potentialShortcut); 487 498 return potentialShortcut;
Note:
See TracChangeset
for help on using the changeset viewer.