Ignore:
Timestamp:
2020-06-10T08:04:42+02:00 (4 years ago)
Author:
simon04
Message:

fix #19197 - MapCSS JOSM_pref: check if a pref could be converted to a color instead of a string (patch by taylor.smock, modified)

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r15719 r16590  
    2121import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon;
    2222import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
     23import org.openstreetmap.josm.data.preferences.NamedColorProperty;
    2324import org.openstreetmap.josm.gui.MainApplication;
    2425import org.openstreetmap.josm.gui.NavigatableComponent;
     
    4041import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
    4142import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
     43import org.openstreetmap.josm.tools.ColorHelper;
    4244import org.openstreetmap.josm.tools.Pair;
    4345
     
    604606     * each primitive can be slow during rendering.
    605607     *
     608     * If the default value can be {@linkplain Cascade#convertTo converted} to a {@link Color},
     609     * the {@link NamedColorProperty} is retrieved as string.
     610     *
     611     * @param source style source
    606612     * @param key preference key
    607613     * @param def default value
     
    609615     * @see org.openstreetmap.josm.data.Preferences#get(String, String)
    610616     */
    611     public String getPreferenceCached(String key, String def) {
     617    public String getPreferenceCached(StyleSource source, String key, String def) {
    612618        String res;
    613619        if (preferenceCache.containsKey(key)) {
    614620            res = preferenceCache.get(key);
    615621        } else {
    616             res = Config.getPref().get(key, null);
     622            Color realDef = Cascade.convertTo(def, Color.class);
     623            if (realDef != null) {
     624                String prefName = source != null ? source.getFileNamePart() : "unknown";
     625                NamedColorProperty property = new NamedColorProperty(NamedColorProperty.COLOR_CATEGORY_MAPPAINT, prefName, key, realDef);
     626                res = ColorHelper.color2html(property.get());
     627            } else {
     628                res = Config.getPref().get(key, null);
     629            }
    617630            preferenceCache.put(key, res);
    618631        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java

    r16553 r16590  
    2828import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
    2929import org.openstreetmap.josm.data.osm.search.SearchParseError;
     30import org.openstreetmap.josm.data.preferences.NamedColorProperty;
    3031import org.openstreetmap.josm.gui.MainApplication;
    3132import org.openstreetmap.josm.gui.mappaint.Cascade;
     
    768769     * Obtains the JOSM'key {@link org.openstreetmap.josm.data.Preferences} string for key {@code key},
    769770     * and defaults to {@code def} if that is null.
     771     *
     772     * If the default value can be {@linkplain Cascade#convertTo converted} to a {@link Color},
     773     * the {@link NamedColorProperty} is retrieved as string.
     774     *
    770775     * @param env the environment
    771776     * @param key Key in JOSM preference
     
    774779     */
    775780    public static String JOSM_pref(Environment env, String key, String def) { // NO_UCD (unused code)
    776         return MapPaintStyles.getStyles().getPreferenceCached(key, def);
     781        return MapPaintStyles.getStyles().getPreferenceCached(env != null ? env.source : null, key, def);
    777782    }
    778783
Note: See TracChangeset for help on using the changeset viewer.