1 package org.simantics.district.network.ui.adapters;
3 import java.awt.geom.Rectangle2D;
4 import java.util.Collection;
5 import java.util.Collections;
7 import org.simantics.district.network.ui.DistrictNetworkEdge;
8 import org.simantics.district.network.ui.nodes.DistrictNetworkEdgeNode;
9 import org.simantics.g2d.connection.handler.ConnectionHandler;
10 import org.simantics.g2d.diagram.handler.Topology.Connection;
11 import org.simantics.g2d.element.ElementClass;
12 import org.simantics.g2d.element.ElementUtils;
13 import org.simantics.g2d.element.IElement;
14 import org.simantics.g2d.element.SceneGraphNodeKey;
15 import org.simantics.g2d.element.handler.InternalSize;
16 import org.simantics.g2d.element.handler.SceneGraph;
17 import org.simantics.g2d.element.handler.impl.DefaultTransform;
18 import org.simantics.g2d.element.handler.impl.SimpleElementLayers;
19 import org.simantics.scenegraph.g2d.G2DParentNode;
20 import org.simantics.utils.datastructures.hints.IHintContext.Key;
21 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class DistrictNetworkEdgeElement {
27 public static final Key KEY_DN_EDGE = new KeyOf(DistrictNetworkEdge.class, "DN_EDGE");
28 public static final Key KEY_DN_EDGE_NODE = new SceneGraphNodeKey(DistrictNetworkEdgeNode.class, "DN_EDGE_NODE");
30 public static final ElementClass CLASS =
32 DefaultTransform.INSTANCE,
33 DNEdgeInternalSize.INSTANCE,
34 DNEdgeSceneGraph.INSTANCE,
35 DNEdgeConnectionHandler.INSTANCE,
36 SimpleElementLayers.INSTANCE
37 ).setId(DistrictNetworkEdgeElement.class.getSimpleName());
39 static final class DNEdgeSceneGraph implements SceneGraph {
41 public static final DNEdgeSceneGraph INSTANCE = new DNEdgeSceneGraph();
43 private static final long serialVersionUID = 8894367073815556871L;
46 public void init(IElement edgeElement, G2DParentNode parent) {
47 DistrictNetworkEdge edge = edgeElement.getHint(KEY_DN_EDGE);
51 DistrictNetworkEdgeNode node = edgeElement.getHint(KEY_DN_EDGE_NODE);
53 node = parent.addNode(ElementUtils.generateNodeId(edgeElement), DistrictNetworkEdgeNode.class);
54 edgeElement.setHint(KEY_DN_EDGE_NODE, node);
61 public void cleanup(IElement edge) {
62 ElementUtils.removePossibleNode(edge, KEY_DN_EDGE_NODE);
63 edge.removeHint(KEY_DN_EDGE_NODE);
67 static final class DNEdgeInternalSize implements InternalSize {
69 private static final Logger LOGGER = LoggerFactory.getLogger(DNEdgeInternalSize.class);
71 private static final long serialVersionUID = -2725017034692179676L;
73 public static final DNEdgeInternalSize INSTANCE = new DNEdgeInternalSize();
76 public Rectangle2D getBounds(IElement e, Rectangle2D size) {
77 DistrictNetworkEdge edge = e.getHint(KEY_DN_EDGE);
79 size = new Rectangle2D.Double();
83 LOGGER.debug("Element {} does not have edge!", e);
90 static class DNEdgeConnectionHandler implements ConnectionHandler {
92 private static final long serialVersionUID = -410377314637446238L;
94 public static final DNEdgeConnectionHandler INSTANCE = new DNEdgeConnectionHandler();
97 public Collection<IElement> getChildren(IElement connection, Collection<IElement> result) {
98 return Collections.emptyList();
102 public Collection<IElement> getBranchPoints(IElement connection, Collection<IElement> result) {
103 return Collections.emptyList();
107 public Collection<IElement> getSegments(IElement connection, Collection<IElement> result) {
108 return Collections.emptyList();
112 public Collection<Connection> getTerminalConnections(IElement connection, Collection<Connection> result) {
113 return Collections.emptyList();