1 package org.simantics.district.network.ui.adapters;
\r
3 import java.awt.geom.Rectangle2D;
\r
5 import org.simantics.district.network.ui.DistrictNetworkEdge;
\r
6 import org.simantics.district.network.ui.nodes.DistrictNetworkEdgeNode;
\r
7 import org.simantics.g2d.element.ElementClass;
\r
8 import org.simantics.g2d.element.ElementUtils;
\r
9 import org.simantics.g2d.element.IElement;
\r
10 import org.simantics.g2d.element.SceneGraphNodeKey;
\r
11 import org.simantics.g2d.element.handler.InternalSize;
\r
12 import org.simantics.g2d.element.handler.SceneGraph;
\r
13 import org.simantics.g2d.element.handler.impl.DefaultTransform;
\r
14 import org.simantics.scenegraph.g2d.G2DParentNode;
\r
15 import org.simantics.utils.datastructures.hints.IHintContext.Key;
\r
16 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
\r
18 public class DistrictNetworkEdgeElement {
\r
20 public static final Key KEY_DN_EDGE = new KeyOf(DistrictNetworkEdge.class, "DN_EDGE");
\r
21 public static final Key KEY_DN_EDGE_NODE = new SceneGraphNodeKey(DistrictNetworkEdgeNode.class, "DN_EDGE_NODE");
\r
23 public static final ElementClass CLASS =
\r
24 ElementClass.compile(
\r
25 DefaultTransform.INSTANCE,
\r
26 DNEdgeInternalSize.INSTANCE,
\r
27 DNEdgeSceneGraph.INSTANCE
\r
28 ).setId(DistrictNetworkEdgeElement.class.getSimpleName());
\r
30 static final class DNEdgeSceneGraph implements SceneGraph {
\r
32 public static final DNEdgeSceneGraph INSTANCE = new DNEdgeSceneGraph();
\r
34 private static final long serialVersionUID = 8894367073815556871L;
\r
37 public void init(IElement edgeElement, G2DParentNode parent) {
\r
38 DistrictNetworkEdge edge = edgeElement.getHint(KEY_DN_EDGE);
\r
40 cleanup(edgeElement);
\r
42 DistrictNetworkEdgeNode node = edgeElement.getHint(KEY_DN_EDGE_NODE);
\r
44 node = parent.addNode(ElementUtils.generateNodeId(edgeElement), DistrictNetworkEdgeNode.class);
\r
45 edgeElement.setHint(KEY_DN_EDGE_NODE, node);
\r
47 node.setDNEdge(edge);
\r
52 public void cleanup(IElement edge) {
\r
53 ElementUtils.removePossibleNode(edge, KEY_DN_EDGE_NODE);
\r
54 edge.removeHint(KEY_DN_EDGE_NODE);
\r
58 static final class DNEdgeInternalSize implements InternalSize {
\r
60 private static final long serialVersionUID = -2725017034692179676L;
\r
62 public static final DNEdgeInternalSize INSTANCE = new DNEdgeInternalSize();
\r
65 public Rectangle2D getBounds(IElement e, Rectangle2D size) {
\r
66 DistrictNetworkEdge edge = e.getHint(KEY_DN_EDGE);
\r
68 size = new Rectangle2D.Double();
\r
69 edge.getBounds(size);
\r