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