View Javadoc

1   /*
2    * Copyright (c) 2003-2008, by Henrik Arro and Contributors
3    *
4    * This file is part of JSeq, a tool to automatically create
5    * sequence diagrams by tracing program execution.
6    *
7    * See <http://jseq.sourceforge.net> for more information.
8    *
9    * JSeq is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of
12   * the License, or (at your option) any later version.
13   *
14   * JSeq is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   * GNU Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public License
20   * along with JSeq. If not, see <http://www.gnu.org/licenses/>.
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  }