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

Last change on this file since 7014 was 7014, checked in by Don-vip, 10 years ago

MapCSS: drop deprecated pattern-image support

  • Property svn:eol-style set to native
File size: 3.4 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.Cascade;
7import org.openstreetmap.josm.gui.mappaint.Environment;
8import org.openstreetmap.josm.gui.mappaint.Keyword;
9import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
10import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
11import org.openstreetmap.josm.gui.mappaint.StyleKeys;
12
13public abstract class Instruction implements StyleKeys {
14
15 public abstract void execute(Environment env);
16
17 public static class RelativeFloat {
18 public final float val;
19
20 public RelativeFloat(float val) {
21 this.val = val;
22 }
23
24 @Override
25 public String toString() {
26 return "RelativeFloat{" + "val=" + val + '}';
27 }
28 }
29
30 public static class AssignmentInstruction extends Instruction {
31 public final String key;
32 public final Object val;
33 public final boolean isSetInstruction;
34
35 public AssignmentInstruction(String key, Object val, boolean isSetInstruction) {
36 this.key = key;
37 this.isSetInstruction = isSetInstruction;
38 if (val instanceof LiteralExpression) {
39 Object litValue = ((LiteralExpression) val).evaluate(null);
40 if (key.equals(TEXT)) {
41 /* Special case for declaration 'text: ...'
42 *
43 * - Treat the value 'auto' as keyword.
44 * - Treat any other literal value 'litval' as as reference to tag with key 'litval'
45 *
46 * - Accept function expressions as is. This allows for
47 * tag(a_tag_name) value of a tag
48 * eval("a static text") a static text
49 * parent_tag(a_tag_name) value of a tag of a parent relation
50 */
51 if (litValue.equals(Keyword.AUTO)) {
52 this.val = Keyword.AUTO;
53 } else {
54 String s = Cascade.convertTo(litValue, String.class);
55 if (s != null) {
56 this.val = new MapPaintStyles.TagKeyReference(s);
57 } else {
58 this.val = litValue;
59 }
60 }
61 } else {
62 this.val = litValue;
63 }
64 } else {
65 this.val = val;
66 }
67 }
68
69 @Override
70 public void execute(Environment env) {
71 Object value = null;
72 if (val instanceof Expression) {
73 value = ((Expression) val).evaluate(env);
74 } else {
75 value = val;
76 }
77 if (key.equals(ICON_IMAGE) || key.equals(FILL_IMAGE) || key.equals(REPEAT_IMAGE)) {
78 if (value instanceof String) {
79 value = new IconReference((String) value, env.source);
80 }
81 }
82 env.mc.getOrCreateCascade(env.layer).putOrClear(key, value);
83 }
84
85 @Override
86 public String toString() {
87 return key + ": " + (val instanceof float[] ? Arrays.toString((float[]) val) : val instanceof String ? "String<"+val+">" : val) + ';';
88 }
89 }
90}
Note: See TracBrowser for help on using the repository browser.