From: Jussi Koskela Date: Wed, 24 Oct 2018 11:52:35 +0000 (+0300) Subject: Move state changes away from render method to refresh method X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=a751855733efc30766b1cd0be1c3b37598f16851;p=simantics%2Fplatform.git Move state changes away from render method to refresh method 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 --- diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextGridNode.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextGridNode.java index f482890e9..1d18aa43e 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextGridNode.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextGridNode.java @@ -264,13 +264,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 diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DNode.java index b39d7a058..477b95517 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DNode.java @@ -69,6 +69,10 @@ public abstract class G2DNode extends Node implements IG2DNode { return true; } + @Override + public void refresh() { + } + @Override public void cleanup() { retractMapping(); diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DParentNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DParentNode.java index 838eb893e..de4631e77 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DParentNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DParentNode.java @@ -122,6 +122,15 @@ public class G2DParentNode extends ParentNode 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 implements IG2DNode, Ini public void synchronizeTransform(double[] data) { this.setTransform(new AffineTransform(data)); } + } diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DSceneGraph.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DSceneGraph.java index 204181c37..9055a8efe 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DSceneGraph.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DSceneGraph.java @@ -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 diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNode.java index e181d59ff..2d17e47c5 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNode.java @@ -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. *