1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011, 2014 Association for Decentralized Information Management in
\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.sysdyn.ui.elements.connections;
\r
14 import java.util.ArrayList;
\r
15 import java.util.List;
\r
17 import org.simantics.diagram.connection.RouteGraph;
\r
18 import org.simantics.diagram.connection.RouteGraphConnectionClass;
\r
19 import org.simantics.diagram.connection.rendering.IRouteGraphRenderer;
\r
20 import org.simantics.g2d.element.ElementClass;
\r
21 import org.simantics.g2d.element.ElementUtils;
\r
22 import org.simantics.g2d.element.IElement;
\r
23 import org.simantics.g2d.element.handler.ElementHandler;
\r
24 import org.simantics.g2d.element.handler.SceneGraph;
\r
25 import org.simantics.scenegraph.g2d.G2DParentNode;
\r
26 import org.simantics.scenegraph.g2d.nodes.connection.IRouteGraphListener;
\r
29 public class RouteFlowEdgeClass extends RouteGraphConnectionClass {
\r
31 public static final ElementClass FLOW_CLASS = getElementClass();
\r
34 public static final ElementClass getElementClass() {
\r
35 List<ElementHandler> oldList = CLASS.getAll();
\r
36 ArrayList<ElementHandler> list = new ArrayList<ElementHandler>();
\r
37 list.add(FlowConnectionSceneGraph.INSTANCE);
\r
38 for(ElementHandler eh : oldList) {
\r
39 if(!(eh instanceof SceneGraph)) {
\r
43 return ElementClass.compile(list);
\r
47 static final class FlowConnectionSceneGraph implements SceneGraph {
\r
49 public static final FlowConnectionSceneGraph INSTANCE = new FlowConnectionSceneGraph();
\r
51 private static final long serialVersionUID = 1865920472882420644L;
\r
54 public void init(IElement connection, G2DParentNode parent) {
\r
55 RouteGraph rg = connection.getHint(KEY_ROUTEGRAPH);
\r
56 IRouteGraphRenderer renderer = connection.getHint(KEY_RENDERER);
\r
57 if (rg == null || renderer == null) {
\r
58 cleanup(connection);
\r
60 RouteFlowNode rgn = ElementUtils.getOrCreateNode(connection, parent, KEY_RG_NODE, "flow_" + connection.hashCode(), RouteFlowNode.class);
\r
61 rgn.setRouteGraph(rg);
\r
62 rgn.setRenderer(renderer);
\r
64 IRouteGraphListener listener = connection.getHint(KEY_RG_LISTENER);
\r
65 rgn.setRouteGraphListener(listener);
\r
67 Double tolerance = connection.getHint(KEY_PICK_TOLERANCE);
\r
68 if (tolerance != null)
\r
69 rgn.setPickTolerance(tolerance);
\r
74 public void cleanup(IElement connection) {
\r
75 ElementUtils.removePossibleNode(connection, KEY_RG_NODE);
\r
76 connection.removeHint(KEY_RG_NODE);
\r