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