1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.element.handler.impl;
14 import java.awt.Shape;
15 import java.awt.geom.AffineTransform;
17 import org.simantics.g2d.diagram.handler.Topology.Terminal;
18 import org.simantics.g2d.utils.geom.DirectionSet;
19 import org.simantics.utils.Container;
20 import org.simantics.utils.DataContainer;
23 * An arbitrary object based implementation of the g2d {@link Terminal}
27 * Elements that intend to contain terminal and use
28 * <code>DiagramGraphSynchronizer</code> must use this implementation to
29 * represent the terminals of the element.
33 * Also contains a relative transformation with respect to its parent, a set of
34 * allowed drawing directions and a graphical shape to depict the terminal.
37 * @author Tuukka Lehtonen
39 public abstract class ObjectTerminal implements Terminal {
41 private static final Container<Shape> NO_SHAPE = new DataContainer<Shape>(null);
43 private final Object data;
44 private final AffineTransform transform;
45 private final DirectionSet ds;
46 private final Container<Shape> shape;
48 public ObjectTerminal(Object data, AffineTransform transform, DirectionSet ds, Container<Shape> shape) {
51 this.transform = transform;
53 this.shape = shape != null ? shape : NO_SHAPE;
56 public ObjectTerminal(Object data, AffineTransform transform, DirectionSet ds, Shape shape) {
57 this(data, transform, ds, new DataContainer<Shape>(shape));
60 public ObjectTerminal(Object data, AffineTransform transform, DirectionSet ds) {
61 this(data, transform, ds, NO_SHAPE);
64 public ObjectTerminal(Object data, AffineTransform transform) {
65 this(data, transform, DirectionSet.ANY, NO_SHAPE);
68 public ObjectTerminal(Object data) {
69 this(data, new AffineTransform(), DirectionSet.ANY, NO_SHAPE);
73 public String toString() {
74 return getClass().getSimpleName() + "[" + data + ", " + transform + ", " + shape + "]";
78 public int hashCode() {
79 return data.hashCode();
83 public boolean equals(Object obj) {
86 if (obj == null || getClass() != obj.getClass())
88 ObjectTerminal other = (ObjectTerminal) obj;
89 return data.equals(other.data);
92 public Object getData() {
96 public AffineTransform getTransform() {
100 public DirectionSet getDirections() {
104 public Shape getShape() {