]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.elementclass;\r
13 \r
14 import org.simantics.g2d.element.ElementClass.Single;\r
15 import org.simantics.g2d.element.IElement;\r
16 import org.simantics.g2d.element.handler.ElementHandler;\r
17 \r
18 /**\r
19  * A tagging element handler for telling whether an element can be considered a\r
20  * branch point of a connection.\r
21  * \r
22  * @author Tuukka Lehtonen\r
23  */\r
24 @Single\r
25 public interface BranchPoint extends ElementHandler {\r
26 \r
27     /**\r
28      * Pass-through direction preference for branch or specifically route\r
29      * points.\r
30      */\r
31     public enum Direction {\r
32         Any, Horizontal, Vertical;\r
33 \r
34         public static Direction toDirection(boolean horizontal, boolean vertical) {\r
35             if (horizontal && vertical)\r
36                 throw new IllegalArgumentException("branch point cannot be both horizontal and vertical");\r
37             if (horizontal)\r
38                 return Horizontal;\r
39             if (vertical)\r
40                 return Vertical;\r
41             return Any;\r
42         }\r
43 \r
44         public Direction toggleDetermined() {\r
45             switch (this) {\r
46                 case Horizontal: return Vertical;\r
47                 case Vertical: return Horizontal;\r
48             }\r
49             return Any;\r
50         }\r
51 \r
52         public Direction cycleNext() {\r
53             Direction[] dirs = values();\r
54             int newOrdinal = ordinal() + 1;\r
55             return dirs[newOrdinal >= dirs.length ? 0 : newOrdinal];\r
56         }\r
57 \r
58         public Direction cyclePrevious() {\r
59             Direction[] dirs = values();\r
60             int newOrdinal = ordinal() - 1;\r
61             return dirs[newOrdinal < 0 ? dirs.length - 1 : newOrdinal];\r
62         }\r
63     }\r
64 \r
65     /**\r
66      * Get the direction preference assigned for the specified branch point\r
67      * element.\r
68      * \r
69      * @param e the branch point element to get the direction preference from\r
70      * @param defaultValue this is returned if the element has no assigned\r
71      *        direction\r
72      * @return direction preference\r
73      */\r
74     Direction getDirectionPreference(IElement e, Direction defaultValue);\r
75 \r
76     /**\r
77      * Set the direction preference assigned for the specified branch point\r
78      * element.\r
79      * \r
80      * @param e the branch point element to get the direction preference from\r
81      * @param value the new direction preference\r
82      */\r
83     void setDirectionPreference(IElement e, Direction value);\r
84 \r
85 }\r