Changeset 3903 in josm for trunk/src/org
- Timestamp:
- 2011-02-15T12:02:25+01:00 (14 years ago)
- 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 75 75 return (T) toBool(o); 76 76 77 if (klass == float[].class) {77 if (klass == float[].class) 78 78 return (T) toFloatArray(o); 79 }80 79 81 if (klass == Color.class) {80 if (klass == Color.class) 82 81 return (T) toColor(o); 83 } 82 83 if (klass == String.class) 84 return (T) o.toString(); 85 84 86 return null; 85 87 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java
r3899 r3903 36 36 Float width = c.get(key, null, Float.class, true); 37 37 if (width != null) { 38 if (width == -1f)39 return (float) MapPaintSettings.INSTANCE.getDefaultSegmentWidth();40 38 if (width > 0) 41 39 return width; … … 44 42 if (equal(width_key, "thinnest")) 45 43 return 0f; 44 else if(equal(width_key, "default")) 45 return (float) MapPaintSettings.INSTANCE.getDefaultSegmentWidth(); 46 46 else if (relativeTo != null) { 47 47 RelativeFloat width_rel = c.get(key, null, RelativeFloat.class, true); -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r3893 r3903 229 229 addIfNotNull(sl, LineElemStyle.createCasing(env)); 230 230 } else if (osm instanceof Node) { 231 addIfNotNull(sl, NodeElemStyle.create( c));231 addIfNotNull(sl, NodeElemStyle.create(env)); 232 232 } else if (osm instanceof Relation) { 233 233 if (((Relation)osm).isMultipolygon()) { … … 236 236 addIfNotNull(sl, LineElemStyle.createCasing(env)); 237 237 } else if ("restriction".equals(osm.get("type"))) { 238 addIfNotNull(sl, NodeElemStyle.create( c));238 addIfNotNull(sl, NodeElemStyle.create(env)); 239 239 } 240 240 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r3893 r3903 21 21 MultiCascade mc = new MultiCascade(); 22 22 Cascade c = mc.getOrCreateCascade("default"); 23 c.put("width", -1f);23 c.put("width", "default"); 24 24 c.put("color", color != null ? color : PaintColors.UNTAGGED.get()); 25 25 return createLine(new Environment(null, mc, "default", null)); … … 95 95 96 96 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); 99 99 } 100 100 if (color == null) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r3893 r3903 124 124 public static final NodeElemStyle SIMPLE_NODE_ELEMSTYLE; 125 125 static { 126 Cascade c = new Cascade(); 126 MultiCascade mc = new MultiCascade(); 127 Cascade c = mc.getOrCreateCascade("default"); 127 128 c.put("text", "auto"); 128 SIMPLE_NODE_ELEMSTYLE = create( c, true);129 SIMPLE_NODE_ELEMSTYLE = create(new Environment(null, mc, "default", null), true); 129 130 } 130 131 … … 137 138 } 138 139 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 144 147 IconReference iconRef = c.get("icon-image", null, IconReference.class); 145 148 ImageIcon icon = null; … … 158 161 } 159 162 } else { 160 symbol = createSymbol( c);163 symbol = createSymbol(env); 161 164 } 162 165 … … 195 198 } 196 199 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 198 204 SymbolShape shape; 199 205 String shapeStr = c.get("symbol-shape", null, String.class); … … 204 210 } else 205 211 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 208 223 if (size <= 0) 209 224 return null; 210 225 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 215 229 Color strokeColor = c.get("symbol-stroke-color", null, Color.class); 216 230 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Expression.java
r3893 r3903 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.mappaint.mapcss; 3 4 import static org.openstreetmap.josm.tools.Utils.equal; 3 5 4 6 import java.awt.Color; … … 113 115 } 114 116 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()); 115 129 } 116 130 … … 154 168 } 155 169 156 public Object cond(boolean cond, Object if_, Object else_) {157 return cond ? if_ : else_; // fixme: do not evaluate the other branch158 }159 160 170 public boolean not(boolean b) { 161 171 return !b; 162 172 } 163 173 164 public boolean and(boolean... bs) {165 for (boolean b : bs) { // fixme: lazy evaluation166 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 180 174 public boolean greater_equal(float a, float b) { 181 175 return a >= b; … … 192 186 public boolean less(float a, float b) { 193 187 return a < b; 188 } 189 190 public int length(String s) { 191 return s.length(); 194 192 } 195 193 … … 201 199 Float.class, Boolean.class, Color.class, float[].class, String.class }) { 202 200 Object a2 = Cascade.convertTo(a, klass); 203 Object b2 = Cascade.convertTo( a, klass);201 Object b2 = Cascade.convertTo(b, klass); 204 202 if (a2 != null && b2 != null && a2.equals(b2)) 205 203 return true; … … 231 229 @Override 232 230 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 } 233 255 EvalFunctions fn = new EvalFunctions(); 234 256 fn.env = env;
Note:
See TracChangeset
for help on using the changeset viewer.