]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Move state changes away from render method to refresh method
authorJussi Koskela <jussi.koskela@semantum.fi>
Wed, 24 Oct 2018 11:52:35 +0000 (14:52 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 14 Nov 2018 12:13:38 +0000 (14:13 +0200)
Backwards compatibility is preserved by calling refresh for each node at
the beginning of rendering. This is performed automatically in
G2DSceneGraph.render contrary to original requirement. This change is
required to support external diagram renderers.

Change-Id: I5d91ee97b0c9527f6d4ba562089ffaebdbc01ce0
(cherry picked from commit 512d469c3e490cdfc9a10fbbd6efe92ae6c0358a)

bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextGridNode.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DNode.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DParentNode.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DSceneGraph.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNode.java

index be0f23a590f62bb2a5009641a77d30b2847cd6ae..20d419ef089cb4690046de362a14755d258881e4 100644 (file)
@@ -265,13 +265,13 @@ public class TextGridNode extends G2DParentNode implements Decoration {
     }
     
     @Override
-    public void render(Graphics2D g2d) {
-       Vec2d delta = getDelta(FACTOR);
-       if(delta != null)
-               setTransform(AffineTransform.getTranslateInstance(delta.x, delta.y-2.1*computeRows()*(up ? 1.0 : 0.0)));
-       else
-               setTransform(AffineTransform.getTranslateInstance(0, -2.1*computeRows()*(up ? 1.0 : 0.0)));
-        super.render(g2d);
+    public void refresh() {
+        Vec2d delta = getDelta(FACTOR);
+        if(delta != null)
+            setTransform(AffineTransform.getTranslateInstance(delta.x, delta.y-2.1*computeRows()*(up ? 1.0 : 0.0)));
+        else
+            setTransform(AffineTransform.getTranslateInstance(0, -2.1*computeRows()*(up ? 1.0 : 0.0)));
+        super.refresh();
     }
     
     @Override
index b39d7a0582167f7b6222a550b44c4d5954769ca9..477b95517cfb26d6aaa95347ccc6bed4285dd394 100644 (file)
@@ -69,6 +69,10 @@ public abstract class G2DNode extends Node implements IG2DNode {
        return true;
     }
     
+    @Override
+    public void refresh() {
+    }
+
     @Override
     public void cleanup() {
         retractMapping();
index 838eb893e52b392b78a8796adf4e6e10e17fd7cc..de4631e770187c8db2f1a372776a8aea9175797d 100644 (file)
@@ -122,6 +122,15 @@ public class G2DParentNode extends ParentNode<IG2DNode> implements IG2DNode, Ini
             g2d.setTransform(ot);
     }
 
+    @Override
+    public void refresh() {
+        for (IG2DNode node : getSortedNodes()) {
+            if (node.validate()) {
+                node.refresh();
+            }
+        }
+    }
+
     @Override
     public void accept(IG2DNodeVisitor visitor) {
         visitor.enter(this);
@@ -602,4 +611,5 @@ public class G2DParentNode extends ParentNode<IG2DNode> implements IG2DNode, Ini
        public void synchronizeTransform(double[] data) {
                this.setTransform(new AffineTransform(data));
        }
+
 }
index 204181c3786fe01631e4b333cce06a7e681bdfd3..9055a8efeca37c1c4822558b77c6ab1c36d242cb 100644 (file)
@@ -105,9 +105,9 @@ public class G2DSceneGraph extends G2DParentNode implements ILookupService, INod
         return focusNode;
     }
 
-    @Override
+    @Override    
     public void render(Graphics2D g2d) {
-        performCleanup();
+        refresh();
         Component rootPane = getRootPane();
         if (rootPane != null)
             g2d.setRenderingHint(G2DRenderingHints.KEY_COMPONENT, rootPane);
@@ -116,6 +116,12 @@ public class G2DSceneGraph extends G2DParentNode implements ILookupService, INod
         }
     }
 
+    @Override
+    public void refresh() {
+        performCleanup();
+        super.refresh();
+    }
+
     /**
      * Util method for executing updates to scenegraph tree
      * NOTE: You should really consider performance issues when using this
index e181d59ff02d45305da28dbbac3cb7802be5b002..2d17e47c594fbc2ad546106a2a0d6c9777bd7d95 100644 (file)
@@ -50,8 +50,9 @@ public interface IG2DNode extends INode, IEventHandler {
     public boolean validate();
 
     /**
-     * Perform the actual rendering. Node state changes should be avoided in
-     * this method. This method should not change the transform of the g2d
+     * Perform the actual rendering. Node state changes must be avoided in
+     * this method. Implement node state changes to refresh method instead. 
+     * This method should not change the transform of the g2d
      * instance. You should call g2d.create or copy the original transform and
      * put it back at the end of this method according to what is specified in
      * {@link Graphics2D#setTransform(AffineTransform)}.
@@ -70,7 +71,12 @@ public interface IG2DNode extends INode, IEventHandler {
      * @see #getTransform()
      */
     public void render(Graphics2D g2d);
-
+    
+    /**
+     * Refresh the node state.  
+     */
+    public void refresh();
+    
     /**
      * Visit the IG2DNode substructure of this node using the provided visitor.
      *