1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.elementclass;
14 import org.simantics.g2d.element.ElementClass.Single;
15 import org.simantics.g2d.element.IElement;
16 import org.simantics.g2d.element.handler.ElementHandler;
19 * A tagging element handler for telling whether an element can be considered a
20 * branch point of a connection.
22 * @author Tuukka Lehtonen
25 public interface BranchPoint extends ElementHandler {
28 * Pass-through direction preference for branch or specifically route
31 public enum Direction {
32 Any, Horizontal, Vertical;
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");
44 public Direction toggleDetermined() {
46 case Horizontal: return Vertical;
47 case Vertical: return Horizontal;
52 public Direction cycleNext() {
53 Direction[] dirs = values();
54 int newOrdinal = ordinal() + 1;
55 return dirs[newOrdinal >= dirs.length ? 0 : newOrdinal];
58 public Direction cyclePrevious() {
59 Direction[] dirs = values();
60 int newOrdinal = ordinal() - 1;
61 return dirs[newOrdinal < 0 ? dirs.length - 1 : newOrdinal];
66 * Get the direction preference assigned for the specified branch point
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
72 * @return direction preference
74 Direction getDirectionPreference(IElement e, Direction defaultValue);
77 * Set the direction preference assigned for the specified branch point
80 * @param e the branch point element to get the direction preference from
81 * @param value the new direction preference
83 void setDirectionPreference(IElement e, Direction value);