Changeset 13543 in josm


Ignore:
Timestamp:
2018-03-19T00:22:20+01:00 (19 months ago)
Author:
Don-vip
Message:

see #15310 - remove deprecated color stuff

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  
    55import static org.openstreetmap.josm.tools.I18n.tr;
    66
    7 import java.awt.Color;
    87import java.io.File;
    98import java.io.IOException;
     
    2827import java.util.concurrent.TimeUnit;
    2928import java.util.function.Predicate;
    30 import java.util.regex.Matcher;
    3129import java.util.regex.Pattern;
    3230import java.util.stream.Stream;
     
    4947import org.openstreetmap.josm.spi.preferences.StringSetting;
    5048import org.openstreetmap.josm.tools.CheckParameterUtil;
    51 import org.openstreetmap.josm.tools.ColorHelper;
    52 import org.openstreetmap.josm.tools.I18n;
    5349import org.openstreetmap.josm.tools.ListenerList;
    5450import org.openstreetmap.josm.tools.Logging;
     
    116112
    117113    /**
    118      * Maps color keys to human readable color name
    119      * @deprecated (since 12987) no longer supported
    120      */
    121     @Deprecated
    122     protected final SortedMap<String, String> colornames = new TreeMap<>();
    123 
    124     /**
    125114     * Indicates whether {@link #init(boolean)} completed successfully.
    126115     * Used to decide whether to write backup preference file in {@link #save()}
     
    153142     * @since 12634
    154143     */
    155     @SuppressWarnings("deprecation")
    156144    public Preferences(Preferences pref) {
    157145        this(pref.dirs);
    158146        settingsMap.putAll(pref.settingsMap);
    159147        defaultsMap.putAll(pref.defaultsMap);
    160         colornames.putAll(pref.colornames);
    161148    }
    162149
     
    440427                        }
    441428                    });
    442         }
    443         return all;
    444     }
    445 
    446     /**
    447      * Gets all known colors (preferences starting with the color prefix)
    448      * @return All colors
    449      * @deprecated (since 12987) replaced by {@link #getAllNamedColors()}
    450      */
    451     @Deprecated
    452     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 colors
    458                 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             }
    468429        }
    469430        return all;
     
    701662
    702663    /**
    703      * only for preferences
    704      * @param o color key
    705      * @return translated color name
    706      * @deprecated (since 12987) no longer supported
    707      */
    708     @Deprecated
    709     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 key
    731      * @param colName The name of the color.
    732      * @since 10824
    733      * @deprecated (since 12987) no longer supported
    734      */
    735     @Deprecated
    736     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 preference
    744      * @param colKey The color name
    745      * @return The color
    746      * @deprecated (since 12989) no longer supported
    747      */
    748     @Deprecated
    749     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 color
    757      * @param colKey The color name
    758      * @param val The color
    759      * @return true if the setting was modified
    760      * @see NamedColorProperty#put(Color)
    761      * @deprecated (since 12987) no longer supported (see {@link NamedColorProperty})
    762      */
    763     @Deprecated
    764     public synchronized boolean putColor(String colKey, Color val) {
    765         return put(COLOR_PREFIX+colKey, val != null ? ColorHelper.color2html(val, true) : null);
    766     }
    767 
    768     /**
    769664     * Set a value for a certain setting. The changed setting is saved to the preference file immediately.
    770665     * 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  
    55import java.util.Arrays;
    66import java.util.List;
    7 import java.util.Optional;
     7
    88import org.openstreetmap.josm.tools.CheckParameterUtil;
    99import org.openstreetmap.josm.tools.ColorHelper;
     
    7272            return ColorHelper.html2color(data.get(0));
    7373        }
    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;
    9175    }
    9276
     
    9579        get(); // trigger migration
    9680        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         }
    11881    }
    11982
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java

    r12990 r13543  
    1313import java.text.Collator;
    1414import java.util.ArrayList;
    15 import java.util.HashMap;
    1615import java.util.List;
    1716import java.util.Map;
     
    3837
    3938import org.openstreetmap.josm.Main;
     39import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    4040import org.openstreetmap.josm.data.preferences.ColorInfo;
    41 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    4241import org.openstreetmap.josm.data.preferences.NamedColorProperty;
    4342import org.openstreetmap.josm.data.validation.Severity;
     
    265264
    266265    /**
    267      * Set the colors to be shown in the preference table. This method creates a table model if
    268      * none exists and overwrites all existing values.
    269      * @param colorMap the map holding the colors
    270      * (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     @Deprecated
    275     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     /**
    281266     * Returns a map with the colors in the table (key = preference key, value = color info).
    282267     * @return a map holding the colors.
     
    284269    public Map<String, ColorInfo> getColors() {
    285270        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     @Deprecated
    294     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;
    300271    }
    301272
Note: See TracChangeset for help on using the changeset viewer.