]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ControlPoint.java
Merge commit 'bd5bc6e45f700e755b61bd112631796631330ecb'
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / participant / ControlPoint.java
1 package org.simantics.diagram.participant;\r
2 \r
3 import java.awt.geom.AffineTransform;\r
4 import java.awt.geom.Point2D;\r
5 \r
6 import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo;\r
7 import org.simantics.g2d.elementclass.BranchPoint.Direction;\r
8 \r
9 /**\r
10  * @author Tuukka Lehtonen\r
11  */\r
12 public class ControlPoint {\r
13 \r
14     private final Point2D position           = new Point2D.Double();\r
15     private Direction     direction;\r
16     private TerminalInfo  attachedToTerminal = null;\r
17 \r
18     public ControlPoint(Point2D pos) {\r
19         this(pos, Direction.Any);\r
20     }\r
21 \r
22     public ControlPoint(Point2D pos, Direction direction) {\r
23         this.position.setLocation(pos);\r
24         this.direction = direction;\r
25     }\r
26 \r
27     public ControlPoint setPosition(Point2D position) {\r
28         this.position.setLocation(position);\r
29         return this;\r
30     }\r
31 \r
32     public ControlPoint setPosition(double x, double y) {\r
33         this.position.setLocation(x, y);\r
34         return this;\r
35     }\r
36 \r
37     /**\r
38      * Take the control point position from the translation part of the\r
39      * specified AffineTransform.\r
40      * \r
41      * @param at\r
42      * @return\r
43      */\r
44     public ControlPoint setPosition(AffineTransform at) {\r
45         this.position.setLocation(at.getTranslateX(), at.getTranslateY());\r
46         return this;\r
47     }\r
48 \r
49     public ControlPoint setDirection(Direction direction) {\r
50         if (direction == null)\r
51             throw new NullPointerException("trying to set null direction");\r
52         this.direction = direction;\r
53         return this;\r
54     }\r
55 \r
56     public ControlPoint setAttachedToTerminal(TerminalInfo info) {\r
57         this.attachedToTerminal = info;\r
58         return this;\r
59     }\r
60 \r
61     public Direction getDirection() {\r
62         return direction;\r
63     }\r
64 \r
65     public Point2D getPosition() {\r
66         return new Point2D.Double(position.getX(), position.getY());\r
67     }\r
68 \r
69     public boolean isAttachedToTerminal() {\r
70         return attachedToTerminal != null;\r
71     }\r
72 \r
73     public TerminalInfo getAttachedTerminal() {\r
74         return attachedToTerminal;\r
75     }\r
76 \r
77     @Override\r
78     public String toString() {\r
79         return "[" + position + ", " + direction + ", " + isAttachedToTerminal() + "]";\r
80     }\r
81 \r
82 }