- Timestamp:
- 2018-03-19T00:22:20+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r13333 r13543 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 7 import java.awt.Color;8 7 import java.io.File; 9 8 import java.io.IOException; … … 28 27 import java.util.concurrent.TimeUnit; 29 28 import java.util.function.Predicate; 30 import java.util.regex.Matcher;31 29 import java.util.regex.Pattern; 32 30 import java.util.stream.Stream; … … 49 47 import org.openstreetmap.josm.spi.preferences.StringSetting; 50 48 import org.openstreetmap.josm.tools.CheckParameterUtil; 51 import org.openstreetmap.josm.tools.ColorHelper;52 import org.openstreetmap.josm.tools.I18n;53 49 import org.openstreetmap.josm.tools.ListenerList; 54 50 import org.openstreetmap.josm.tools.Logging; … … 116 112 117 113 /** 118 * Maps color keys to human readable color name119 * @deprecated (since 12987) no longer supported120 */121 @Deprecated122 protected final SortedMap<String, String> colornames = new TreeMap<>();123 124 /**125 114 * Indicates whether {@link #init(boolean)} completed successfully. 126 115 * Used to decide whether to write backup preference file in {@link #save()} … … 153 142 * @since 12634 154 143 */ 155 @SuppressWarnings("deprecation")156 144 public Preferences(Preferences pref) { 157 145 this(pref.dirs); 158 146 settingsMap.putAll(pref.settingsMap); 159 147 defaultsMap.putAll(pref.defaultsMap); 160 colornames.putAll(pref.colornames);161 148 } 162 149 … … 440 427 } 441 428 }); 442 }443 return all;444 }445 446 /**447 * Gets all known colors (preferences starting with the color prefix)448 * @return All colors449 * @deprecated (since 12987) replaced by {@link #getAllNamedColors()}450 */451 @Deprecated452 public synchronized Map<String, String> getAllColors() {453 final Map<String, String> all = new TreeMap<>();454 for (final Entry<String, Setting<?>> e : defaultsMap.entrySet()) {455 if (e.getKey().startsWith(COLOR_PREFIX) && e.getValue() instanceof StringSetting) {456 if (e.getKey().startsWith(COLOR_PREFIX+"layer."))457 continue; // do not add unchanged layer colors458 StringSetting d = (StringSetting) e.getValue();459 if (d.getValue() != null) {460 all.put(e.getKey().substring(6), d.getValue());461 }462 }463 }464 for (final Entry<String, Setting<?>> e : settingsMap.entrySet()) {465 if (e.getKey().startsWith(COLOR_PREFIX) && (e.getValue() instanceof StringSetting)) {466 all.put(e.getKey().substring(6), ((StringSetting) e.getValue()).getValue());467 }468 429 } 469 430 return all; … … 701 662 702 663 /** 703 * only for preferences704 * @param o color key705 * @return translated color name706 * @deprecated (since 12987) no longer supported707 */708 @Deprecated709 public synchronized String getColorName(String o) {710 Matcher m = COLOR_LAYER_PATTERN.matcher(o);711 if (m.matches()) {712 return tr("Layer: {0}", tr(I18n.escape(m.group(1))));713 }714 String fullKey = COLOR_PREFIX + o;715 if (colornames.containsKey(fullKey)) {716 String name = colornames.get(fullKey);717 Matcher m2 = COLOR_MAPPAINT_PATTERN.matcher(name);718 if (m2.matches()) {719 return tr("Paint style {0}: {1}", tr(I18n.escape(m2.group(1))), tr(I18n.escape(m2.group(2))));720 } else {721 return tr(I18n.escape(colornames.get(fullKey)));722 }723 } else {724 return fullKey;725 }726 }727 728 /**729 * Registers a color name conversion for the global color registry.730 * @param colKey The key731 * @param colName The name of the color.732 * @since 10824733 * @deprecated (since 12987) no longer supported734 */735 @Deprecated736 public void registerColor(String colKey, String colName) {737 if (!colKey.equals(colName)) {738 colornames.put(colKey, colName);739 }740 }741 742 /**743 * Gets the default color that was registered with the preference744 * @param colKey The color name745 * @return The color746 * @deprecated (since 12989) no longer supported747 */748 @Deprecated749 public synchronized Color getDefaultColor(String colKey) {750 StringSetting col = Utils.cast(defaultsMap.get(COLOR_PREFIX+colKey), StringSetting.class);751 String colStr = col == null ? null : col.getValue();752 return colStr == null || colStr.isEmpty() ? null : ColorHelper.html2color(colStr);753 }754 755 /**756 * Stores a color757 * @param colKey The color name758 * @param val The color759 * @return true if the setting was modified760 * @see NamedColorProperty#put(Color)761 * @deprecated (since 12987) no longer supported (see {@link NamedColorProperty})762 */763 @Deprecated764 public synchronized boolean putColor(String colKey, Color val) {765 return put(COLOR_PREFIX+colKey, val != null ? ColorHelper.color2html(val, true) : null);766 }767 768 /**769 664 * Set a value for a certain setting. The changed setting is saved to the preference file immediately. 770 665 * Due to caching mechanisms on modern operating systems and hardware, this shouldn't be a performance problem. -
trunk/src/org/openstreetmap/josm/data/preferences/NamedColorProperty.java
r12987 r13543 5 5 import java.util.Arrays; 6 6 import java.util.List; 7 import java.util.Optional; 7 8 8 import org.openstreetmap.josm.tools.CheckParameterUtil; 9 9 import org.openstreetmap.josm.tools.ColorHelper; … … 72 72 return ColorHelper.html2color(data.get(0)); 73 73 } 74 return Optional.ofNullable(migrate()).orElse(defaultValue); 75 } 76 77 /** 78 * migrate to new color preferences scheme - remove 4 months after {@link ColorProperty} is removed. 79 * @return the old preferences value 80 */ 81 private Color migrate() { 82 String s = getPreferences().get(getOldColorKey(), null); 83 if (s != null) { 84 Color c = ColorHelper.html2color(s); 85 if (c != null) { 86 put(c); 87 return c; 88 } 89 } 90 return null; 74 return defaultValue; 91 75 } 92 76 … … 95 79 get(); // trigger migration 96 80 return super.isSet(); 97 }98 99 @SuppressWarnings("deprecation")100 private String getOldColorKey() {101 switch (category) {102 case COLOR_CATEGORY_MAPPAINT:103 return ColorProperty.getColorKey("mappaint." + (source == null ? "MapCSS" : source) + "." + name);104 case COLOR_CATEGORY_LAYER:105 {106 String k = "layer " + (source == null ? "" : source);107 return ColorProperty.getColorKey(k);108 }109 default:110 {111 String k = name;112 if (source != null) {113 k = source + "." + k;114 }115 return ColorProperty.getColorKey(k);116 }117 }118 81 } 119 82 -
trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java
r12990 r13543 13 13 import java.text.Collator; 14 14 import java.util.ArrayList; 15 import java.util.HashMap;16 15 import java.util.List; 17 16 import java.util.Map; … … 38 37 39 38 import org.openstreetmap.josm.Main; 39 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 40 40 import org.openstreetmap.josm.data.preferences.ColorInfo; 41 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;42 41 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 43 42 import org.openstreetmap.josm.data.validation.Severity; … … 265 264 266 265 /** 267 * Set the colors to be shown in the preference table. This method creates a table model if268 * none exists and overwrites all existing values.269 * @param colorMap the map holding the colors270 * (key = color id (without prefixes, so only <code>background</code>; not <code>color.background</code>),271 * value = html representation of the color.272 * @deprecated (since 12987) replaced by {@link #setColors(java.util.Map)}273 */274 @Deprecated275 public void setColorModel(Map<String, String> colorMap) {276 setColors(colorMap.entrySet().stream().collect(Collectors.toMap(e->e.getKey(), e->277 new ColorInfo(NamedColorProperty.COLOR_CATEGORY_GENERAL, null, e.getKey(), ColorHelper.html2color(e.getValue()), null))));278 }279 280 /**281 266 * Returns a map with the colors in the table (key = preference key, value = color info). 282 267 * @return a map holding the colors. … … 284 269 public Map<String, ColorInfo> getColors() { 285 270 return tableModel.getData().stream().collect(Collectors.toMap(e -> e.key, e -> e.info)); 286 }287 288 /**289 * Returns a map with the colors in the table (key = color name without prefix, value = html color code).290 * @return a map holding the colors.291 * @deprecated replaced by {@link #getColors()}292 */293 @Deprecated294 public Map<String, String> getColorModel() {295 Map<String, String> colorMap = new HashMap<>();296 for (ColorEntry e : tableModel.getData()) {297 colorMap.put(e.key, ColorHelper.color2html(e.getDisplayColor()));298 }299 return colorMap;300 271 } 301 272
Note:
See TracChangeset
for help on using the changeset viewer.