1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package th.co.edge.jseq.argouml.pgml;
24
25 import java.awt.Point;
26 import java.util.LinkedList;
27 import java.util.List;
28
29 import org.w3c.dom.Document;
30 import org.w3c.dom.Element;
31
32 public class FigPath extends Fig {
33 private String description;
34 private List<Point> points = new LinkedList<Point>();
35
36 public FigPath(String name, String description, int x1, int y1, int x2,
37 int y2, Fill fill) {
38 super(name, fill, FillColor.WHITE, Stroke.ON, StrokeColor.BLACK);
39 this.description = description;
40 this.points.add(new Point(x1, y1));
41 this.points.add(new Point(x2, y2));
42 }
43
44 public FigPath(String name, String description, List<Point> points,
45 Fill fill) {
46 super(name, fill, FillColor.WHITE, Stroke.ON, StrokeColor.BLACK);
47 this.description = description;
48 if (points.size() < 2) {
49 String message = "Number of points must be at least 2: " + points;
50 throw new IllegalArgumentException(message);
51 }
52 this.points.addAll(points);
53 }
54
55 public Element getXML(Document doc) {
56 Element lineElement = createElement(doc, "path");
57 lineElement.setAttribute("description", getDescription());
58
59 Point point = (Point) points.get(0);
60
61 Element moveTo = doc.createElement("moveto");
62 moveTo.setAttribute("x", Integer.toString(point.x));
63 moveTo.setAttribute("y", Integer.toString(point.y));
64 lineElement.appendChild(moveTo);
65
66 for (int i = 1; i < points.size(); i++) {
67 point = (Point) points.get(i);
68 Element lineTo = doc.createElement("lineto");
69 lineTo.setAttribute("x", Integer.toString(point.x));
70 lineTo.setAttribute("y", Integer.toString(point.y));
71 lineElement.appendChild(lineTo);
72 }
73
74 return lineElement;
75 }
76
77 public String getDescription() {
78 return description;
79 }
80
81 public List<Point> getPoints() {
82 return points;
83 }
84 }