Ticket #19819: JOSM-NamedColor-from-Laf.diff

File JOSM-NamedColor-from-Laf.diff, 1.5 KB (added by DevCharly, 5 years ago)

allow class NamedColorProperty to get a default color from the current look and feel

  • src/org/openstreetmap/josm/data/preferences/NamedColorProperty.java

     
    55import java.util.Arrays;
    66import java.util.List;
    77
     8import javax.swing.UIManager;
     9
    810import org.openstreetmap.josm.tools.CheckParameterUtil;
    911import org.openstreetmap.josm.tools.ColorHelper;
    1012
     
    3638     * @param defaultValue the default value, can be null
    3739     */
    3840    public NamedColorProperty(String category, String source, String name, Color defaultValue) {
    39         super(getKey(category, source, name), defaultValue);
     41        super(getKey(category, source, name), getUIColor("JOSM." + getKey(category, source, name), defaultValue));
    4042        CheckParameterUtil.ensureParameterNotNull(category, "category");
    4143        CheckParameterUtil.ensureParameterNotNull(name, "name");
    4244        this.category = category;
     
    5961        return NAMED_COLOR_PREFIX + category + "." + (source == null ? "" : source + ".") + name;
    6062    }
    6163
     64    private static Color getUIColor(String uiKey, Color defaultValue) {
     65        Color color = UIManager.getColor(uiKey);
     66        return (color != null) ? color : defaultValue;
     67    }
     68
    6269    private List<String> getDefaultValuePref() {
    6370        return defaultValue == null ? null : getValuePref(defaultValue, category, source, name);
    6471    }