- Timestamp:
- 2017-10-12T19:56:13+02:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
- 1 moved
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 } -
trunk/test/unit/org/openstreetmap/josm/data/PreferencesTest.java
r12949 r12989 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertTrue;6 7 import java.awt.Color;8 5 9 6 import org.junit.Rule; 10 7 import org.junit.Test; 11 8 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.data.preferences.ColorProperty;13 9 import org.openstreetmap.josm.testutils.JOSMTestRules; 14 10 … … 28 24 29 25 /** 30 * Test color name.31 */32 @Test33 public void testColorName() {34 assertEquals("Layer: {5DE308C0-916F-4B5A-B3DB-D45E17F30172}.gpx",35 Main.pref.getColorName("layer.{5DE308C0-916F-4B5A-B3DB-D45E17F30172}.gpx"));36 }37 38 /**39 * Test color alpha.40 */41 @Test42 public void testColorAlpha() {43 assertEquals(0x12, new ColorProperty("foo", new Color(0x12345678, true)).get().getAlpha());44 assertTrue(Main.pref.putColor("bar", new Color(0x12345678, true)));45 assertEquals(0x12, new ColorProperty("bar", Color.RED).get().getAlpha());46 }47 48 /**49 * Test color name and alpha.50 */51 @Test52 public void testColorNameAlpha() {53 assertEquals(0x12, new ColorProperty("foo", new Color(0x12345678, true)).get().getAlpha());54 assertEquals(new Color(0x34, 0x56, 0x78, 0x12), Main.pref.getDefaultColor("foo"));55 assertEquals(0x12, Main.pref.getDefaultColor("foo").getAlpha());56 }57 58 /**59 26 * Test {@link Preferences#toXML}. 60 27 */ -
trunk/test/unit/org/openstreetmap/josm/data/preferences/NamedColorPropertyTest.java
r12988 r12989 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertTrue; 5 6 6 7 import java.awt.Color; 8 import java.util.Arrays; 7 9 8 10 import org.junit.Before; 9 11 import org.junit.Rule; 10 12 import org.junit.Test; 13 import org.openstreetmap.josm.Main; 11 14 import org.openstreetmap.josm.spi.preferences.Config; 12 15 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 18 21 * @author Michael Zangl 19 22 */ 20 public class ColorPropertyTest {23 public class NamedColorPropertyTest { 21 24 /** 22 25 * This is a preference test. … … 25 28 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 26 29 public JOSMTestRules test = new JOSMTestRules().preferences(); 27 private ColorProperty base;30 private NamedColorProperty base; 28 31 29 32 /** … … 32 35 @Before 33 36 public void createTestProperty() { 34 base = new ColorProperty("test", Color.RED);37 base = new NamedColorProperty("test", Color.RED); 35 38 } 36 39 … … 41 44 public void testGet() { 42 45 assertEquals(Color.RED, base.get()); 43 44 Config.getPref().put("color.test", "#00ff00");45 assertEquals(new Color(0xff00ff00), base.get());46 46 } 47 47 … … 53 53 assertEquals(Color.RED, base.get()); 54 54 55 base.put(new Color(0xff00 ff00));56 assertEquals(new Color(0xff00 ff00), base.get());57 assertEquals("#00 ff00", Config.getPref().get("color.test").toLowerCase());55 base.put(new Color(0xff00af00)); 56 assertEquals(new Color(0xff00af00), base.get()); 57 assertEquals("#00af00", Config.getPref().getList("clr.general.test").get(0).toLowerCase()); 58 58 59 59 base.put(null); 60 60 assertEquals(Color.RED, base.get()); 61 } 62 63 /** 64 * Test color alpha. 65 */ 66 @Test 67 public void testColorAlpha() { 68 assertEquals(0x12, new NamedColorProperty("foo", new Color(0x12345678, true)).get().getAlpha()); 69 assertTrue(Main.pref.putList("clr.general.bar", Arrays.asList("#34567812", "general", "", "bar"))); 70 assertEquals(0x12, new NamedColorProperty("bar", Color.RED).get().getAlpha()); 71 } 72 73 /** 74 * Test color name and alpha. 75 */ 76 @Test 77 public void testColorNameAlpha() { 78 assertEquals(0x12, new NamedColorProperty("foo", new Color(0x12345678, true)).get().getAlpha()); 61 79 } 62 80 … … 66 84 @Test 67 85 public void testGetChildColor() { 68 Abstract ToStringProperty<Color> child = base.getChildColor("test2");86 AbstractProperty<Color> child = base.getChildColor("test2"); 69 87 70 88 assertEquals(Color.RED, child.get()); -
trunk/test/unit/org/openstreetmap/josm/gui/layer/LayerTest.java
r10900 r12989 16 16 import org.openstreetmap.josm.Main; 17 17 import org.openstreetmap.josm.data.preferences.AbstractProperty; 18 import org.openstreetmap.josm.data.preferences. ColorProperty;18 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 19 19 import org.openstreetmap.josm.testutils.JOSMTestRules; 20 20 … … 52 52 AbstractProperty<Color> color = new LayerManagerTest.TestLayer() { 53 53 @Override 54 protected ColorProperty getBaseColorProperty() {55 return new ColorProperty("x", Color.BLACK);54 protected NamedColorProperty getBaseColorProperty() { 55 return new NamedColorProperty("x", Color.BLACK); 56 56 } 57 57 }.getColorProperty(); … … 101 101 @Override 102 102 public AbstractProperty<Color> getColorProperty() { 103 return new ColorProperty("test", Color.RED);103 return new NamedColorProperty("test", Color.RED); 104 104 } 105 105 };
Note:
See TracChangeset
for help on using the changeset viewer.