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