| 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 | 15 | 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 | 15 | super(name, fill, FillColor.WHITE, Stroke.ON, StrokeColor.BLACK); |
| 39 | 15 | this.description = description; |
| 40 | 15 | this.points.add(new Point(x1, y1)); |
| 41 | 15 | this.points.add(new Point(x2, y2)); |
| 42 | 15 | } |
| 43 | |
|
| 44 | |
public FigPath(String name, String description, List<Point> points, |
| 45 | |
Fill fill) { |
| 46 | 0 | super(name, fill, FillColor.WHITE, Stroke.ON, StrokeColor.BLACK); |
| 47 | 0 | this.description = description; |
| 48 | 0 | if (points.size() < 2) { |
| 49 | 0 | String message = "Number of points must be at least 2: " + points; |
| 50 | 0 | throw new IllegalArgumentException(message); |
| 51 | |
} |
| 52 | 0 | this.points.addAll(points); |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
public Element getXML(Document doc) { |
| 56 | 15 | Element lineElement = createElement(doc, "path"); |
| 57 | 15 | lineElement.setAttribute("description", getDescription()); |
| 58 | |
|
| 59 | 15 | Point point = (Point) points.get(0); |
| 60 | |
|
| 61 | 15 | Element moveTo = doc.createElement("moveto"); |
| 62 | 15 | moveTo.setAttribute("x", Integer.toString(point.x)); |
| 63 | 15 | moveTo.setAttribute("y", Integer.toString(point.y)); |
| 64 | 15 | lineElement.appendChild(moveTo); |
| 65 | |
|
| 66 | 30 | for (int i = 1; i < points.size(); i++) { |
| 67 | 15 | point = (Point) points.get(i); |
| 68 | 15 | Element lineTo = doc.createElement("lineto"); |
| 69 | 15 | lineTo.setAttribute("x", Integer.toString(point.x)); |
| 70 | 15 | lineTo.setAttribute("y", Integer.toString(point.y)); |
| 71 | 15 | lineElement.appendChild(lineTo); |
| 72 | |
} |
| 73 | |
|
| 74 | 15 | return lineElement; |
| 75 | |
} |
| 76 | |
|
| 77 | |
public String getDescription() { |
| 78 | 15 | return description; |
| 79 | |
} |
| 80 | |
|
| 81 | |
public List<Point> getPoints() { |
| 82 | 0 | return points; |
| 83 | |
} |
| 84 | |
} |