]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ControlPoint.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / participant / ControlPoint.java
diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ControlPoint.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ControlPoint.java
new file mode 100644 (file)
index 0000000..69d90a7
--- /dev/null
@@ -0,0 +1,82 @@
+package org.simantics.diagram.participant;\r
+\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Point2D;\r
+\r
+import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo;\r
+import org.simantics.g2d.elementclass.BranchPoint.Direction;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class ControlPoint {\r
+\r
+    private final Point2D position           = new Point2D.Double();\r
+    private Direction     direction;\r
+    private TerminalInfo  attachedToTerminal = null;\r
+\r
+    public ControlPoint(Point2D pos) {\r
+        this(pos, Direction.Any);\r
+    }\r
+\r
+    public ControlPoint(Point2D pos, Direction direction) {\r
+        this.position.setLocation(pos);\r
+        this.direction = direction;\r
+    }\r
+\r
+    public ControlPoint setPosition(Point2D position) {\r
+        this.position.setLocation(position);\r
+        return this;\r
+    }\r
+\r
+    public ControlPoint setPosition(double x, double y) {\r
+        this.position.setLocation(x, y);\r
+        return this;\r
+    }\r
+\r
+    /**\r
+     * Take the control point position from the translation part of the\r
+     * specified AffineTransform.\r
+     * \r
+     * @param at\r
+     * @return\r
+     */\r
+    public ControlPoint setPosition(AffineTransform at) {\r
+        this.position.setLocation(at.getTranslateX(), at.getTranslateY());\r
+        return this;\r
+    }\r
+\r
+    public ControlPoint setDirection(Direction direction) {\r
+        if (direction == null)\r
+            throw new NullPointerException("trying to set null direction");\r
+        this.direction = direction;\r
+        return this;\r
+    }\r
+\r
+    public ControlPoint setAttachedToTerminal(TerminalInfo info) {\r
+        this.attachedToTerminal = info;\r
+        return this;\r
+    }\r
+\r
+    public Direction getDirection() {\r
+        return direction;\r
+    }\r
+\r
+    public Point2D getPosition() {\r
+        return new Point2D.Double(position.getX(), position.getY());\r
+    }\r
+\r
+    public boolean isAttachedToTerminal() {\r
+        return attachedToTerminal != null;\r
+    }\r
+\r
+    public TerminalInfo getAttachedTerminal() {\r
+        return attachedToTerminal;\r
+    }\r
+\r
+    @Override\r
+    public String toString() {\r
+        return "[" + position + ", " + direction + ", " + isAttachedToTerminal() + "]";\r
+    }\r
+\r
+}
\ No newline at end of file