Changeset 12987 in josm
- Timestamp:
- 2017-10-12T16:02:15+02:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/netbeans/nbproject/private/config.properties
r9765 r12987 1 config= local_preferences1 config=pref-clr -
trunk/netbeans/nbproject/project.properties
r12801 r12987 65 65 javac.compilerargs=-Xlint:unchecked -Xlint:cast -Xlint:dep-ann -Xlint:divzero -Xlint:empty -Xlint:finally -Xlint:overrides -Xlint:static -Xlint:try -Xlint:deprecation 66 66 javac.deprecation=true 67 javac.external.vm=false 67 68 javac.processorpath=\ 68 69 ${javac.classpath} -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r12836 r12987 48 48 import org.openstreetmap.josm.data.osm.visitor.paint.ArrowPaintHelper; 49 49 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 50 import org.openstreetmap.josm.data.preferences.Abstract ToStringProperty;50 import org.openstreetmap.josm.data.preferences.AbstractProperty; 51 51 import org.openstreetmap.josm.data.preferences.BooleanProperty; 52 52 import org.openstreetmap.josm.data.preferences.CachingProperty; 53 import org.openstreetmap.josm.data.preferences.ColorProperty;54 53 import org.openstreetmap.josm.data.preferences.DoubleProperty; 54 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 55 55 import org.openstreetmap.josm.data.preferences.StrokeProperty; 56 56 import org.openstreetmap.josm.gui.MainApplication; … … 110 110 111 111 static final CachingProperty<Color> SNAP_HELPER_COLOR 112 = new ColorProperty(marktr("draw angle snap"), Color.ORANGE).cached();112 = new NamedColorProperty(marktr("draw angle snap"), Color.ORANGE).cached(); 113 113 114 114 static final CachingProperty<Color> HIGHLIGHT_COLOR 115 = new ColorProperty(marktr("draw angle snap highlight"), ORANGE_TRANSPARENT).cached();116 117 static final Abstract ToStringProperty<Color> RUBBER_LINE_COLOR115 = new NamedColorProperty(marktr("draw angle snap highlight"), ORANGE_TRANSPARENT).cached(); 116 117 static final AbstractProperty<Color> RUBBER_LINE_COLOR 118 118 = PaintColors.SELECTED.getProperty().getChildColor(marktr("helper line")); 119 119 -
trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
r12846 r12987 45 45 import org.openstreetmap.josm.data.osm.Way; 46 46 import org.openstreetmap.josm.data.osm.WaySegment; 47 import org.openstreetmap.josm.data.preferences. ColorProperty;47 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 48 48 import org.openstreetmap.josm.gui.MainApplication; 49 49 import org.openstreetmap.josm.gui.MainMenu; … … 310 310 initialMoveDelay = Config.getPref().getInt("edit.initial-move-delay", 200); 311 311 initialMoveThreshold = Config.getPref().getInt("extrude.initial-move-threshold", 1); 312 mainColor = new ColorProperty(marktr("Extrude: main line"), Color.RED).get();313 helperColor = new ColorProperty(marktr("Extrude: helper line"), Color.ORANGE).get();312 mainColor = new NamedColorProperty(marktr("Extrude: main line"), Color.RED).get(); 313 helperColor = new NamedColorProperty(marktr("Extrude: helper line"), Color.ORANGE).get(); 314 314 helperStrokeDash = GuiHelper.getCustomizedStroke(Config.getPref().get("extrude.stroke.helper-line", "1 4")); 315 315 helperStrokeRA = new BasicStroke(1); -
trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
r12726 r12987 37 37 import org.openstreetmap.josm.data.osm.WaySegment; 38 38 import org.openstreetmap.josm.data.preferences.CachingProperty; 39 import org.openstreetmap.josm.data.preferences. ColorProperty;39 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 40 40 import org.openstreetmap.josm.data.preferences.IntegerProperty; 41 41 import org.openstreetmap.josm.data.preferences.StrokeProperty; … … 161 161 @Override 162 162 protected void readPreferences() { 163 guideColor = new ColorProperty(marktr("improve way accuracy helper line"), Color.RED).get();163 guideColor = new NamedColorProperty(marktr("improve way accuracy helper line"), Color.RED).get(); 164 164 } 165 165 -
trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java
r12969 r12987 35 35 import org.openstreetmap.josm.data.preferences.BooleanProperty; 36 36 import org.openstreetmap.josm.data.preferences.CachingProperty; 37 import org.openstreetmap.josm.data.preferences. ColorProperty;37 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 38 38 import org.openstreetmap.josm.data.preferences.DoubleProperty; 39 39 import org.openstreetmap.josm.data.preferences.IntegerProperty; … … 105 105 private static final CachingProperty<Double> SNAP_DISTANCE_CHINESE = new DoubleProperty(prefKey("snap-distance-chinese"), 1).cached(); 106 106 private static final CachingProperty<Double> SNAP_DISTANCE_NAUTICAL = new DoubleProperty(prefKey("snap-distance-nautical"), 0.1).cached(); 107 private static final CachingProperty<Color> MAIN_COLOR = new ColorProperty(marktr("make parallel helper line"), Color.RED).cached();107 private static final CachingProperty<Color> MAIN_COLOR = new NamedColorProperty(marktr("make parallel helper line"), Color.RED).cached(); 108 108 109 109 private static final CachingProperty<Map<Modifier, Boolean>> SNAP_MODIFIER_COMBO -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r12982 r12987 43 43 import org.openstreetmap.josm.Main; 44 44 import org.openstreetmap.josm.data.preferences.BooleanProperty; 45 import org.openstreetmap.josm.data.preferences.ColorProperty;46 45 import org.openstreetmap.josm.data.preferences.DoubleProperty; 47 46 import org.openstreetmap.josm.data.preferences.IntegerProperty; 47 import org.openstreetmap.josm.data.preferences.ColorInfo; 48 import org.openstreetmap.josm.data.preferences.LongProperty; 49 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 50 import org.openstreetmap.josm.data.preferences.PreferencesReader; 51 import org.openstreetmap.josm.data.preferences.PreferencesWriter; 52 import org.openstreetmap.josm.spi.preferences.AbstractPreferences; 53 import org.openstreetmap.josm.spi.preferences.IBaseDirectories; 54 import org.openstreetmap.josm.spi.preferences.IPreferences; 48 55 import org.openstreetmap.josm.spi.preferences.ListListSetting; 49 56 import org.openstreetmap.josm.spi.preferences.ListSetting; 50 import org.openstreetmap.josm.data.preferences.LongProperty;51 57 import org.openstreetmap.josm.spi.preferences.MapListSetting; 52 import org.openstreetmap.josm.data.preferences.PreferencesReader;53 import org.openstreetmap.josm.data.preferences.PreferencesWriter;54 58 import org.openstreetmap.josm.spi.preferences.Setting; 55 59 import org.openstreetmap.josm.spi.preferences.StringSetting; 56 60 import org.openstreetmap.josm.io.OfflineAccessException; 57 61 import org.openstreetmap.josm.io.OnlineResource; 58 import org.openstreetmap.josm.spi.preferences.AbstractPreferences;59 import org.openstreetmap.josm.spi.preferences.IBaseDirectories;60 import org.openstreetmap.josm.spi.preferences.IPreferences;61 62 import org.openstreetmap.josm.tools.CheckParameterUtil; 62 63 import org.openstreetmap.josm.tools.ColorHelper; … … 143 144 /** 144 145 * Maps color keys to human readable color name 145 */ 146 * @deprecated (since 12987) no longer supported 147 */ 148 @Deprecated 146 149 protected final SortedMap<String, String> colornames = new TreeMap<>(); 147 150 … … 251 254 * @since 12634 252 255 */ 256 @SuppressWarnings("deprecation") 253 257 public Preferences(Preferences pref) { 254 258 settingsMap.putAll(pref.settingsMap); … … 630 634 631 635 /** 636 * Get all named colors, including customized and the default ones. 637 * @return a map of all named colors (maps preference key to {@link ColorInfo}) 638 */ 639 public synchronized Map<String, ColorInfo> getAllNamedColors() { 640 final Map<String, ColorInfo> all = new TreeMap<>(); 641 for (final Entry<String, Setting<?>> e : settingsMap.entrySet()) { 642 if (!e.getKey().startsWith(NamedColorProperty.NAMED_COLOR_PREFIX)) 643 continue; 644 Utils.instanceOfAndCast(e.getValue(), ListSetting.class) 645 .map(d -> d.getValue()) 646 .map(lst -> ColorInfo.fromPref(lst, false)) 647 .ifPresent(info -> all.put(e.getKey(), info)); 648 } 649 for (final Entry<String, Setting<?>> e : defaultsMap.entrySet()) { 650 if (!e.getKey().startsWith(NamedColorProperty.NAMED_COLOR_PREFIX)) 651 continue; 652 Utils.instanceOfAndCast(e.getValue(), ListSetting.class) 653 .map(d -> d.getValue()) 654 .map(lst -> ColorInfo.fromPref(lst, true)) 655 .ifPresent(infoDef -> { 656 ColorInfo info = all.get(e.getKey()); 657 if (info == null) { 658 all.put(e.getKey(), infoDef); 659 } else { 660 info.setDefaultValue(infoDef.getDefaultValue()); 661 } 662 }); 663 } 664 return all; 665 } 666 667 /** 632 668 * Gets all known colors (preferences starting with the color prefix) 633 669 * @return All colors 634 */ 670 * @deprecated (since 12987) replaced by {@link #getAllNamedColors()} 671 */ 672 @Deprecated 635 673 public synchronized Map<String, String> getAllColors() { 636 674 final Map<String, String> all = new TreeMap<>(); … … 975 1013 } 976 1014 977 /* only for preferences */ 1015 /** 1016 * only for preferences 1017 * @deprecated (since 12987) no longer supported 1018 */ 1019 @Deprecated 978 1020 public synchronized String getColorName(String o) { 979 1021 Matcher m = COLOR_LAYER_PATTERN.matcher(o); … … 1008 1050 @Deprecated 1009 1051 public synchronized Color getColor(String colName, String specName, Color def) { 1010 String colKey = ColorProperty.getColorKey(colName);1052 String colKey = org.openstreetmap.josm.data.preferences.ColorProperty.getColorKey(colName); 1011 1053 registerColor(colKey, colName); 1012 1054 String colStr = specName != null ? get(COLOR_PREFIX+specName) : ""; … … 1026 1068 * @param colName The name of the color. 1027 1069 * @since 10824 1028 */ 1070 * @deprecated (since 12987) no longer supported 1071 */ 1072 @Deprecated 1029 1073 public void registerColor(String colKey, String colName) { 1030 1074 if (!colKey.equals(colName)) { … … 1050 1094 * @return true if the setting was modified 1051 1095 * @see ColorProperty#put(Color) 1052 */ 1096 * @deprecated (since 12987) no longer supported (see {@link NamedColorProperty}) 1097 */ 1098 @Deprecated 1053 1099 public synchronized boolean putColor(String colKey, Color val) { 1054 1100 return put(COLOR_PREFIX+colKey, val != null ? ColorHelper.color2html(val, true) : null); … … 1435 1481 } 1436 1482 1483 @Override 1484 public Set<String> getKeySet() { 1485 return Collections.unmodifiableSet(settingsMap.keySet()); 1486 } 1487 1437 1488 /** 1438 1489 * Gets a map of all settings that are currently stored -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/PaintColors.java
r12966 r12987 7 7 8 8 import org.openstreetmap.josm.data.preferences.CachingProperty; 9 import org.openstreetmap.josm.data.preferences. ColorProperty;9 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 10 10 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 11 11 … … 84 84 private final String name; 85 85 private final Color defaultColor; 86 private final ColorProperty baseProperty;86 private final NamedColorProperty baseProperty; 87 87 private final CachingProperty<Color> property; 88 88 89 89 PaintColors(String name, Color defaultColor) { 90 baseProperty = new ColorProperty(name, defaultColor);90 baseProperty = new NamedColorProperty(name, defaultColor); 91 91 property = baseProperty.cached(); 92 92 this.name = name; … … 123 123 * @since 10874 124 124 */ 125 public ColorProperty getProperty() {125 public NamedColorProperty getProperty() { 126 126 return baseProperty; 127 127 } -
trunk/src/org/openstreetmap/josm/data/preferences/AbstractProperty.java
r12983 r12987 191 191 */ 192 192 public boolean isSet() { 193 return !getPreferences().get(key).isEmpty();193 return getPreferences().getKeySet().contains(key); 194 194 } 195 195 … … 206 206 */ 207 207 public void remove() { 208 put(getDefaultValue());208 getPreferences().put(key, null); 209 209 } 210 210 -
trunk/src/org/openstreetmap/josm/data/preferences/ColorProperty.java
r11542 r12987 11 11 * A property containing a {@link Color} value. 12 12 * @since 5464 13 * @deprecated (since 12987) replaced by {@link NamedColorProperty} 13 14 */ 15 @Deprecated 14 16 public class ColorProperty extends AbstractToStringProperty<Color> { 15 17 -
trunk/src/org/openstreetmap/josm/data/validation/Severity.java
r12667 r12987 7 7 import java.awt.Color; 8 8 9 import org.openstreetmap.josm.data.preferences. ColorProperty;9 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 10 10 import org.openstreetmap.josm.tools.Logging; 11 11 … … 14 14 // CHECKSTYLE.OFF: SingleSpaceSeparator 15 15 /** Error messages */ 16 ERROR(1, tr("Errors"), /* ICON(data/) */"error", new ColorProperty(marktr("validation error"), Color.RED).get()),16 ERROR(1, tr("Errors"), /* ICON(data/) */"error", new NamedColorProperty(marktr("validation error"), Color.RED).get()), 17 17 /** Warning messages */ 18 WARNING(2, tr("Warnings"), /* ICON(data/) */"warning", new ColorProperty(marktr("validation warning"), Color.YELLOW).get()),18 WARNING(2, tr("Warnings"), /* ICON(data/) */"warning", new NamedColorProperty(marktr("validation warning"), Color.YELLOW).get()), 19 19 /** Other messages */ 20 OTHER(3, tr("Other"), /* ICON(data/) */"other", new ColorProperty(marktr("validation other"), Color.CYAN).get());20 OTHER(3, tr("Other"), /* ICON(data/) */"other", new NamedColorProperty(marktr("validation other"), Color.CYAN).get()); 21 21 // CHECKSTYLE.ON: SingleSpaceSeparator 22 22 -
trunk/src/org/openstreetmap/josm/gui/MapScaler.java
r11534 r12987 15 15 import javax.swing.JComponent; 16 16 17 import org.openstreetmap.josm.data.preferences. ColorProperty;17 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 18 18 import org.openstreetmap.josm.gui.help.Helpful; 19 19 … … 29 29 private static final int PADDING_RIGHT = 50; 30 30 31 private static final ColorProperty SCALER_COLOR = newColorProperty(marktr("scale"), Color.WHITE);31 private static final NamedColorProperty SCALER_COLOR = new NamedColorProperty(marktr("scale"), Color.WHITE); 32 32 33 33 /** -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r12881 r12987 71 71 import org.openstreetmap.josm.data.preferences.AbstractProperty; 72 72 import org.openstreetmap.josm.data.preferences.BooleanProperty; 73 import org.openstreetmap.josm.data.preferences.ColorProperty;74 73 import org.openstreetmap.josm.data.preferences.DoubleProperty; 74 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 75 75 import org.openstreetmap.josm.gui.help.Helpful; 76 76 import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor; … … 80 80 import org.openstreetmap.josm.gui.widgets.JosmTextField; 81 81 import org.openstreetmap.josm.spi.preferences.Config; 82 import org.openstreetmap.josm.tools.ColorHelper; 82 83 import org.openstreetmap.josm.tools.Destroyable; 83 84 import org.openstreetmap.josm.tools.GBC; … … 110 111 * @since 6789 111 112 */ 112 public static final ColorProperty PROP_BACKGROUND_COLOR = newColorProperty(113 marktr("Status bar background"), "#b8cfe5");113 public static final NamedColorProperty PROP_BACKGROUND_COLOR = new NamedColorProperty( 114 marktr("Status bar background"), ColorHelper.html2color("#b8cfe5")); 114 115 115 116 /** … … 117 118 * @since 6789 118 119 */ 119 public static final ColorProperty PROP_ACTIVE_BACKGROUND_COLOR = newColorProperty(120 marktr("Status bar background: active"), "#aaff5e");120 public static final NamedColorProperty PROP_ACTIVE_BACKGROUND_COLOR = new NamedColorProperty( 121 marktr("Status bar background: active"), ColorHelper.html2color("#aaff5e")); 121 122 122 123 /** … … 124 125 * @since 6789 125 126 */ 126 public static final ColorProperty PROP_FOREGROUND_COLOR = newColorProperty(127 public static final NamedColorProperty PROP_FOREGROUND_COLOR = new NamedColorProperty( 127 128 marktr("Status bar foreground"), Color.black); 128 129 … … 131 132 * @since 6789 132 133 */ 133 public static final ColorProperty PROP_ACTIVE_FOREGROUND_COLOR = newColorProperty(134 public static final NamedColorProperty PROP_ACTIVE_FOREGROUND_COLOR = new NamedColorProperty( 134 135 marktr("Status bar foreground: active"), Color.black); 135 136 -
trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterButton.java
r12630 r12987 12 12 13 13 import org.openstreetmap.josm.actions.JosmAction; 14 import org.openstreetmap.josm.data.preferences. ColorProperty;14 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 15 15 import org.openstreetmap.josm.gui.MainApplication; 16 16 … … 21 21 public class AutoFilterButton extends JButton { 22 22 23 private static final ColorProperty PROP_COLOR = newColorProperty("auto.filter.button.color", new Color(0, 160, 160));23 private static final NamedColorProperty PROP_COLOR = new NamedColorProperty("auto.filter.button.color", new Color(0, 160, 160)); 24 24 25 25 private final AutoFilter filter; -
trunk/src/org/openstreetmap/josm/gui/conflict/ConflictColors.java
r10824 r12987 6 6 import java.awt.Color; 7 7 8 import org.openstreetmap.josm.data.preferences. ColorProperty;8 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 9 9 10 10 /** … … 82 82 FGCOLOR_MEMBER_REMOVE(marktr("Conflict foreground: remove member"), Color.black); 83 83 84 private final ColorProperty property;84 private final NamedColorProperty property; 85 85 86 86 ConflictColors(String name, Color defaultColor) { 87 property = new ColorProperty(name, defaultColor);87 property = new NamedColorProperty(name, defaultColor); 88 88 } 89 89 -
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r12809 r12987 52 52 import org.openstreetmap.josm.data.osm.Way; 53 53 import org.openstreetmap.josm.data.osm.visitor.OsmPrimitiveVisitor; 54 import org.openstreetmap.josm.data.preferences. ColorProperty;54 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 55 55 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 56 56 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; … … 78 78 public final class ConflictDialog extends ToggleDialog implements ActiveLayerChangeListener, IConflictListener, DataSelectionListener { 79 79 80 private static final ColorProperty CONFLICT_COLOR = newColorProperty(marktr("conflict"), Color.GRAY);81 private static final ColorProperty BACKGROUND_COLOR = newColorProperty(marktr("background"), Color.BLACK);80 private static final NamedColorProperty CONFLICT_COLOR = new NamedColorProperty(marktr("conflict"), Color.GRAY); 81 private static final NamedColorProperty BACKGROUND_COLOR = new NamedColorProperty(marktr("background"), Color.BLACK); 82 82 83 83 /** the collection of conflicts displayed by this conflict dialog */ -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesCellRenderer.java
r11553 r12987 24 24 import org.openstreetmap.josm.data.preferences.BooleanProperty; 25 25 import org.openstreetmap.josm.data.preferences.CachingProperty; 26 import org.openstreetmap.josm.data.preferences. ColorProperty;26 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 27 27 28 28 /** … … 33 33 34 34 private static final CachingProperty<Color> SELECTED_FG 35 = new ColorProperty(marktr("Discardable key: selection Foreground"), Color.GRAY).cached();35 = new NamedColorProperty(marktr("Discardable key: selection Foreground"), Color.GRAY).cached(); 36 36 private static final CachingProperty<Color> SELECTED_BG; 37 37 private static final CachingProperty<Color> NORMAL_FG 38 = new ColorProperty(marktr("Discardable key: foreground"), Color.GRAY).cached();38 = new NamedColorProperty(marktr("Discardable key: foreground"), Color.GRAY).cached(); 39 39 private static final CachingProperty<Color> NORMAL_BG; 40 40 private static final CachingProperty<Boolean> DISCARDABLE … … 42 42 43 43 static { 44 SELECTED_BG = new ColorProperty(marktr("Discardable key: selection Background"),44 SELECTED_BG = new NamedColorProperty(marktr("Discardable key: selection Background"), 45 45 Optional.ofNullable(UIManager.getColor("Table.selectionBackground")).orElse(Color.BLUE)).cached(); 46 NORMAL_BG = new ColorProperty(marktr("Discardable key: background"),46 NORMAL_BG = new NamedColorProperty(marktr("Discardable key: background"), 47 47 Optional.ofNullable(UIManager.getColor("Table.background")).orElse(Color.WHITE)).cached(); 48 48 } -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r12671 r12987 26 26 import org.openstreetmap.josm.data.gpx.GpxTrack; 27 27 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 28 import org.openstreetmap.josm.data.preferences. ColorProperty;28 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 29 29 import org.openstreetmap.josm.data.projection.Projection; 30 30 import org.openstreetmap.josm.gui.MapView; … … 100 100 101 101 @Override 102 protected ColorProperty getBaseColorProperty() {102 protected NamedColorProperty getBaseColorProperty() { 103 103 return GpxDrawHelper.DEFAULT_COLOR; 104 104 } -
trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
r12782 r12987 29 29 import org.openstreetmap.josm.data.preferences.AbstractProperty; 30 30 import org.openstreetmap.josm.data.preferences.AbstractProperty.ValueChangeListener; 31 import org.openstreetmap.josm.data.preferences. ColorProperty;31 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 32 32 import org.openstreetmap.josm.data.projection.Projection; 33 33 import org.openstreetmap.josm.data.projection.ProjectionChangeListener; … … 204 204 */ 205 205 public AbstractProperty<Color> getColorProperty() { 206 ColorProperty base = getBaseColorProperty();206 NamedColorProperty base = getBaseColorProperty(); 207 207 if (base != null) { 208 // cannot cache this - name may change. 209 return base.getChildColor("layer " + getName()); 208 return base.getChildColor(NamedColorProperty.COLOR_CATEGORY_LAYER, getName(), base.getName()); 210 209 } else { 211 210 return null; … … 218 217 * @since 10824 219 218 */ 220 protected ColorProperty getBaseColorProperty() {219 protected NamedColorProperty getBaseColorProperty() { 221 220 return null; 222 221 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r12846 r12987 81 81 import org.openstreetmap.josm.data.osm.visitor.paint.Rendering; 82 82 import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; 83 import org.openstreetmap.josm.data.preferences.ColorProperty;84 83 import org.openstreetmap.josm.data.preferences.IntegerProperty; 84 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 85 85 import org.openstreetmap.josm.data.preferences.StringProperty; 86 86 import org.openstreetmap.josm.data.projection.Projection; … … 153 153 public static final StringProperty PROPERTY_SAVE_EXTENSION = new StringProperty("save.extension.osm", "osm"); 154 154 155 private static final ColorProperty PROPERTY_BACKGROUND_COLOR = newColorProperty(marktr("background"), Color.BLACK);156 private static final ColorProperty PROPERTY_OUTSIDE_COLOR = newColorProperty(marktr("outside downloaded area"), Color.YELLOW);155 private static final NamedColorProperty PROPERTY_BACKGROUND_COLOR = new NamedColorProperty(marktr("background"), Color.BLACK); 156 private static final NamedColorProperty PROPERTY_OUTSIDE_COLOR = new NamedColorProperty(marktr("outside downloaded area"), Color.YELLOW); 157 157 158 158 /** List of recent relations */ -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
r12891 r12987 43 43 import org.openstreetmap.josm.data.gpx.GpxData.GpxDataChangeListener; 44 44 import org.openstreetmap.josm.data.gpx.WayPoint; 45 import org.openstreetmap.josm.data.preferences. ColorProperty;45 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 46 46 import org.openstreetmap.josm.gui.MapView; 47 47 import org.openstreetmap.josm.gui.MapViewState; … … 69 69 * @since 10824 70 70 */ 71 public static final ColorProperty DEFAULT_COLOR = newColorProperty(marktr("gps point"), Color.magenta);71 public static final NamedColorProperty DEFAULT_COLOR = new NamedColorProperty(marktr("gps point"), Color.magenta); 72 72 73 73 private final GpxData data; … … 266 266 public Color getColor(String layerName, boolean ignoreCustom) { 267 267 if (ignoreCustom || getColorMode(layerName) == ColorMode.NONE) { 268 return DEFAULT_COLOR.getChildColor(specName(layerName)).get(); 268 return DEFAULT_COLOR.getChildColor( 269 NamedColorProperty.COLOR_CATEGORY_LAYER, 270 layerName, 271 DEFAULT_COLOR.getName()).get(); 269 272 } else { 270 273 return null; -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r12846 r12987 38 38 import org.openstreetmap.josm.data.gpx.WayPoint; 39 39 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 40 import org.openstreetmap.josm.data.preferences. ColorProperty;40 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 41 41 import org.openstreetmap.josm.gui.MainApplication; 42 42 import org.openstreetmap.josm.gui.MapView; … … 79 79 80 80 private static final Color DEFAULT_COLOR = Color.magenta; 81 private static final ColorProperty COLOR_PROPERTY = newColorProperty(marktr("gps marker"), DEFAULT_COLOR);81 private static final NamedColorProperty COLOR_PROPERTY = new NamedColorProperty(marktr("gps marker"), DEFAULT_COLOR); 82 82 83 83 /** … … 163 163 164 164 @Override 165 protected ColorProperty getBaseColorProperty() {165 protected NamedColorProperty getBaseColorProperty() { 166 166 return COLOR_PROPERTY; 167 167 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r12620 r12987 18 18 import java.util.Locale; 19 19 20 import org.openstreetmap.josm.data.preferences. ColorProperty;20 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 21 21 import org.openstreetmap.josm.gui.mappaint.Keyword; 22 22 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition; … … 1134 1134 LOOKAHEAD(2) 1135 1135 pref=ident() t=<HEXCOLOR> 1136 { return new ColorProperty("mappaint." + (sheet == null ? "MapCSS" : sheet.title) + "." + pref, t.image).get(); } 1136 { 1137 return new NamedColorProperty( 1138 NamedColorProperty.COLOR_CATEGORY_MAPPAINT, 1139 sheet == null ? "MapCSS" : sheet.title, pref, 1140 ColorHelper.html2color(t.image)).get(); 1141 } 1137 1142 | 1138 1143 t=<IDENT> { return new Keyword(t.image); } -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/PreferencesTable.java
r12881 r12987 29 29 import javax.swing.table.DefaultTableModel; 30 30 31 import org.openstreetmap.josm.data.preferences. ColorProperty;31 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 32 32 import org.openstreetmap.josm.spi.preferences.ListListSetting; 33 33 import org.openstreetmap.josm.spi.preferences.ListSetting; … … 336 336 static final class SettingCellRenderer extends DefaultTableCellRenderer { 337 337 private final Color backgroundColor = UIManager.getColor("Table.background"); 338 private final Color changedColor = new ColorProperty(338 private final Color changedColor = new NamedColorProperty( 339 339 marktr("Advanced Background: Changed"), 340 340 new Color(200, 255, 200)).get(); 341 private final Color nonDefaultColor = new ColorProperty(341 private final Color nonDefaultColor = new NamedColorProperty( 342 342 marktr("Advanced Background: NonDefault"), 343 343 new Color(255, 255, 200)).get(); -
trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java
r12959 r12987 13 13 import java.text.Collator; 14 14 import java.util.ArrayList; 15 import java.util.Collections;16 15 import java.util.HashMap; 17 16 import java.util.List; 18 17 import java.util.Map; 19 18 import java.util.Objects; 19 import java.util.Optional; 20 import java.util.stream.Collectors; 20 21 21 22 import javax.swing.BorderFactory; … … 34 35 35 36 import org.openstreetmap.josm.Main; 37 import org.openstreetmap.josm.data.preferences.ColorInfo; 36 38 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 39 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 37 40 import org.openstreetmap.josm.data.validation.Severity; 38 41 import org.openstreetmap.josm.gui.MapScaler; … … 52 55 import org.openstreetmap.josm.tools.ColorHelper; 53 56 import org.openstreetmap.josm.tools.GBC; 54 import org.openstreetmap.josm.tools. Logging;57 import org.openstreetmap.josm.tools.I18n; 55 58 56 59 /** 57 60 * Color preferences. 61 * 62 * GUI preference to let the user customize named colors. 63 * @see NamedColorProperty 58 64 */ 59 65 public class ColorPreference implements SubPreferenceSetting { … … 78 84 private static class ColorEntry { 79 85 String key; 80 Color color;81 82 ColorEntry(String key, String colorHtml) {86 ColorInfo info; 87 88 ColorEntry(String key, ColorInfo info) { 83 89 CheckParameterUtil.ensureParameterNotNull(key, "key"); 90 CheckParameterUtil.ensureParameterNotNull(info, "info"); 84 91 this.key = key; 85 this.color = ColorHelper.html2color(colorHtml); 86 if (this.color == null) { 87 Logging.warn("Unable to get color from '"+colorHtml+"' for color preference '"+key+'\''); 88 } 89 } 90 92 this.info = info; 93 } 94 95 /** 96 * Get a description of the color based on the given info. 97 * @return a description of the color 98 */ 91 99 public String getDisplay() { 92 return Main.pref.getColorName(key); 100 switch (info.getCategory()) { 101 case NamedColorProperty.COLOR_CATEGORY_LAYER: 102 String v = null; 103 if (info.getSource() != null) { 104 v = info.getSource(); 105 } 106 if (!info.getName().isEmpty()) { 107 if (v == null) { 108 v = tr(I18n.escape(info.getName())); 109 } else { 110 v += " - " + tr(I18n.escape(info.getName())); 111 } 112 } 113 return tr("Layer: {0}", v); 114 case NamedColorProperty.COLOR_CATEGORY_MAPPAINT: 115 if (info.getSource() != null) 116 return tr("Paint style {0}: {1}", tr(I18n.escape(info.getSource())), tr(info.getName())); 117 // fall through 118 default: 119 if (info.getSource() != null) 120 return tr(I18n.escape(info.getSource())) + " - " + tr(I18n.escape(info.getName())); 121 else 122 return tr(I18n.escape(info.getName())); 123 } 124 } 125 126 /** 127 * Get the color value to display. 128 * Either value (if set) or default value. 129 * @return the color value to display 130 */ 131 public Color getDisplayColor() { 132 return Optional.ofNullable(info.getValue()).orElse(info.getDefaultValue()); 133 } 134 135 /** 136 * Check if color has been customized by the user or not. 137 * @return true if the color is at its default value, false if it is customized by the user. 138 */ 139 public boolean isDefault() { 140 return info.getValue() == null || Objects.equals(info.getValue(), info.getDefaultValue()); 141 } 142 143 /** 144 * Convert to a {@link NamedColorProperty}. 145 * @return a {@link NamedColorProperty} 146 */ 147 public NamedColorProperty toProperty() { 148 return new NamedColorProperty(info.getCategory(), info.getSource(), 149 info.getName(), info.getDefaultValue()); 93 150 } 94 151 } … … 143 200 @Override 144 201 public Object getValueAt(int rowIndex, int columnIndex) { 145 return columnIndex == 0 ? data.get(rowIndex) : data.get(rowIndex). color;202 return columnIndex == 0 ? data.get(rowIndex) : data.get(rowIndex).getDisplayColor(); 146 203 } 147 204 … … 159 216 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 160 217 if (columnIndex == 1 && aValue instanceof Color) { 161 data.get(rowIndex). color = (Color) aValue;218 data.get(rowIndex).info.setValue((Color) aValue); 162 219 fireTableRowsUpdated(rowIndex, rowIndex); 163 220 } 221 } 222 } 223 224 /** 225 * Set the colors to be shown in the preference table. This method creates a table model if 226 * none exists and overwrites all existing values. 227 * @param colorMap the map holding the colors 228 * (key = preference key, value = {@link ColorInfo} instance) 229 */ 230 public void setColors(Map<String, ColorInfo> colorMap) { 231 if (tableModel == null) { 232 tableModel = new ColorTableModel(); 233 } 234 tableModel.clear(); 235 236 // fill model with colors: 237 colorMap.entrySet().stream() 238 .map(e -> new ColorEntry(e.getKey(), e.getValue())) 239 .sorted((e1, e2) -> { 240 int cat = Integer.compare( 241 getCategroyPriority(e1.info.getCategory()), 242 getCategroyPriority(e2.info.getCategory())); 243 if (cat != 0) return cat; 244 return Collator.getInstance().compare(e1.getDisplay(), e2.getDisplay()); 245 }) 246 .forEach(tableModel::addEntry); 247 248 if (this.colors != null) { 249 this.colors.repaint(); 250 } 251 252 } 253 254 private static int getCategroyPriority(String category) { 255 switch (category) { 256 case NamedColorProperty.COLOR_CATEGORY_GENERAL: return 1; 257 case NamedColorProperty.COLOR_CATEGORY_MAPPAINT: return 2; 258 case NamedColorProperty.COLOR_CATEGORY_LAYER: return 3; 259 default: return 4; 164 260 } 165 261 } … … 171 267 * (key = color id (without prefixes, so only <code>background</code>; not <code>color.background</code>), 172 268 * value = html representation of the color. 173 */ 269 * @deprecated (since 12987) replaced by {@link #setColors(java.util.Map)} 270 */ 271 @Deprecated 174 272 public void setColorModel(Map<String, String> colorMap) { 175 if (tableModel == null) { 176 tableModel = new ColorTableModel(); 177 } 178 179 tableModel.clear(); 180 // fill model with colors: 181 List<ColorEntry> colorKeyList = new ArrayList<>(); 182 List<ColorEntry> colorKeyListMappaint = new ArrayList<>(); 183 List<ColorEntry> colorKeyListLayer = new ArrayList<>(); 184 for (Map.Entry<String, String> e : colorMap.entrySet()) { 185 String key = e.getKey(); 186 String html = e.getValue(); 187 if (key.startsWith("layer.")) { 188 colorKeyListLayer.add(new ColorEntry(key, html)); 189 } else if (key.startsWith("mappaint.")) { 190 colorKeyListMappaint.add(new ColorEntry(key, html)); 191 } else { 192 colorKeyList.add(new ColorEntry(key, html)); 193 } 194 } 195 addColorRows(colorKeyList); 196 addColorRows(colorKeyListMappaint); 197 addColorRows(colorKeyListLayer); 198 if (this.colors != null) { 199 this.colors.repaint(); 200 } 201 } 202 203 private void addColorRows(List<ColorEntry> entries) { 204 Collections.sort(entries, (e1, e2) -> Collator.getInstance().compare(e1.getDisplay(), e2.getDisplay())); 205 entries.forEach(tableModel::addEntry); 273 setColors(colorMap.entrySet().stream().collect(Collectors.toMap(e->e.getKey(), e-> 274 new ColorInfo(NamedColorProperty.COLOR_CATEGORY_GENERAL, null, e.getKey(), ColorHelper.html2color(e.getValue()), null)))); 275 } 276 277 /** 278 * Returns a map with the colors in the table (key = preference key, value = color info). 279 * @return a map holding the colors. 280 */ 281 public Map<String, ColorInfo> getColors() { 282 return tableModel.getData().stream().collect(Collectors.toMap(e -> e.key, e -> e.info)); 206 283 } 207 284 … … 209 286 * Returns a map with the colors in the table (key = color name without prefix, value = html color code). 210 287 * @return a map holding the colors. 211 */ 288 * @deprecated replaced by {@link #getColors()} 289 */ 290 @Deprecated 212 291 public Map<String, String> getColorModel() { 213 292 Map<String, String> colorMap = new HashMap<>(); 214 293 for (ColorEntry e : tableModel.getData()) { 215 colorMap.put(e.key, ColorHelper.color2html(e. color));294 colorMap.put(e.key, ColorHelper.color2html(e.getDisplayColor())); 216 295 } 217 296 return colorMap; … … 221 300 public void addGui(final PreferenceTabbedPane gui) { 222 301 fixColorPrefixes(); 223 setColor Model(Main.pref.getAllColors());302 setColors(Main.pref.getAllNamedColors()); 224 303 225 304 colorEdit = new JButton(tr("Choose")); … … 227 306 int sel = colors.getSelectedRow(); 228 307 ColorEntry ce = tableModel.getEntry(sel); 229 JColorChooser chooser = new JColorChooser(ce. color);308 JColorChooser chooser = new JColorChooser(ce.getDisplayColor()); 230 309 int answer = JOptionPane.showConfirmDialog( 231 310 gui, chooser, … … 293 372 ColorEntry e = (ColorEntry) value; 294 373 label.setText(e.getDisplay()); 295 if (! Objects.equals(e.color, Main.pref.getDefaultColor(e.key))) {374 if (!e.isDefault()) { 296 375 label.setFont(label.getFont().deriveFont(Font.BOLD)); 297 376 } else { … … 339 418 340 419 Boolean isRemoveColor(int row) { 341 return tableModel.getEntry(row). key.startsWith("layer.");420 return tableModel.getEntry(row).info.getCategory().equals(NamedColorProperty.COLOR_CATEGORY_LAYER); 342 421 } 343 422 … … 361 440 boolean ret = false; 362 441 for (ColorEntry d : tableModel.getDeleted()) { 363 Main.pref.putColor(d.key, null);442 d.toProperty().remove(); 364 443 } 365 444 for (ColorEntry e : tableModel.getData()) { 366 if (Main.pref.putColor(e.key, e.color) && e.key.startsWith("mappaint.")) { 367 ret = true; 445 if (!e.isDefault()) { 446 if (e.toProperty().put(e.info.getValue()) 447 && e.key.startsWith("mappaint.")) { 448 ret = true; 449 } 368 450 } 369 451 } -
trunk/src/org/openstreetmap/josm/gui/preferences/display/GPXSettingsPanel.java
r12896 r12987 26 26 import org.openstreetmap.josm.actions.ExpertToggleAction; 27 27 import org.openstreetmap.josm.data.PreferencesUtils; 28 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 28 29 import org.openstreetmap.josm.gui.layer.gpx.GpxDrawHelper; 29 30 import org.openstreetmap.josm.gui.layer.markerlayer.Marker; … … 329 330 // ask the GPX draw for the correct color of that layer ( if there is one ) 330 331 if (null != layerName) { 331 color = GpxDrawHelper.DEFAULT_COLOR.getChildColor(layerName).get(); 332 color = GpxDrawHelper.DEFAULT_COLOR.getChildColor( 333 NamedColorProperty.COLOR_CATEGORY_LAYER, layerName, GpxDrawHelper.DEFAULT_COLOR.getName()).get(); 332 334 } else { 333 335 color = GpxDrawHelper.DEFAULT_COLOR.getDefaultValue(); -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java
r12643 r12987 60 60 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 61 61 import org.openstreetmap.josm.data.imagery.Shape; 62 import org.openstreetmap.josm.data.preferences. ColorProperty;62 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 63 63 import org.openstreetmap.josm.gui.MainApplication; 64 64 import org.openstreetmap.josm.gui.download.DownloadDialog; … … 248 248 private static class ImageryURLTableCellRenderer extends DefaultTableCellRenderer { 249 249 250 private static final ColorProperty IMAGERY_BACKGROUND_COLOR = newColorProperty(250 private static final NamedColorProperty IMAGERY_BACKGROUND_COLOR = new NamedColorProperty( 251 251 marktr("Imagery Background: Default"), 252 252 new Color(200, 255, 200)); -
trunk/src/org/openstreetmap/josm/gui/preferences/shortcut/PrefJPanel.java
r12620 r12987 45 45 import javax.swing.table.TableRowSorter; 46 46 47 import org.openstreetmap.josm.data.preferences. ColorProperty;47 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 48 48 import org.openstreetmap.josm.gui.util.GuiHelper; 49 49 import org.openstreetmap.josm.gui.widgets.JosmComboBox; … … 160 160 private class ShortcutTableCellRenderer extends DefaultTableCellRenderer { 161 161 162 private final transient ColorProperty SHORTCUT_BACKGROUND_USER_COLOR = newColorProperty(162 private final transient NamedColorProperty SHORTCUT_BACKGROUND_USER_COLOR = new NamedColorProperty( 163 163 marktr("Shortcut Background: User"), 164 164 new Color(200, 255, 200)); 165 private final transient ColorProperty SHORTCUT_BACKGROUND_MODIFIED_COLOR = newColorProperty(165 private final transient NamedColorProperty SHORTCUT_BACKGROUND_MODIFIED_COLOR = new NamedColorProperty( 166 166 marktr("Shortcut Background: Modified"), 167 167 new Color(255, 255, 200)); -
trunk/src/org/openstreetmap/josm/spi/preferences/IPreferences.java
r12881 r12987 5 5 import java.util.List; 6 6 import java.util.Map; 7 import java.util.Set; 7 8 8 9 /** … … 234 235 boolean putListOfMaps(String key, List<Map<String, String>> value); 235 236 237 /** 238 * Get the set of all keys that are mapped to a value in this preferences. 239 * @return the set of all keys 240 */ 241 Set<String> getKeySet(); 236 242 } -
trunk/src/org/openstreetmap/josm/spi/preferences/ListSetting.java
r12882 r12987 37 37 private void consistencyTest() { 38 38 if (value != null && value.contains(null)) 39 throw new IllegalArgumentException("Error: Null as list element in preference setting ");39 throw new IllegalArgumentException("Error: Null as list element in preference setting: " + value); 40 40 } 41 41 -
trunk/src/org/openstreetmap/josm/spi/preferences/MemoryPreferences.java
r12906 r12987 2 2 package org.openstreetmap.josm.spi.preferences; 3 3 4 import java.util.Collections; 4 5 import java.util.HashMap; 5 6 import java.util.Map; 6 7 import java.util.Objects; 8 import java.util.Set; 7 9 8 10 /** … … 41 43 42 44 @Override 45 public Set<String> getKeySet() { 46 return Collections.unmodifiableSet(settings.keySet()); 47 } 48 49 @Override 43 50 public void addPreferenceChangeListener(PreferenceChangedListener listener) { 44 51 // do nothing -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r12854 r12987 45 45 import java.util.List; 46 46 import java.util.Locale; 47 import java.util.Optional; 47 48 import java.util.concurrent.ExecutionException; 48 49 import java.util.concurrent.Executor; … … 1731 1732 } 1732 1733 } 1734 1735 /** 1736 * Helper method to replace the "<code>instanceof</code>-check and cast" pattern. 1737 * 1738 * @param <T> the type for the instanceof check and cast 1739 * @param o the object to check and cast 1740 * @param klass the class T 1741 * @return {@link Optional} containing the result of the cast, if it is possible, an empty 1742 * Optional otherwise 1743 */ 1744 @SuppressWarnings("unchecked") 1745 public static <T> Optional<T> instanceOfAndCast(Object o, Class<T> klass) { 1746 if (klass.isInstance(o)) 1747 return Optional.of((T) o); 1748 return Optional.empty(); 1749 } 1750 1733 1751 }
Note:
See TracChangeset
for help on using the changeset viewer.