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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g2d.elementclass;
\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
19 * A tagging element handler for telling whether an element can be considered a
\r
20 * branch point of a connection.
\r
22 * @author Tuukka Lehtonen
\r
25 public interface BranchPoint extends ElementHandler {
\r
28 * Pass-through direction preference for branch or specifically route
\r
31 public enum Direction {
\r
32 Any, Horizontal, Vertical;
\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
44 public Direction toggleDetermined() {
\r
46 case Horizontal: return Vertical;
\r
47 case Vertical: return Horizontal;
\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
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
66 * Get the direction preference assigned for the specified branch point
\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
72 * @return direction preference
\r
74 Direction getDirectionPreference(IElement e, Direction defaultValue);
\r
77 * Set the direction preference assigned for the specified branch point
\r
80 * @param e the branch point element to get the direction preference from
\r
81 * @param value the new direction preference
\r
83 void setDirectionPreference(IElement e, Direction value);
\r