1 package org.simantics.diagram.participant;
\r
3 import java.awt.geom.AffineTransform;
\r
4 import java.awt.geom.Point2D;
\r
6 import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo;
\r
7 import org.simantics.g2d.elementclass.BranchPoint.Direction;
\r
10 * @author Tuukka Lehtonen
\r
12 public class ControlPoint {
\r
14 private final Point2D position = new Point2D.Double();
\r
15 private Direction direction;
\r
16 private TerminalInfo attachedToTerminal = null;
\r
18 public ControlPoint(Point2D pos) {
\r
19 this(pos, Direction.Any);
\r
22 public ControlPoint(Point2D pos, Direction direction) {
\r
23 this.position.setLocation(pos);
\r
24 this.direction = direction;
\r
27 public ControlPoint setPosition(Point2D position) {
\r
28 this.position.setLocation(position);
\r
32 public ControlPoint setPosition(double x, double y) {
\r
33 this.position.setLocation(x, y);
\r
38 * Take the control point position from the translation part of the
\r
39 * specified AffineTransform.
\r
44 public ControlPoint setPosition(AffineTransform at) {
\r
45 this.position.setLocation(at.getTranslateX(), at.getTranslateY());
\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
56 public ControlPoint setAttachedToTerminal(TerminalInfo info) {
\r
57 this.attachedToTerminal = info;
\r
61 public Direction getDirection() {
\r
65 public Point2D getPosition() {
\r
66 return new Point2D.Double(position.getX(), position.getY());
\r
69 public boolean isAttachedToTerminal() {
\r
70 return attachedToTerminal != null;
\r
73 public TerminalInfo getAttachedTerminal() {
\r
74 return attachedToTerminal;
\r
78 public String toString() {
\r
79 return "[" + position + ", " + direction + ", " + isAttachedToTerminal() + "]";
\r