source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java@ 3876

Last change on this file since 3876 was 3876, checked in by bastiK, 13 years ago

mapcss: support for more exotic constructs; make parser more robust: if parsing as an expression fails, read everything between colon and semicolon as string, e.g. 'icon-image: images/img.png;' where the path should be in quotes, but it isn't

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint.mapcss;
3
4import java.util.Arrays;
5
6import org.openstreetmap.josm.gui.mappaint.Environment;
7import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
8
9abstract public class Instruction {
10
11 public abstract void execute(Environment env);
12
13 public static class RelativeFloat {
14 public float val;
15
16 public RelativeFloat(float val) {
17 this.val = val;
18 }
19
20 @Override
21 public String toString() {
22 return "RelativeFloat{" + "val=" + val + '}';
23 }
24 }
25
26 public static class AssignmentInstruction extends Instruction {
27 String key;
28 Object val;
29
30 public AssignmentInstruction(String key, Object val) {
31 this.key = key;
32 if (val instanceof Expression.LiteralExpression) {
33 this.val = ((Expression.LiteralExpression) val).evaluate(null);
34 } else {
35 this.val = val;
36 }
37 }
38
39 @Override
40 public void execute(Environment env) {
41 Object value = (val instanceof Expression) ? ((Expression) val).evaluate(env) : val;
42 if (key.equals("icon-image") || key.equals("fill-image")) {
43 if (value instanceof String) {
44 value = new IconReference((String) value, env.source);
45 }
46 }
47 env.getCascade().putOrClear(key, value);
48 }
49
50 @Override
51 public String toString() {
52 return key + ':' + (val instanceof float[] ? Arrays.toString((float[]) val) : val) + ';';
53 }
54 }
55}
Note: See TracBrowser for help on using the repository browser.