1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package org.vectomatic.dom.svg;
31
32 import java.util.HashMap;
33 import java.util.Map;
34
35 import com.google.gwt.core.client.JavaScriptException;
36
37
38
39
40
41 public class OMCSSPrimitiveValue extends OMCSSValue {
42 public static final short CSS_UNKNOWN = 0;
43 public static final short CSS_NUMBER = 1;
44 public static final short CSS_PERCENTAGE = 2;
45 public static final short CSS_EMS = 3;
46 public static final short CSS_EXS = 4;
47 public static final short CSS_PX = 5;
48 public static final short CSS_CM = 6;
49 public static final short CSS_MM = 7;
50 public static final short CSS_IN = 8;
51 public static final short CSS_PT = 9;
52 public static final short CSS_PC = 10;
53 public static final short CSS_DEG = 11;
54 public static final short CSS_RAD = 12;
55 public static final short CSS_GRAD = 13;
56 public static final short CSS_MS = 14;
57 public static final short CSS_S = 15;
58 public static final short CSS_HZ = 16;
59 public static final short CSS_KHZ = 17;
60 public static final short CSS_DIMENSION = 18;
61 public static final short CSS_STRING = 19;
62 public static final short CSS_URI = 20;
63 public static final short CSS_IDENT = 21;
64 public static final short CSS_ATTR = 22;
65 public static final short CSS_COUNTER = 23;
66 public static final short CSS_RECT = 24;
67 public static final short CSS_RGBCOLOR = 25;
68
69 private short primitiveType;
70 private float floatValue;
71 private String stringValue;
72 private static Map<Short,String> unitToString;
73 protected OMCSSPrimitiveValue(float f) {
74 this(f, CSS_NUMBER);
75 }
76
77 public OMCSSPrimitiveValue(float floatValue, short primitiveType) {
78 super(CSS_PRIMITIVE_VALUE);
79 if (unitToString == null) {
80 unitToString = new HashMap<Short, String>();
81 unitToString.put(CSS_EMS, "em");
82 unitToString.put(CSS_EXS, "ex");
83 unitToString.put(CSS_PX, "px");
84 unitToString.put(CSS_IN, "in");
85 unitToString.put(CSS_CM, "cm");
86 unitToString.put(CSS_MM, "mm");
87 unitToString.put(CSS_PT, "pt");
88 unitToString.put(CSS_PC, "pc");
89 unitToString.put(CSS_PERCENTAGE, "%");
90 }
91 StringBuilder builder = new StringBuilder(Float.toString(floatValue));
92 String unit = unitToString.get(primitiveType);
93 if (unit != null) {
94 builder.append(unit);
95 }
96 setCssText(builder.toString());
97 this.floatValue = floatValue;
98 this.primitiveType = primitiveType;
99 }
100 public OMCSSPrimitiveValue(String stringValue, short primitiveType) {
101 super(CSS_PRIMITIVE_VALUE);
102 this.stringValue = stringValue;
103 this.primitiveType = primitiveType;
104 this.cssText = stringValue;
105 }
106
107
108 public final short getPrimitiveType() {
109 return this.primitiveType;
110 }
111 public final void setFloatValue(short unitType, float floatValue) throws JavaScriptException {
112 this.primitiveType = unitType;
113 this.floatValue = floatValue;
114 }
115 public final float getFloatValue(short unitType) throws JavaScriptException {
116 return floatValue;
117 }
118 public final void setStringValue(short stringType, String stringValue) throws JavaScriptException {
119 this.primitiveType = stringType;
120 this.stringValue = stringValue;
121 }
122 public final String getStringValue() throws JavaScriptException {
123 return stringValue;
124 }
125 public final OMRGBColor getRGBColorValue() throws JavaScriptException {
126 throw new UnsupportedOperationException();
127 }
128 @Override
129 public String getDescription() {
130 StringBuilder builder = new StringBuilder("OMCSSPrimitiveValue(primitiveType=");
131 builder.append(primitiveType);
132 builder.append(", value=");
133 if (primitiveType >= CSS_NUMBER && CSS_NUMBER <= CSS_GRAD) {
134 builder.append(floatValue);
135 } else {
136 builder.append(stringValue);
137 }
138 builder.append(", cssValueType=");
139 builder.append(cssValueType);
140 builder.append(", cssText=");
141 builder.append(cssText);
142 builder.append(")");
143 return builder.toString();
144 }
145
146 }