]> gerrit.simantics Code Review - simantics/district.git/blob
c19716469d243e81ce7f35ead2b7799310d49c46
[simantics/district.git] /
1 package org.simantics.district.network.ui.adapters;\r
2 \r
3 import java.awt.geom.AffineTransform;\r
4 \r
5 import org.simantics.db.AsyncReadGraph;\r
6 import org.simantics.db.ReadGraph;\r
7 import org.simantics.db.Resource;\r
8 import org.simantics.db.exception.DatabaseException;\r
9 import org.simantics.db.procedure.AsyncProcedure;\r
10 import org.simantics.diagram.adapter.SyncElementFactory;\r
11 import org.simantics.diagram.stubs.DiagramResource;\r
12 import org.simantics.district.network.ontology.DistrictNetworkResource;\r
13 import org.simantics.g2d.canvas.ICanvasContext;\r
14 import org.simantics.g2d.diagram.IDiagram;\r
15 import org.simantics.g2d.element.ElementClass;\r
16 import org.simantics.g2d.element.ElementUtils;\r
17 import org.simantics.g2d.element.IElement;\r
18 import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
19 \r
20 public class DistrictNetworkVertexElementFactory extends SyncElementFactory {\r
21 \r
22     public static final ElementClass CLASS = DistrictNetworkVertexElement.CLASS;\r
23     private DistrictNetworkResource DN;\r
24     private DiagramResource DIA;\r
25 \r
26     public DistrictNetworkVertexElementFactory(ReadGraph graph) {\r
27         this.DN = DistrictNetworkResource.getInstance(graph);\r
28         this.DIA = DiagramResource.getInstance(graph);\r
29     }\r
30 \r
31     @Override\r
32     public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure<ElementClass> procedure) {\r
33         procedure.execute(graph, CLASS.newClassWith(false, new StaticObjectAdapter(elementType)));\r
34     }\r
35 \r
36     @Override\r
37     protected Resource getElementClassBaseType(AsyncReadGraph graph) {\r
38         return DN.Vertex;\r
39     }\r
40 \r
41     @Override\r
42     public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource vertexResource, IElement element) throws DatabaseException {\r
43         \r
44         double[] coords = graph.getRelatedValue(vertexResource, DIA.HasLocation);\r
45         DistrictNetworkVertex vertex = new DistrictNetworkVertex(coords);\r
46         element.setHint(DistrictNetworkVertexElement.KEY_DN_VERTEX, vertex);\r
47         \r
48         // set element transform based on layer SRS and coords\r
49         AffineTransform at = new AffineTransform(1, 0, 0, 1, coords[0], coords[1]);\r
50         ElementUtils.setTransform(element, at);\r
51     }\r
52 }\r