1 package org.simantics.district.network.ui.adapters;
3 import java.awt.geom.AffineTransform;
4 import java.awt.geom.Rectangle2D;
6 import org.simantics.district.network.ui.nodes.DistrictNetworkVertexNode;
7 import org.simantics.g2d.element.ElementClass;
8 import org.simantics.g2d.element.ElementUtils;
9 import org.simantics.g2d.element.IElement;
10 import org.simantics.g2d.element.SceneGraphNodeKey;
11 import org.simantics.g2d.element.handler.InternalSize;
12 import org.simantics.g2d.element.handler.SceneGraph;
13 import org.simantics.g2d.element.handler.impl.DefaultTransform;
14 import org.simantics.g2d.element.handler.impl.SimpleElementLayers;
15 import org.simantics.scenegraph.g2d.G2DParentNode;
16 import org.simantics.utils.datastructures.hints.IHintContext.Key;
17 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
19 public class DistrictNetworkVertexElement {
21 public static final Key KEY_DN_VERTEX = new KeyOf(DistrictNetworkVertex.class, "DN_VERTEX");
22 public static final Key KEY_DN_VERTEX_NODE = new SceneGraphNodeKey(DistrictNetworkVertexNode.class, "DN_VERTEX_NODE");
24 public static final ElementClass CLASS =
26 DefaultTransform.INSTANCE,
27 DNVertexInternalSize.INSTANCE,
28 DNVertexSceneGraph.INSTANCE,
29 SimpleElementLayers.INSTANCE
30 ).setId(DistrictNetworkVertexElement.class.getSimpleName());
32 static final class DNVertexSceneGraph implements SceneGraph {
34 public static final DNVertexSceneGraph INSTANCE = new DNVertexSceneGraph();
36 private static final long serialVersionUID = 8894367073815556871L;
39 public void init(IElement edgeElement, G2DParentNode parent) {
40 DistrictNetworkVertex vertex = edgeElement.getHint(KEY_DN_VERTEX);
44 DistrictNetworkVertexNode node = edgeElement.getHint(KEY_DN_VERTEX_NODE);
46 node = parent.addNode(ElementUtils.generateNodeId(edgeElement), DistrictNetworkVertexNode.class);
47 edgeElement.setHint(KEY_DN_VERTEX_NODE, node);
49 node.setVertex(vertex);
51 AffineTransform at = ElementUtils.getTransform(edgeElement);
53 node.setTransform(at);
58 public void cleanup(IElement edge) {
59 ElementUtils.removePossibleNode(edge, KEY_DN_VERTEX_NODE);
60 edge.removeHint(KEY_DN_VERTEX_NODE);
64 static final class DNVertexInternalSize implements InternalSize {
66 public static final DNVertexInternalSize INSTANCE = new DNVertexInternalSize();
68 private static final long serialVersionUID = 2625702114278956461L;
71 public Rectangle2D getBounds(IElement e, Rectangle2D size) {
73 size = new Rectangle2D.Double();
74 size.setFrame(-0.5, -0.5, 1, 1);