001: /*
002: * WaypointFlag.java
003: *
004: * Created on 28 November 2006, 12:01
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009:
010: package com.xoetrope.svg;
011:
012: import com.kitfox.svg.Group;
013: import com.kitfox.svg.Path;
014: import com.kitfox.svg.Rect;
015: import com.kitfox.svg.SVGElementException;
016: import com.kitfox.svg.SVGRoot;
017: import com.kitfox.svg.Text;
018: import com.kitfox.svg.Tspan;
019: import com.kitfox.svg.animation.AnimationElement;
020: import com.xoetrope.carousel.build.BuildProperties;
021:
022: /**
023: *
024: *
025: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
026: * the GNU Public License (GPL), please see license.txt for more details. If
027: * you make commercial use of this software you must purchase a commercial
028: * license from Xoetrope.</p>
029: * <p> $Revision: 1.2 $</p>
030: */
031: public class XWaypointFlag extends Group {
032: public static final int START_WAYPOINT = 0;
033: public static final int END_WAYPOINT = 1;
034: public static final int MARKER_WAYPOINT = 2;
035: private int type;
036: private String colour;
037:
038: protected SVGRoot root;
039:
040: /**
041: * Creates a new instance of WaypointFlag.
042: * @param root the <CODE>SVGRoot</CODE> instance that the flag will be added to.
043: */
044: public XWaypointFlag(SVGRoot root) {
045: this .root = root;
046: }
047:
048: /**
049: * Draws the flag group.
050: * @param x <CODE>double</CODE> specifying the x coordinate of the flag.
051: * @param y <CODE>double</CODE> specifying the y coordinate of the flag.
052: * @param content <CODE>String</CODE> specifying the content of the flag.
053: * @param type <CODE>int</CODE> specifying the type of flag to be drawn.
054: */
055: public void drawFlag(double x, double y, String content, int type) {
056: if (type == 0)
057: colour = "lime";
058: else if (type == 1)
059: colour = "red";
060: else if (type == 2)
061: colour = "yellow";
062:
063: try {
064: addAttribute("id", AnimationElement.AT_XML, "waypointFlag");
065: addAttribute("transform", AnimationElement.AT_XML,
066: "translate(" + Double.toString(x - 12.2) + ","
067: + Double.toString(y - 18) + ") scale(0.75)");
068:
069: Path p1 = new Path();
070: p1.addAttribute("id", AnimationElement.AT_XML, "p1");
071: p1
072: .addAttribute(
073: "d",
074: AnimationElement.AT_XML,
075: "M 12.838026,14.794209 L 19.549687,14.794209 L 16.146591,22.888131 L 12.838026,14.794209 z ");
076: p1.addAttribute("fill", AnimationElement.AT_CSS, colour);
077: p1.addAttribute("fill-opacity", AnimationElement.AT_CSS,
078: "1");
079: p1.addAttribute("fill-rule", AnimationElement.AT_CSS,
080: "evenodd");
081: p1.addAttribute("stroke", AnimationElement.AT_CSS, "black");
082: p1.addAttribute("stroke-width", AnimationElement.AT_CSS,
083: "0.034336px");
084: p1.addAttribute("stroke-linecap", AnimationElement.AT_CSS,
085: "butt");
086: p1.addAttribute("stroke-linejoin", AnimationElement.AT_CSS,
087: "miter");
088: p1.addAttribute("stroke-miterlimit",
089: AnimationElement.AT_CSS, "4");
090: p1.addAttribute("stroke-dasharray",
091: AnimationElement.AT_CSS, "none");
092: p1.addAttribute("stroke-opacity", AnimationElement.AT_CSS,
093: "1");
094:
095: Path p2 = new Path();
096: p2
097: .addAttribute(
098: "d",
099: AnimationElement.AT_XML,
100: "M 17.731344,19.32296 C 17.131717,20.708532 16.503161,22.104614 16.204231,23.599272 L 16.197994,23.65206");
101: p2.addAttribute("fill", AnimationElement.AT_CSS, colour);
102: p2.addAttribute("fill-opacity", AnimationElement.AT_CSS,
103: "1");
104: p2.addAttribute("fill-rule", AnimationElement.AT_CSS,
105: "nonzero");
106: p2.addAttribute("stroke", AnimationElement.AT_CSS, "black");
107: p2.addAttribute("stroke-width", AnimationElement.AT_CSS,
108: "0.50563216");
109: p2.addAttribute("stroke-linecap", AnimationElement.AT_CSS,
110: "round");
111: p2.addAttribute("stroke-linejoin", AnimationElement.AT_CSS,
112: "round");
113: p2.addAttribute("stroke-miterlimit",
114: AnimationElement.AT_CSS, "4");
115: p2.addAttribute("stroke-dasharray",
116: AnimationElement.AT_CSS, "none");
117: p2.addAttribute("stroke-opacity", AnimationElement.AT_CSS,
118: "1");
119:
120: Path p3 = new Path();
121: p3
122: .addAttribute(
123: "d",
124: AnimationElement.AT_XML,
125: "M 14.726964,19.33059 C 15.348015,20.717128 15.857829,22.163201 16.197994,23.652056");
126: p3.addAttribute("fill", AnimationElement.AT_CSS, colour);
127: p3.addAttribute("fill-opacity", AnimationElement.AT_CSS,
128: "1");
129: p3.addAttribute("fill-rule", AnimationElement.AT_CSS,
130: "nonzero");
131: p3.addAttribute("stroke", AnimationElement.AT_CSS, "black");
132: p3.addAttribute("stroke-width", AnimationElement.AT_CSS,
133: "0.50563216");
134: p3.addAttribute("stroke-linecap", AnimationElement.AT_CSS,
135: "round");
136: p3.addAttribute("stroke-linejoin", AnimationElement.AT_CSS,
137: "round");
138: p3.addAttribute("stroke-miterlimit",
139: AnimationElement.AT_CSS, "4");
140: p3.addAttribute("stroke-dasharray",
141: AnimationElement.AT_CSS, "none");
142: p3.addAttribute("stroke-opacity", AnimationElement.AT_CSS,
143: "1");
144:
145: Path p4 = new Path();
146: p4
147: .addAttribute(
148: "d",
149: AnimationElement.AT_XML,
150: "M 12.830714,15.111361 C 12.26495,13.481487 13.004347,11.514391 14.480129,10.70754 C 15.880713,9.8721814 17.797167,10.219258 18.847859,11.49035 C 19.696669,12.476095 19.992631,13.947021 19.527951,15.188154");
151: p4.addAttribute("fill", AnimationElement.AT_CSS, colour);
152: p4.addAttribute("fill-opacity", AnimationElement.AT_CSS,
153: "1");
154: p4.addAttribute("fill-rule", AnimationElement.AT_CSS,
155: "nonzero");
156: p4.addAttribute("stroke", AnimationElement.AT_CSS, "black");
157: p4.addAttribute("stroke-width", AnimationElement.AT_CSS,
158: "0.50563216");
159: p4.addAttribute("stroke-linecap", AnimationElement.AT_CSS,
160: "round");
161: p4.addAttribute("stroke-linejoin", AnimationElement.AT_CSS,
162: "round");
163: p4.addAttribute("stroke-miterlimit",
164: AnimationElement.AT_CSS, "4");
165: p4.addAttribute("stroke-dasharray",
166: AnimationElement.AT_CSS, "none");
167: p4.addAttribute("stroke-opacity", AnimationElement.AT_CSS,
168: "1");
169:
170: Path p5 = new Path();
171: p5
172: .addAttribute(
173: "d",
174: AnimationElement.AT_XML,
175: "M 19.529488,15.158241 C 18.929293,16.542501 18.329098,17.926759 17.728905,19.311015");
176: p5.addAttribute("fill", AnimationElement.AT_CSS, colour);
177: p5.addAttribute("fill-opacity", AnimationElement.AT_CSS,
178: "1");
179: p5.addAttribute("fill-rule", AnimationElement.AT_CSS,
180: "nonzero");
181: p5.addAttribute("stroke", AnimationElement.AT_CSS, "black");
182: p5.addAttribute("stroke-width", AnimationElement.AT_CSS,
183: "0.50563216");
184: p5.addAttribute("stroke-linecap", AnimationElement.AT_CSS,
185: "round");
186: p5.addAttribute("stroke-linejoin", AnimationElement.AT_CSS,
187: "round");
188: p5.addAttribute("stroke-miterlimit",
189: AnimationElement.AT_CSS, "4");
190: p5.addAttribute("stroke-dasharray",
191: AnimationElement.AT_CSS, "none");
192: p5.addAttribute("stroke-opacity", AnimationElement.AT_CSS,
193: "1");
194:
195: Path p6 = new Path();
196: p6
197: .addAttribute(
198: "d",
199: AnimationElement.AT_XML,
200: "M 12.784054,14.993192 C 13.419218,16.405721 14.078017,17.867306 14.71318,19.279837");
201: p6.addAttribute("fill", AnimationElement.AT_CSS, colour);
202: p6.addAttribute("fill-opacity", AnimationElement.AT_CSS,
203: "1");
204: p6.addAttribute("fill-rule", AnimationElement.AT_CSS,
205: "nonzero");
206: p6.addAttribute("stroke", AnimationElement.AT_CSS, "black");
207: p6.addAttribute("stroke-width", AnimationElement.AT_CSS,
208: "0.50563216");
209: p6.addAttribute("stroke-linecap", AnimationElement.AT_CSS,
210: "round");
211: p6.addAttribute("stroke-linejoin", AnimationElement.AT_CSS,
212: "round");
213: p6.addAttribute("stroke-miterlimit",
214: AnimationElement.AT_CSS, "4");
215: p6.addAttribute("stroke-dasharray",
216: AnimationElement.AT_CSS, "none");
217: p6.addAttribute("stroke-opacity", AnimationElement.AT_CSS,
218: "1");
219:
220: loaderAddChild(null, p1);
221: loaderAddChild(null, p2);
222: loaderAddChild(null, p3);
223: loaderAddChild(null, p4);
224: loaderAddChild(null, p5);
225: loaderAddChild(null, p6);
226:
227: if (type == 0) {
228: Path p7 = new Path();
229: p7
230: .addAttribute(
231: "d",
232: AnimationElement.AT_XML,
233: "M 15.429687,13.232427 L 15.429687,14.550786 L 16.894532,13.916021 L 15.429687,13.232427 z ");
234: p7.addAttribute("fill", AnimationElement.AT_CSS,
235: "black");
236: p7.addAttribute("fill-opacity",
237: AnimationElement.AT_CSS, "1");
238: p7.addAttribute("fill-rule", AnimationElement.AT_CSS,
239: "evenodd");
240: p7.addAttribute("stroke", AnimationElement.AT_CSS,
241: "black");
242: p7.addAttribute("stroke-width",
243: AnimationElement.AT_CSS, "1px");
244: p7.addAttribute("stroke-linecap",
245: AnimationElement.AT_CSS, "butt");
246: p7.addAttribute("stroke-linejoin",
247: AnimationElement.AT_CSS, "miter");
248: p7.addAttribute("stroke-miterlimit",
249: AnimationElement.AT_CSS, "4");
250: p7.addAttribute("stroke-dasharray",
251: AnimationElement.AT_CSS, "none");
252: p7.addAttribute("stroke-opacity",
253: AnimationElement.AT_CSS, "1");
254: loaderAddChild(null, p7);
255: } else if (type == 1) {
256: Rect rect = new Rect();
257: rect.addAttribute("fill", AnimationElement.AT_CSS,
258: "black");
259: rect.addAttribute("fill-opacity",
260: AnimationElement.AT_CSS, "1");
261: rect.addAttribute("fill-rule", AnimationElement.AT_CSS,
262: "nonzero");
263: rect.addAttribute("stroke", AnimationElement.AT_CSS,
264: "none");
265: rect.addAttribute("stroke-width",
266: AnimationElement.AT_CSS, "15");
267: rect.addAttribute("stroke-linecap",
268: AnimationElement.AT_CSS, "round");
269: rect.addAttribute("stroke-linejoin",
270: AnimationElement.AT_CSS, "round");
271: rect.addAttribute("stroke-miterlimit",
272: AnimationElement.AT_CSS, "4");
273: rect.addAttribute("stroke-dasharray",
274: AnimationElement.AT_CSS, "none");
275: rect.addAttribute("stroke-opacity",
276: AnimationElement.AT_CSS, "1");
277: rect.addAttribute("width", AnimationElement.AT_XML,
278: "2.7324219");
279: rect.addAttribute("height", AnimationElement.AT_XML,
280: "2.9796286");
281: rect.addAttribute("x", AnimationElement.AT_XML,
282: "14.755859");
283: rect.addAttribute("y", AnimationElement.AT_XML,
284: "12.410996");
285: loaderAddChild(null, rect);
286: } else if (type == 2) {
287: Text text = new Text();
288: double d = 14.614655 - (1.2 * (content.length() - 1));
289: text.addAttribute("x", AnimationElement.AT_XML, Double
290: .toString(d));
291: text.addAttribute("y", AnimationElement.AT_XML,
292: "15.793638");
293: text.addAttribute("text-align",
294: AnimationElement.AT_XML, "center");
295: text.addAttribute("xml:space", AnimationElement.AT_CSS,
296: "preserve");
297: text.addAttribute("sodipodi:linespacing",
298: AnimationElement.AT_XML, "125%");
299:
300: Tspan tspan = new Tspan();
301: tspan.addAttribute("x", AnimationElement.AT_XML, Double
302: .toString(d));
303: tspan.addAttribute("y", AnimationElement.AT_XML,
304: "17.731087");
305: tspan.addAttribute("font-size",
306: AnimationElement.AT_CSS, "5.14629841px");
307: tspan.addAttribute("font-style",
308: AnimationElement.AT_CSS, "normal");
309: tspan.addAttribute("font-variant",
310: AnimationElement.AT_CSS, "normal");
311: tspan.addAttribute("font-weight",
312: AnimationElement.AT_CSS, "normal");
313: tspan.addAttribute("font-stretch",
314: AnimationElement.AT_CSS, "normal");
315: tspan.addAttribute("text-align",
316: AnimationElement.AT_CSS, "center");
317: tspan.addAttribute("line-height",
318: AnimationElement.AT_CSS, "125%");
319: tspan.addAttribute("writing-mode",
320: AnimationElement.AT_CSS, "lr-tb");
321: tspan.addAttribute("text-anchor",
322: AnimationElement.AT_CSS, "center");
323: tspan.addAttribute("font-family",
324: AnimationElement.AT_CSS, "Arial");
325: tspan.setText(content);
326:
327: text.appendTspan(tspan);
328: loaderAddChild(null, text);
329: }
330:
331: root.loaderAddChild(null, this );
332: } catch (Exception ex) {
333: if (BuildProperties.DEBUG)
334: ex.printStackTrace();
335: }
336: }
337: }
|