1 package org.simantics.district.network.ui.adapters;
\r
3 import java.awt.Dimension;
\r
4 import java.awt.geom.AffineTransform;
\r
5 import java.awt.geom.Rectangle2D;
\r
7 import org.simantics.district.network.ui.nodes.DistrictNetworkVertexNode;
\r
8 import org.simantics.g2d.element.ElementClass;
\r
9 import org.simantics.g2d.element.ElementUtils;
\r
10 import org.simantics.g2d.element.IElement;
\r
11 import org.simantics.g2d.element.SceneGraphNodeKey;
\r
12 import org.simantics.g2d.element.handler.InternalSize;
\r
13 import org.simantics.g2d.element.handler.SceneGraph;
\r
14 import org.simantics.g2d.element.handler.impl.DefaultTransform;
\r
15 import org.simantics.scenegraph.g2d.G2DParentNode;
\r
16 import org.simantics.utils.datastructures.hints.IHintContext.Key;
\r
17 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
\r
19 public class DistrictNetworkVertexElement {
\r
21 public static final Key KEY_DN_VERTEX = new KeyOf(DistrictNetworkVertex.class, "DN_VERTEX");
\r
22 public static final Key KEY_DN_VERTEX_NODE = new SceneGraphNodeKey(DistrictNetworkVertexNode.class, "DN_VERTEX_NODE");
\r
24 public static final ElementClass CLASS =
\r
25 ElementClass.compile(
\r
26 DefaultTransform.INSTANCE,
\r
27 DNVertexInternalSize.INSTANCE,
\r
28 DNVertexSceneGraph.INSTANCE
\r
29 ).setId(DistrictNetworkVertexElement.class.getSimpleName());
\r
31 static final class DNVertexSceneGraph implements SceneGraph {
\r
33 public static final DNVertexSceneGraph INSTANCE = new DNVertexSceneGraph();
\r
35 private static final long serialVersionUID = 8894367073815556871L;
\r
38 public void init(IElement edgeElement, G2DParentNode parent) {
\r
39 DistrictNetworkVertex vertex = edgeElement.getHint(KEY_DN_VERTEX);
\r
40 if (vertex == null) {
\r
41 cleanup(edgeElement);
\r
43 DistrictNetworkVertexNode node = edgeElement.getHint(KEY_DN_VERTEX_NODE);
\r
45 node = parent.addNode(ElementUtils.generateNodeId(edgeElement), DistrictNetworkVertexNode.class);
\r
46 edgeElement.setHint(KEY_DN_VERTEX_NODE, node);
\r
48 node.setVertex(vertex);
\r
50 AffineTransform at = ElementUtils.getTransform(edgeElement);
\r
52 node.setTransform(at);
\r
57 public void cleanup(IElement edge) {
\r
58 ElementUtils.removePossibleNode(edge, KEY_DN_VERTEX_NODE);
\r
59 edge.removeHint(KEY_DN_VERTEX_NODE);
\r
63 static final class DNVertexInternalSize implements InternalSize {
\r
65 public static final DNVertexInternalSize INSTANCE = new DNVertexInternalSize();
\r
67 private static final long serialVersionUID = 2625702114278956461L;
\r
70 public Rectangle2D getBounds(IElement e, Rectangle2D size) {
\r
72 size = new Rectangle2D.Double();
\r
73 size.setFrame(-0.5, -0.5, 1, 1);
\r