]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/BranchPoint.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / elementclass / BranchPoint.java
diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/BranchPoint.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/BranchPoint.java
new file mode 100644 (file)
index 0000000..62e0a37
--- /dev/null
@@ -0,0 +1,85 @@
+/*******************************************************************************\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.elementclass;\r
+\r
+import org.simantics.g2d.element.ElementClass.Single;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.ElementHandler;\r
+\r
+/**\r
+ * A tagging element handler for telling whether an element can be considered a\r
+ * branch point of a connection.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+@Single\r
+public interface BranchPoint extends ElementHandler {\r
+\r
+    /**\r
+     * Pass-through direction preference for branch or specifically route\r
+     * points.\r
+     */\r
+    public enum Direction {\r
+        Any, Horizontal, Vertical;\r
+\r
+        public static Direction toDirection(boolean horizontal, boolean vertical) {\r
+            if (horizontal && vertical)\r
+                throw new IllegalArgumentException("branch point cannot be both horizontal and vertical");\r
+            if (horizontal)\r
+                return Horizontal;\r
+            if (vertical)\r
+                return Vertical;\r
+            return Any;\r
+        }\r
+\r
+        public Direction toggleDetermined() {\r
+            switch (this) {\r
+                case Horizontal: return Vertical;\r
+                case Vertical: return Horizontal;\r
+            }\r
+            return Any;\r
+        }\r
+\r
+        public Direction cycleNext() {\r
+            Direction[] dirs = values();\r
+            int newOrdinal = ordinal() + 1;\r
+            return dirs[newOrdinal >= dirs.length ? 0 : newOrdinal];\r
+        }\r
+\r
+        public Direction cyclePrevious() {\r
+            Direction[] dirs = values();\r
+            int newOrdinal = ordinal() - 1;\r
+            return dirs[newOrdinal < 0 ? dirs.length - 1 : newOrdinal];\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Get the direction preference assigned for the specified branch point\r
+     * element.\r
+     * \r
+     * @param e the branch point element to get the direction preference from\r
+     * @param defaultValue this is returned if the element has no assigned\r
+     *        direction\r
+     * @return direction preference\r
+     */\r
+    Direction getDirectionPreference(IElement e, Direction defaultValue);\r
+\r
+    /**\r
+     * Set the direction preference assigned for the specified branch point\r
+     * element.\r
+     * \r
+     * @param e the branch point element to get the direction preference from\r
+     * @param value the new direction preference\r
+     */\r
+    void setDirectionPreference(IElement e, Direction value);\r
+\r
+}\r