]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/handler/Topology.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / diagram / handler / Topology.java
diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/handler/Topology.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/handler/Topology.java
new file mode 100644 (file)
index 0000000..6a2851b
--- /dev/null
@@ -0,0 +1,125 @@
+/*******************************************************************************\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.diagram.handler;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.g2d.diagram.handler.impl.TopologyImpl;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.EdgeVisuals.EdgeEnd;\r
+import org.simantics.g2d.element.handler.TerminalTopology;\r
+import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
+\r
+/**\r
+ * \r
+ * TODO Remove Connection. Replace with Individual hints.\r
+ * \r
+ * @see TopologyImpl Default implementation.\r
+ * @author Toni Kalajainen\r
+ */\r
+public interface Topology extends DiagramHandler {\r
+\r
+    /**\r
+     * @See TerminalImpl\r
+     * @see ObjectTerminal\r
+     */\r
+    public interface Terminal {}\r
+\r
+    /**\r
+     * @param edge\r
+     * @param end Begin or End\r
+     * @return <code>null</code> if the specified end of the specified edge is\r
+     *         not connected\r
+     */\r
+    Connection getConnection(IElement edge, EdgeEnd end);\r
+\r
+    /**\r
+     * Get all the connections attached to the specified terminal of the\r
+     * specified node.\r
+     * \r
+     * @param node\r
+     * @param terminal\r
+     * @param connections\r
+     */\r
+    void getConnections(IElement node, Terminal terminal, Collection<Connection> connections);\r
+\r
+    /**\r
+     * Connect one end of a connection to an element terminal.\r
+     * \r
+     * @param edge the edge to connect to the specified node, must belong to the\r
+     *        same diagram as the node\r
+     * @param end\r
+     * @param node the node to connect to the specified edge, must belong to the\r
+     *        same diagram as the edge\r
+     * @param terminal a terminal of node, retrieved using {@link TerminalTopology}\r
+     */\r
+    void connect(IElement edge, EdgeEnd end, IElement node, Terminal terminal);\r
+\r
+    /**\r
+     * Disconnect one end of a connection from an element terminal.\r
+     * \r
+     * @param edge the edge to connect to the specified node, must belong to the\r
+     *        same diagram as the node\r
+     * @param end the end of the edge to disconnect\r
+     * @param node the node to disconnect the specified edge from. Must belong to the\r
+     *        same diagram as the edge.\r
+     * @param terminal a terminal of node, retrieved using {@link TerminalTopology}\r
+     */\r
+    void disconnect(IElement edge, EdgeEnd end, IElement node, Terminal terminal);\r
+\r
+    /**\r
+     * A hint value class for representing a single edge end to node terminal\r
+     * connection.\r
+     */\r
+    public static class Connection {\r
+        public final Terminal terminal;\r
+        public final IElement edge;\r
+        public final IElement node;\r
+        public final EdgeEnd  end;\r
+        public Connection(IElement edge, EdgeEnd end, IElement node, Terminal terminal) {\r
+            assert edge != null;\r
+            assert end != null;\r
+            assert (terminal == null && node == null) || (node != null && terminal != null);\r
+            this.edge = edge;\r
+            this.end = end;\r
+            this.node = node;\r
+            this.terminal = terminal;\r
+        }\r
+        @Override\r
+        public boolean equals(Object obj) {\r
+            if (this == obj)\r
+                return true;\r
+            if (!(obj instanceof Connection))\r
+                return false;\r
+            Connection other = (Connection) obj;\r
+            return other.terminal == terminal &&\r
+            other.edge == edge &&\r
+            other.node == node &&\r
+            other.end == end;\r
+        }\r
+        @Override\r
+        public int hashCode() {\r
+            final int prime = 31;\r
+            int result = 1;\r
+            result = prime * result + edge.hashCode();\r
+            result = prime * result + end.hashCode();\r
+            result = prime * result + ((node == null) ? 0 : node.hashCode());\r
+            result = prime * result + ((terminal == null) ? 0 : terminal.hashCode());\r
+            return result;\r
+        }\r
+        @Override\r
+        public String toString() {\r
+            return "Topology.Connection[edge=" + edge + ", node=" + node + ", terminal=" + terminal + ", end=" + end + "]";\r
+        }\r
+    }\r
+\r
+}\r