]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/ObjectTerminal.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / impl / ObjectTerminal.java
diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/ObjectTerminal.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/ObjectTerminal.java
new file mode 100644 (file)
index 0000000..1804b15
--- /dev/null
@@ -0,0 +1,108 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.g2d.element.handler.impl;\r
+\r
+import java.awt.Shape;\r
+import java.awt.geom.AffineTransform;\r
+\r
+import org.simantics.g2d.diagram.handler.Topology.Terminal;\r
+import org.simantics.g2d.utils.geom.DirectionSet;\r
+import org.simantics.utils.Container;\r
+import org.simantics.utils.DataContainer;\r
+\r
+/**\r
+ * An arbitrary object based implementation of the g2d {@link Terminal}\r
+ * interface.\r
+ * \r
+ * <p>\r
+ * Elements that intend to contain terminal and use\r
+ * <code>DiagramGraphSynchronizer</code> must use this implementation to\r
+ * represent the terminals of the element.\r
+ * </p>\r
+ * \r
+ * <p>\r
+ * Also contains a relative transformation with respect to its parent, a set of\r
+ * allowed drawing directions and a graphical shape to depict the terminal.\r
+ * </p>\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+public abstract class ObjectTerminal implements Terminal {\r
+\r
+    private static final Container<Shape> NO_SHAPE = new DataContainer<Shape>(null);\r
+\r
+    private final Object          data;\r
+    private final AffineTransform transform;\r
+    private final DirectionSet    ds;\r
+    private final Container<Shape> shape;\r
+\r
+    public ObjectTerminal(Object data, AffineTransform transform, DirectionSet ds, Container<Shape> shape) {\r
+        assert data != null;\r
+        this.data = data;\r
+        this.transform = transform;\r
+        this.ds = ds;\r
+        this.shape = shape != null ? shape : NO_SHAPE;\r
+    }\r
+\r
+    public ObjectTerminal(Object data, AffineTransform transform, DirectionSet ds, Shape shape) {\r
+        this(data, transform, ds, new DataContainer<Shape>(shape));\r
+    }\r
+\r
+    public ObjectTerminal(Object data, AffineTransform transform, DirectionSet ds) {\r
+        this(data, transform, ds, NO_SHAPE);\r
+    }\r
+\r
+    public ObjectTerminal(Object data, AffineTransform transform) {\r
+        this(data, transform, DirectionSet.ANY, NO_SHAPE);\r
+    }\r
+\r
+    public ObjectTerminal(Object data) {\r
+        this(data, new AffineTransform(), DirectionSet.ANY, NO_SHAPE);\r
+    }\r
+\r
+    @Override\r
+    public String toString() {\r
+        return getClass().getSimpleName() + "[" + data + ", " + transform + ", " + shape + "]";\r
+    }\r
+\r
+    @Override\r
+    public int hashCode() {\r
+        return data.hashCode();\r
+    }\r
+\r
+    @Override\r
+    public boolean equals(Object obj) {\r
+        if (this == obj)\r
+            return true;\r
+        if (obj == null || getClass() != obj.getClass())\r
+            return false;\r
+        ObjectTerminal other = (ObjectTerminal) obj;\r
+        return data.equals(other.data);\r
+    }\r
+\r
+    public Object getData() {\r
+        return data;\r
+    }\r
+\r
+    public AffineTransform getTransform() {\r
+        return transform;\r
+    }\r
+\r
+    public DirectionSet getDirections() {\r
+        return ds;\r
+    }\r
+\r
+    public Shape getShape() {\r
+        return shape.get();\r
+    }\r
+\r
+}
\ No newline at end of file