]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.maps/src/org/simantics/maps/eclipse/MapPainter.java
Optimization of district scene graph node rendering
[simantics/district.git] / org.simantics.district.maps / src / org / simantics / maps / eclipse / MapPainter.java
index ef88e1c55ea9fdf266506ffbcd82c41b6a75a954..5e989546723e2966866dcb5ea78d0683cc5d8efd 100644 (file)
@@ -23,7 +23,8 @@ import org.simantics.g2d.canvas.impl.SGNodeReflection.SGCleanup;
 import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;
 import org.simantics.g2d.participant.MouseUtil;
 import org.simantics.maps.sg.MapAttributionNode;
-import org.simantics.maps.sg.MapLocationZoomInfoNode;
+import org.simantics.maps.sg.MapInfoNode;
+import org.simantics.maps.sg.MapLocationInfoNode;
 import org.simantics.maps.sg.MapNode;
 import org.simantics.maps.sg.MapScaleNode;
 import org.simantics.maps.sg.commands.MapCommands;
@@ -76,13 +77,13 @@ public class MapPainter extends AbstractCanvasParticipant {
         }
     };
 
-    protected MapNode node = null;
-    protected MapScaleNode scaleNode = null;
+    private MapNode mapNode;
+    private MapLocationInfoNode locationInfoNode;
+    private MapScaleNode scaleNode;
+    private MapInfoNode attributionNode;
 
     private AffineTransform transform;
 
-    private MapLocationZoomInfoNode locationZoomInfoNode;
-
     private ScheduledFuture<?> schedule;
 
     public MapPainter(AffineTransform transform) {
@@ -139,7 +140,7 @@ public class MapPainter extends AbstractCanvasParticipant {
     public boolean handleEvent(Event e) {
         if (e instanceof MouseMovedEvent) {
             // here we should somehow re-render ?
-            if (locationZoomInfoNode.isEnabled()) {
+            if (locationInfoNode != null && locationInfoNode.isEnabled()) {
                 if (schedule == null || schedule.isDone()) {
                     LOGGER.debug("current setDirty time" + System.currentTimeMillis());
                     schedule = ThreadUtils.getNonBlockingWorkExecutor().schedule(() -> {
@@ -155,38 +156,42 @@ public class MapPainter extends AbstractCanvasParticipant {
 
     @SGInit
     public void initSG(G2DParentNode parent) {
-        node = parent.addNode("map", MapNode.class);
-        node.setTransform(transform);
-        node.setEnabled(true);
-        node.setZIndex(Integer.MIN_VALUE + 999); // Just under the grid
-        
+        // Just under the grid
+        mapNode = parent.addNode("map", MapNode.class);
+        mapNode.setTransform(transform);
+        mapNode.setEnabled(true);
+        mapNode.setZIndex(Integer.MIN_VALUE + 999);
+
+        // On top of pretty much everything
+        attributionNode = parent.addNode("mapAttribution", MapAttributionNode.class);
+        attributionNode.setTransform(transform);
+        attributionNode.setZIndex(Integer.MAX_VALUE - 999);
+        attributionNode.setEnabled(true);
+
         scaleNode = parent.addNode("mapScale", MapScaleNode.class);
         scaleNode.setTransform(transform);
+        scaleNode.setZIndex(Integer.MAX_VALUE - 998);
         scaleNode.setEnabled(true);
-        scaleNode.setZIndex(Integer.MAX_VALUE - 999); // Just under the grid
-        
-        locationZoomInfoNode = parent.addNode("locationZoomInfo", MapLocationZoomInfoNode.class);
-        locationZoomInfoNode.setTransform(transform);
-        locationZoomInfoNode.setEnabled(true);
-        MouseUtil mouseUtil = getContext().getAtMostOneItemOfClass(MouseUtil.class);
-        locationZoomInfoNode.setMouseUtil(mouseUtil);
-        locationZoomInfoNode.setZIndex(Integer.MAX_VALUE - 999); // Just under the grid
-        
-        MapAttributionNode addNode = parent.addNode("mapAttribution", MapAttributionNode.class);
-        addNode.setTransform(transform);
-        addNode.setEnabled(true);
-        addNode.setZIndex(Integer.MAX_VALUE - 999);
+
+        locationInfoNode = parent.addNode("mapLocationInfo", MapLocationInfoNode.class);
+        locationInfoNode.setTransform(transform);
+        locationInfoNode.setZIndex(Integer.MAX_VALUE - 997);
+        locationInfoNode.setEnabled(true);
+        locationInfoNode.setMouseUtil(getContext().getAtMostOneItemOfClass(MouseUtil.class));
     }
 
     @SGCleanup
     public void cleanupSG() {
-        node.remove();
+        mapNode.remove();
+        attributionNode.remove();
+        scaleNode.remove();
+        locationInfoNode.remove();
     }
 
     protected void updateNode() {
-        node.setEnabled(isPaintingEnabled());
-        node.setEnabled(isMapEnabled());
-        node.setBackgroundColor(getBackgroundColor());
+        mapNode.setEnabled(isPaintingEnabled());
+        mapNode.setEnabled(isMapEnabled());
+        mapNode.setBackgroundColor(getBackgroundColor());
     }
 
     boolean isPaintingEnabled() {