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 org.vectomatic.dom.svg.utils.SVGConstants;
33
34 import com.google.gwt.core.client.JavaScriptException;
35
36
37
38
39
40
41
42
43 public class OMSVGPaint extends OMSVGColor {
44
45
46
47
48
49 public static final short SVG_PAINTTYPE_UNKNOWN = 0;
50
51
52
53 public static final short SVG_PAINTTYPE_RGBCOLOR = 1;
54
55
56
57 public static final short SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR = 2;
58
59
60
61
62 public static final short SVG_PAINTTYPE_NONE = 101;
63
64
65
66
67 public static final short SVG_PAINTTYPE_CURRENTCOLOR = 102;
68
69
70
71
72 public static final short SVG_PAINTTYPE_URI_NONE = 103;
73
74
75
76
77 public static final short SVG_PAINTTYPE_URI_CURRENTCOLOR = 104;
78
79
80
81
82 public static final short SVG_PAINTTYPE_URI_RGBCOLOR = 105;
83
84
85
86
87 public static final short SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR = 106;
88
89
90
91 public static final short SVG_PAINTTYPE_URI = 107;
92
93 private short paintType;
94 private String uri;
95
96 public OMSVGPaint(short paintType) {
97 this.paintType = paintType;
98 switch(paintType) {
99 case SVG_PAINTTYPE_NONE:
100 cssText = SVGConstants.CSS_NONE_VALUE;
101 break;
102 case SVG_PAINTTYPE_CURRENTCOLOR:
103 cssText = SVGConstants.CSS_CURRENTCOLOR_VALUE;
104 colorType = SVG_COLORTYPE_CURRENTCOLOR;
105 break;
106 }
107 }
108
109 @Override
110 public int hashCode() {
111 int hashCode = paintType;
112 if (rgbColor != null) {
113 hashCode += rgbColor.hashCode();
114 }
115 if (iccColor != null) {
116 hashCode += iccColor.hashCode();
117 }
118 if (uri != null) {
119 hashCode += uri.hashCode();
120 }
121 return hashCode;
122 }
123
124 @Override
125 public boolean equals(Object obj) {
126 if (obj instanceof OMSVGPaint) {
127 OMSVGPaint p = (OMSVGPaint)obj;
128 if (paintType == p.paintType) {
129 switch (paintType) {
130 case SVG_PAINTTYPE_NONE:
131 case SVG_PAINTTYPE_CURRENTCOLOR:
132 case SVG_PAINTTYPE_UNKNOWN:
133 return true;
134 case SVG_PAINTTYPE_RGBCOLOR:
135 return rgbColor.equals(p.rgbColor);
136 case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
137 return rgbColor.equals(p.rgbColor) && iccColor.equals(p.iccColor);
138 case SVG_PAINTTYPE_URI:
139 case SVG_PAINTTYPE_URI_NONE:
140 return uri.equals(p.uri);
141 case SVG_PAINTTYPE_URI_RGBCOLOR:
142 return uri.equals(p.uri) && rgbColor.equals(p.rgbColor);
143 case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
144 return uri.equals(p.uri) && rgbColor.equals(p.rgbColor) && iccColor.equals(p.iccColor);
145 }
146 }
147 }
148 return false;
149 }
150
151
152
153
154
155
156
157
158 public final short getPaintType() {
159 return this.paintType;
160 }
161
162
163
164
165
166 public final String getUri() {
167 return this.uri;
168 }
169
170
171
172
173
174
175 public final void setUri(String uri) {
176 this.paintType = SVG_PAINTTYPE_URI_NONE;
177 this.uri = uri;
178 this.rgbColor = null;
179 this.iccColor = null;
180 }
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197 public final void setPaint(short paintType, String uri, String rgbColor, String iccColor) throws JavaScriptException {
198 if (((paintType == SVG_PAINTTYPE_RGBCOLOR && uri == null) || (paintType == SVG_PAINTTYPE_URI_RGBCOLOR && uri != null)) && iccColor == null) {
199 setRGBColor(rgbColor);
200 } else if ((paintType == SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR && uri == null) || (paintType == SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR && uri != null)) {
201 setRGBColorICCColor(rgbColor, iccColor);
202 } else if ((paintType == SVG_PAINTTYPE_NONE && uri == null) || (paintType == SVG_PAINTTYPE_URI_NONE && uri != null)) {
203 setColor(SVG_COLORTYPE_UNKNOWN, rgbColor, iccColor);
204 } else if ((paintType == SVG_PAINTTYPE_CURRENTCOLOR && uri == null) || (paintType == SVG_PAINTTYPE_URI_CURRENTCOLOR && uri != null)) {
205 setColor(SVG_COLORTYPE_CURRENTCOLOR, rgbColor, iccColor);
206 } else if (paintType == SVG_PAINTTYPE_URI) {
207 this.rgbColor = null;
208 this.iccColor = null;
209 this.cssText = "url(" + uri + ")";
210 } else {
211 throw new JavaScriptException("Invalid paint spec");
212 }
213 this.paintType = paintType;
214 this.uri = uri;
215 if (paintType != SVG_PAINTTYPE_URI && cssText != null && uri != null) {
216 cssText = "url(" + uri + ") " + cssText;
217 }
218 }
219
220 @Override
221 public String getDescription() {
222 StringBuilder builder = new StringBuilder("OMSVGPaint(paintType=");
223 builder.append(paintType);
224 builder.append(", uri=");
225 builder.append(uri);
226 builder.append(", colorType=");
227 builder.append(colorType);
228 builder.append(", rgbColor=");
229 builder.append(rgbColor.getDescription());
230 builder.append(", iccColor=");
231 builder.append(iccColor.getDescription());
232 builder.append(", cssValueType=");
233 builder.append(cssValueType);
234 builder.append(", cssText=");
235 builder.append(cssText);
236 builder.append(")");
237 return builder.toString();
238 }
239
240 }