Changeset 16843 in josm


Ignore:
Timestamp:
2020-08-03T22:32:16+02:00 (4 years ago)
Author:
simon04
Message:

fix #19574 - Add a color setting for MapCSS (patch by taylor.smock)

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/preferences/NamedColorProperty.java

    r15496 r16843  
    1717 * @since 12987
    1818 */
    19 public class NamedColorProperty extends AbstractProperty<Color> {
     19public class NamedColorProperty extends AbstractToStringProperty<Color> {
    2020
    2121    public static final String NAMED_COLOR_PREFIX = "clr.";
     
    6262    private List<String> getDefaultValuePref() {
    6363        return defaultValue == null ? null : getValuePref(defaultValue, category, source, name);
     64    }
     65
     66    @Override
     67    protected void storeDefaultValue() {
     68        // This is required due to the super() initializer calling this method.
     69        if (category != null) {
     70            super.storeDefaultValue();
     71        }
    6472    }
    6573
     
    137145        return getChildColor(category, source, name);
    138146    }
     147
     148    @Override
     149    protected Color fromString(String string) {
     150        return ColorHelper.html2color(string);
     151    }
     152
     153    @Override
     154    protected String toString(Color color) {
     155        return ColorHelper.color2html(color);
     156    }
    139157}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSetting.java

    r15731 r16843  
    22package org.openstreetmap.josm.gui.mappaint;
    33
     4import java.awt.Color;
    45import java.util.Objects;
    56import java.util.Optional;
     
    176177        }
    177178    }
     179
     180    /**
     181     * A style setting for color values.
     182     * @since 16842
     183     */
     184    class ColorStyleSetting extends PropertyStyleSetting<Color> {
     185        ColorStyleSetting(StyleSource parentStyle, String label, AbstractToStringProperty<Color> property) {
     186            super(parentStyle, label, Color.class, property);
     187        }
     188
     189        @Override
     190        public StyleSettingGui getStyleSettingGui() {
     191            return new ColorStyleSettingGui(this);
     192        }
     193    }
    178194}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSettingFactory.java

    r15731 r16843  
    22package org.openstreetmap.josm.gui.mappaint;
    33
     4import java.awt.Color;
    45import java.util.function.BiFunction;
    56
    67import org.openstreetmap.josm.data.preferences.BooleanProperty;
    78import org.openstreetmap.josm.data.preferences.DoubleProperty;
     9import org.openstreetmap.josm.data.preferences.NamedColorProperty;
    810import org.openstreetmap.josm.data.preferences.StringProperty;
    911import org.openstreetmap.josm.tools.Logging;
     
    4648                    return new StyleSetting.PropertyStyleSetting<>(parentStyle, label, String.class, property);
    4749                });
     50            case "color":
     51                return forLabelAndDefault(c, Color.class, (label, defaultValue) -> {
     52                    final NamedColorProperty property = new NamedColorProperty(NamedColorProperty.COLOR_CATEGORY_MAPPAINT,
     53                            parentStyle.getFileNamePart(), label, defaultValue);
     54                    return new StyleSetting.ColorStyleSetting(parentStyle, label, property);
     55                });
    4856            default:
    4957                Logging.warn("Unknown setting type {0} for style {1}", type, parentStyle.url);
Note: See TracChangeset for help on using the changeset viewer.