]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AddModule.java
Small but effective HiDPI fixes for platform G2D
[simantics/platform.git] / bundles / org.simantics.modeling.tests / src / org / simantics / modeling / tests / commands / AddModule.java
1 package org.simantics.modeling.tests.commands;
2
3 import org.simantics.databoard.Bindings;
4 import org.simantics.db.Resource;
5 import org.simantics.db.WriteGraph;
6 import org.simantics.db.common.utils.OrderedSetUtils;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.diagram.stubs.DiagramResource;
9 import org.simantics.diagram.stubs.G2DResource;
10 import org.simantics.diagram.synchronization.graph.AddElement;
11 import org.simantics.layer0.Layer0;
12 import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
13 import org.simantics.modeling.tests.traits.SingleResourceTrait;
14 import org.simantics.modeling.tests.traits.SingleResourceTraitImpl;
15
16
17 public class AddModule extends ResourceWriteCommand<ModelingCommandSequenceTest> implements SingleResourceTrait {
18
19         private AddDiagram diagram;
20         private SingleResourceTrait type;
21         private double x,y;
22         
23         public AddModule(AddDiagram diagram, SingleResourceTrait type, double x, double y) {
24                 this.diagram = diagram;
25                 this.type = type;
26                 this.x = x;
27                 this.y = y;
28         }
29         
30         public AddModule(AddDiagram diagram, Resource type, double x, double y) {
31                 this.diagram = diagram;
32                 this.type = new SingleResourceTraitImpl(type);
33                 this.x = x;
34                 this.y = y;
35         }
36
37         @Override
38         protected Resource run(WriteGraph graph, ModelingCommandSequenceTest environment) throws DatabaseException {
39                 
40                 Layer0 L0 = Layer0.getInstance(graph);
41         DiagramResource DIA = DiagramResource.getInstance(graph);
42         G2DResource G2D = G2DResource.getInstance(graph);
43                 
44                 Resource diagramResource = diagram.getResource();
45                 
46                 // Diagram
47         Resource resource = graph.newResource();
48         graph.claim(resource, L0.InstanceOf, null, type.getResource(graph));
49         graph.claimLiteral(resource, DIA.HasTransform, G2D.Transform, new double[] { 1, 0, 0, 1, x, y }, Bindings.DOUBLE_ARRAY);
50         graph.claim(resource, L0.PartOf, diagramResource);
51
52                 AddElement.claimFreshElementName(graph, diagramResource, resource);
53         OrderedSetUtils.addFirst(graph, diagramResource, resource);
54         
55         return resource;
56         
57         }
58         
59 }