Ignore:
Timestamp:
2012-08-20T23:06:41+02:00 (12 years ago)
Author:
Don-vip
Message:

Rework Properties a bit to simplify management of Color properties

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    r5462 r5464  
    3535import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    3636import org.openstreetmap.josm.data.imagery.OffsetBookmark;
     37import org.openstreetmap.josm.data.preferences.ColorProperty;
    3738import org.openstreetmap.josm.data.preferences.IntegerProperty;
    3839import org.openstreetmap.josm.gui.MenuScroller;
     
    4344public abstract class ImageryLayer extends Layer {
    4445
     46    public static final ColorProperty PROP_FADE_COLOR = new ColorProperty(marktr("Imagery fade"), Color.white);
    4547    public static final IntegerProperty PROP_FADE_AMOUNT = new IntegerProperty("imagery.fade_amount", 0);
    4648    public static final IntegerProperty PROP_SHARPEN_LEVEL = new IntegerProperty("imagery.sharpen_level", 0);
    4749
    4850    public static Color getFadeColor() {
    49         return Main.pref.getColor(marktr("Imagery fade"), Color.white);
     51        return PROP_FADE_COLOR.get();
    5052    }
    5153
    5254    public static Color getFadeColorWithAlpha() {
    53         Color c = getFadeColor();
     55        Color c = PROP_FADE_COLOR.get();
    5456        return new Color(c.getRed(),c.getGreen(),c.getBlue(),PROP_FADE_AMOUNT.get()*255/100);
    55     }
    56 
    57     public static void setFadeColor(Color color) {
    58         Main.pref.putColor("imagery.fade", color);
    5957    }
    6058
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r4869 r5464  
    102102            TemplateEntryProperty result = cache.get(key);
    103103            if (result == null) {
    104                 String defaultValue = layerName == null?getDefaultLabelPattern():"";
    105                 TemplateEntryProperty parent = layerName == null?null:forMarker(null);
    106                 result = new TemplateEntryProperty(key, defaultValue, parent);
    107                 cache.put(key, result);
     104                String defaultValue = layerName == null ? getDefaultLabelPattern():"";
     105                TemplateEntryProperty parent = layerName == null ? null : forMarker(null);
     106                try {
     107                    result = new TemplateEntryProperty(key, defaultValue, parent);
     108                    cache.put(key, result);
     109                } catch (ParseError e) {
     110                    System.out.println(String.format("Unable to parse template engine pattern '%s' for property %s", defaultValue, key));
     111                }
    108112            }
    109113            return result;
     
    118122            if (result == null) {
    119123                String defaultValue = layerName == null?"?{ '{name}' | '{desc}' | '{" + Marker.MARKER_FORMATTED_OFFSET + "}' }":"";
    120                 TemplateEntryProperty parent = layerName == null?null:forAudioMarker(null);
    121                 result = new TemplateEntryProperty(key, defaultValue, parent);
    122                 cache.put(key, result);
     124                TemplateEntryProperty parent = layerName == null ? null : forAudioMarker(null);
     125                try {
     126                    result = new TemplateEntryProperty(key, defaultValue, parent);
     127                    cache.put(key, result);
     128                } catch (ParseError e) {
     129                    System.out.println(String.format("Unable to parse template engine pattern '%s' for property %s", defaultValue, key));
     130                }
    123131            }
    124132            return result;
     
    128136
    129137
    130         private TemplateEntryProperty(String key, String defaultValue, TemplateEntryProperty parent) {
    131             super(key, defaultValue);
     138        private TemplateEntryProperty(String key, String defaultValue, TemplateEntryProperty parent) throws ParseError {
     139            super(key, new TemplateParser(defaultValue).parse(), defaultValue);
    132140            this.parent = parent;
    133141            updateValue(); // Needs to be called because parent wasn't know in super constructor
     
    140148            } catch (ParseError e) {
    141149                System.out.println(String.format("Unable to parse template engine pattern '%s' for property %s. Using default ('%s') instead",
    142                         s, getKey(), defaultValue));
     150                        s, getKey(), super.getDefaultValueAsString()));
    143151                return getDefaultValue();
    144152            }
Note: See TracChangeset for help on using the changeset viewer.