]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/BranchPoint.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / elementclass / BranchPoint.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g2d.elementclass;
13
14 import org.simantics.g2d.element.ElementClass.Single;
15 import org.simantics.g2d.element.IElement;
16 import org.simantics.g2d.element.handler.ElementHandler;
17
18 /**
19  * A tagging element handler for telling whether an element can be considered a
20  * branch point of a connection.
21  * 
22  * @author Tuukka Lehtonen
23  */
24 @Single
25 public interface BranchPoint extends ElementHandler {
26
27     /**
28      * Pass-through direction preference for branch or specifically route
29      * points.
30      */
31     public enum Direction {
32         Any, Horizontal, Vertical;
33
34         public static Direction toDirection(boolean horizontal, boolean vertical) {
35             if (horizontal && vertical)
36                 throw new IllegalArgumentException("branch point cannot be both horizontal and vertical");
37             if (horizontal)
38                 return Horizontal;
39             if (vertical)
40                 return Vertical;
41             return Any;
42         }
43
44         public Direction toggleDetermined() {
45             switch (this) {
46                 case Horizontal: return Vertical;
47                 case Vertical: return Horizontal;
48             }
49             return Any;
50         }
51
52         public Direction cycleNext() {
53             Direction[] dirs = values();
54             int newOrdinal = ordinal() + 1;
55             return dirs[newOrdinal >= dirs.length ? 0 : newOrdinal];
56         }
57
58         public Direction cyclePrevious() {
59             Direction[] dirs = values();
60             int newOrdinal = ordinal() - 1;
61             return dirs[newOrdinal < 0 ? dirs.length - 1 : newOrdinal];
62         }
63     }
64
65     /**
66      * Get the direction preference assigned for the specified branch point
67      * element.
68      * 
69      * @param e the branch point element to get the direction preference from
70      * @param defaultValue this is returned if the element has no assigned
71      *        direction
72      * @return direction preference
73      */
74     Direction getDirectionPreference(IElement e, Direction defaultValue);
75
76     /**
77      * Set the direction preference assigned for the specified branch point
78      * element.
79      * 
80      * @param e the branch point element to get the direction preference from
81      * @param value the new direction preference
82      */
83     void setDirectionPreference(IElement e, Direction value);
84
85 }