Ticket #11663: color_property.patch

File color_property.patch, 1.7 KB (added by shinigami, 11 years ago)
  • src/org/openstreetmap/josm/data/preferences/ColorProperty.java

    ### Eclipse Workspace Patch 1.0
    #P JOSM
     
    22package org.openstreetmap.josm.data.preferences;
    33
    44import java.awt.Color;
     5import java.util.HashMap;
    56import java.util.Locale;
     7import java.util.Map;
     8import java.util.regex.Pattern;
    69
    710import org.openstreetmap.josm.Main;
    811import org.openstreetmap.josm.data.Preferences.ColorKey;
     
    3538        return Main.pref.putColor(getColorKey(name), value);
    3639    }
    3740
     41    private static final Map<String, String> XLATED_COLOR_KEYS = new HashMap<String, String>();
     42    private static final Pattern XLATED_COLOR_PATTERN = Pattern.compile("[^a-z0-9]+");
     43
    3844    /**
    3945     * Replies the color key used in JOSM preferences for this property.
    4046     * @param colName The color name
     
    4147     * @return The color key for this property
    4248     */
    4349    public static String getColorKey(String colName) {
    44         return colName == null ? null : colName.toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9]+", ".");
     50
     51        if (colName == null) {
     52            return null;
     53        }
     54
     55        synchronized (XLATED_COLOR_KEYS) {
     56            String xlated = XLATED_COLOR_KEYS.get(colName);
     57            if (xlated == null) {
     58                xlated = XLATED_COLOR_PATTERN.matcher(colName.toLowerCase(Locale.ENGLISH)).replaceAll(".");
     59                XLATED_COLOR_KEYS.put(colName, xlated);
     60            }
     61            return xlated;
     62        }
    4563    }
    4664
    4765    @Override