Changeset 3903 in josm


Ignore:
Timestamp:
2011-02-15T12:02:25+01:00 (13 years ago)
Author:
bastiK
Message:

mapcss: minor fixes

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

Legend:

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

    r3893 r3903  
    7575            return (T) toBool(o);
    7676
    77         if (klass == float[].class) {
     77        if (klass == float[].class)
    7878            return (T) toFloatArray(o);
    79         }
    8079
    81         if (klass == Color.class) {
     80        if (klass == Color.class)
    8281            return (T) toColor(o);
    83         }
     82
     83        if (klass == String.class)
     84            return (T) o.toString();
     85
    8486        return null;
    8587    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java

    r3899 r3903  
    3636        Float width = c.get(key, null, Float.class, true);
    3737        if (width != null) {
    38             if (width == -1f)
    39                 return (float) MapPaintSettings.INSTANCE.getDefaultSegmentWidth();
    4038            if (width > 0)
    4139                return width;
     
    4442            if (equal(width_key, "thinnest"))
    4543                return 0f;
     44            else if(equal(width_key, "default"))
     45                return (float) MapPaintSettings.INSTANCE.getDefaultSegmentWidth();
    4646            else if (relativeTo != null) {
    4747                RelativeFloat width_rel = c.get(key, null, RelativeFloat.class, true);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r3893 r3903  
    229229                addIfNotNull(sl, LineElemStyle.createCasing(env));
    230230            } else if (osm instanceof Node) {
    231                 addIfNotNull(sl, NodeElemStyle.create(c));
     231                addIfNotNull(sl, NodeElemStyle.create(env));
    232232            } else if (osm instanceof Relation) {
    233233                if (((Relation)osm).isMultipolygon()) {
     
    236236                    addIfNotNull(sl, LineElemStyle.createCasing(env));
    237237                } else if ("restriction".equals(osm.get("type"))) {
    238                     addIfNotNull(sl, NodeElemStyle.create(c));
     238                    addIfNotNull(sl, NodeElemStyle.create(env));
    239239                }
    240240            }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r3893 r3903  
    2121        MultiCascade mc = new MultiCascade();
    2222        Cascade c = mc.getOrCreateCascade("default");
    23         c.put("width", -1f);
     23        c.put("width", "default");
    2424        c.put("color", color != null ? color : PaintColors.UNTAGGED.get());
    2525        return createLine(new Environment(null, mc, "default", null));
     
    9595
    9696        Color color = c.get(prefix + "color", null, Color.class);
    97         if (color == null) {
    98             color = c.get(prefix + "fill-color", null, Color.class);
     97        if (!casing && color == null) {
     98            color = c.get("fill-color", null, Color.class);
    9999        }
    100100        if (color == null) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r3893 r3903  
    124124    public static final NodeElemStyle SIMPLE_NODE_ELEMSTYLE;
    125125    static {
    126         Cascade c = new Cascade();
     126        MultiCascade mc = new MultiCascade();
     127        Cascade c = mc.getOrCreateCascade("default");
    127128        c.put("text", "auto");
    128         SIMPLE_NODE_ELEMSTYLE = create(c, true);
     129        SIMPLE_NODE_ELEMSTYLE = create(new Environment(null, mc, "default", null), true);
    129130    }
    130131
     
    137138    }
    138139
    139     public static NodeElemStyle create(Cascade c) {
    140         return create(c, false);
    141     }
    142 
    143     private static NodeElemStyle create(Cascade c, boolean allowOnlyText) {
     140    public static NodeElemStyle create(Environment env) {
     141        return create(env, false);
     142    }
     143
     144    private static NodeElemStyle create(Environment env, boolean allowOnlyText) {
     145        Cascade c = env.mc.getCascade(env.layer);
     146
    144147        IconReference iconRef = c.get("icon-image", null, IconReference.class);
    145148        ImageIcon icon = null;
     
    158161            }
    159162        } else {
    160             symbol = createSymbol(c);
     163            symbol = createSymbol(env);
    161164        }
    162165
     
    195198    }
    196199
    197     private static Symbol createSymbol(Cascade c) {
     200    private static Symbol createSymbol(Environment env) {
     201        Cascade c = env.mc.getCascade(env.layer);
     202        Cascade c_def = env.mc.getCascade("default");
     203
    198204        SymbolShape shape;
    199205        String shapeStr = c.get("symbol-shape", null, String.class);
     
    204210        } else
    205211            return null;
    206 
    207         float size = c.get("symbol-size", 10f, Float.class);
     212       
     213        Float sizeOnDefault = c_def.get("symbol-size", null, Float.class);
     214        if (sizeOnDefault != null && sizeOnDefault <= 0) {
     215            sizeOnDefault = null;
     216        }
     217        Float size = getWidth(c, "symbol-size", sizeOnDefault);
     218
     219        if (size == null) {
     220            size = 10f;
     221        }
     222
    208223        if (size <= 0)
    209224            return null;
    210225
    211         Float strokeWidth = c.get("symbol-stroke-width", null, Float.class);
    212         if (strokeWidth != null && strokeWidth <= 0) {
    213             strokeWidth = null;
    214         }
     226        Float strokeWidthOnDefault = getWidth(c_def, "symbol-stroke-width", null);
     227        Float strokeWidth = getWidth(c, "symbol-stroke-width", strokeWidthOnDefault);
     228
    215229        Color strokeColor = c.get("symbol-stroke-color", null, Color.class);
    216230
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Expression.java

    r3893 r3903  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.mappaint.mapcss;
     3
     4import static org.openstreetmap.josm.tools.Utils.equal;
    35
    46import java.awt.Color;
     
    113115                }
    114116                return c;
     117            }
     118
     119            public float red(Color c) {
     120                return Utils.color_int2float(c.getRed());
     121            }
     122
     123            public float green(Color c) {
     124                return Utils.color_int2float(c.getGreen());
     125            }
     126
     127            public float blue(Color c) {
     128                return Utils.color_int2float(c.getBlue());
    115129            }
    116130
     
    154168            }
    155169
    156             public Object cond(boolean cond, Object if_, Object else_) {
    157                 return cond ? if_ : else_; // fixme: do not evaluate the other branch
    158             }
    159 
    160170            public boolean not(boolean b) {
    161171                return !b;
    162172            }
    163173
    164             public boolean and(boolean... bs) {
    165                 for (boolean b : bs) {  // fixme: lazy evaluation
    166                     if (!b)
    167                         return false;
    168                 }
    169                 return true;
    170             }
    171 
    172             public boolean or(boolean... bs) {
    173                 for (boolean b : bs) {
    174                     if (b)
    175                         return true;
    176                 }
    177                 return false;
    178             }
    179 
    180174            public boolean greater_equal(float a, float b) {
    181175                return a >= b;
     
    192186            public boolean less(float a, float b) {
    193187                return a < b;
     188            }
     189
     190            public int length(String s) {
     191                return s.length();
    194192            }
    195193
     
    201199                        Float.class, Boolean.class, Color.class, float[].class, String.class }) {
    202200                    Object a2 = Cascade.convertTo(a, klass);
    203                     Object b2 = Cascade.convertTo(a, klass);
     201                    Object b2 = Cascade.convertTo(b, klass);
    204202                    if (a2 != null && b2 != null && a2.equals(b2))
    205203                        return true;
     
    231229        @Override
    232230        public Object evaluate(Environment env) {
     231            if (equal(name, "cond")) { // this needs special handling since only one argument should be evaluated
     232                if (args.size() != 3)
     233                    return null;
     234                Boolean b = Cascade.convertTo(args.get(0).evaluate(env), boolean.class);
     235                if (b == null)
     236                    return null;
     237                return args.get(b ? 0 : 1).evaluate(env);
     238            }
     239            if (equal(name, "and")) {
     240                for (Expression arg : args) {
     241                    Boolean b = Cascade.convertTo(arg.evaluate(env), boolean.class);
     242                    if (b == null || !b)
     243                        return false;
     244                }
     245                return true;
     246            }
     247            if (equal(name, "or")) {
     248                for (Expression arg : args) {
     249                    Boolean b = Cascade.convertTo(arg.evaluate(env), boolean.class);
     250                    if (b != null && b)
     251                        return true;
     252                }
     253                return false;
     254            }
    233255            EvalFunctions fn = new EvalFunctions();
    234256            fn.env = env;
Note: See TracChangeset for help on using the changeset viewer.