Changeset 12989 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-10-12T19:56:13+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r12987 r12989 1081 1081 * @param colKey The color name 1082 1082 * @return The color 1083 */ 1083 * @deprecated (since 12989) no longer supported 1084 */ 1085 @Deprecated 1084 1086 public synchronized Color getDefaultColor(String colKey) { 1085 1087 StringSetting col = Utils.cast(defaultsMap.get(COLOR_PREFIX+colKey), StringSetting.class); -
trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java
r12987 r12989 31 31 import javax.swing.ListSelectionModel; 32 32 import javax.swing.event.ListSelectionEvent; 33 import javax.swing.event.ListSelectionListener; 34 import javax.swing.event.TableModelEvent; 35 import javax.swing.event.TableModelListener; 33 36 import javax.swing.table.AbstractTableModel; 34 37 import javax.swing.table.DefaultTableCellRenderer; … … 63 66 * @see NamedColorProperty 64 67 */ 65 public class ColorPreference implements SubPreferenceSetting {68 public class ColorPreference implements SubPreferenceSetting, ListSelectionListener, TableModelListener { 66 69 67 70 /** … … 320 323 int sel = colors.getSelectedRow(); 321 324 ColorEntry ce = tableModel.getEntry(sel); 322 Color c = Main.pref.getDefaultColor(ce.key);325 Color c = ce.info.getDefaultValue(); 323 326 if (c != null) { 324 327 colors.setValueAt(c, sel, 1); … … 330 333 for (int i = 0; i < data.size(); ++i) { 331 334 ColorEntry ce = data.get(i); 332 Color c = Main.pref.getDefaultColor(ce.key);335 Color c = ce.info.getDefaultValue(); 333 336 if (c != null) { 334 337 colors.setValueAt(c, i, 1); … … 345 348 defaultSet.setEnabled(false); 346 349 347 colors = new JTable(tableModel) { 348 @Override public void valueChanged(ListSelectionEvent e) { 349 super.valueChanged(e); 350 int sel = getSelectedRow(); 351 remove.setEnabled(sel >= 0 && isRemoveColor(sel)); 352 colorEdit.setEnabled(sel >= 0); 353 defaultSet.setEnabled(sel >= 0); 354 } 355 }; 350 colors = new JTable(tableModel); 356 351 colors.addMouseListener(new MouseAdapter() { 357 352 @Override … … 402 397 colors.setPreferredScrollableViewportSize(new Dimension(100, 112)); 403 398 399 colors.getSelectionModel().addListSelectionListener(this); 400 colors.getModel().addTableModelListener(this); 401 404 402 JPanel panel = new JPanel(new GridBagLayout()); 405 403 panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); … … 417 415 } 418 416 419 Boolean isRemoveColor(int row) {420 return tableModel.getEntry(row).info.getCategory().equals(NamedColorProperty.COLOR_CATEGORY_LAYER);417 private boolean isRemoveColor(ColorEntry ce) { 418 return ce.info.getCategory().equals(NamedColorProperty.COLOR_CATEGORY_LAYER); 421 419 } 422 420 … … 443 441 } 444 442 for (ColorEntry e : tableModel.getData()) { 445 if ( !e.isDefault()) {443 if (e.info.getValue() != null) { 446 444 if (e.toProperty().put(e.info.getValue()) 447 445 && e.key.startsWith("mappaint.")) { … … 463 461 return gui.getDisplayPreference(); 464 462 } 463 464 @Override 465 public void valueChanged(ListSelectionEvent e) { 466 updateEnabledState(); 467 } 468 469 @Override 470 public void tableChanged(TableModelEvent e) { 471 updateEnabledState(); 472 } 473 474 private void updateEnabledState() { 475 int sel = colors.getSelectedRow(); 476 ColorEntry ce = sel >= 0 ? tableModel.getEntry(sel) : null; 477 remove.setEnabled(ce != null && isRemoveColor(ce)); 478 colorEdit.setEnabled(ce != null); 479 defaultSet.setEnabled(ce != null && !ce.isDefault()); 480 } 465 481 }
Note:
See TracChangeset
for help on using the changeset viewer.