-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.scenegraph.g2d.nodes;\r
-\r
-import java.awt.BasicStroke;\r
-import java.awt.Color;\r
-import java.awt.Graphics2D;\r
-import java.awt.Shape;\r
-import java.awt.geom.AffineTransform;\r
-import java.awt.geom.Rectangle2D;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.scenegraph.g2d.IG2DNode;\r
-\r
-/**\r
- * \r
- * Holder node that scales content to fit (and scales SVG inside those bounds)\r
- * \r
- * @author jplaine\r
- *\r
- */\r
-public class SVGHolderNode extends G2DParentNode {\r
- /**\r
- * \r
- */\r
- private static final long serialVersionUID = 8698435757824280001L;\r
-\r
- protected Rectangle2D bounds = null;\r
- protected Float borderWidth = null;\r
- \r
- \r
- @PropertySetter("VariableFilter")\r
- public void setScript(String script) {\r
- for(IG2DNode node : getSortedNodes()) // Pass value to children\r
- if(node instanceof AnimatedSVGNode) {\r
- ((AnimatedSVGNode)node).setScript(script);\r
- }\r
- }\r
- \r
- @PropertySetter("SVG")\r
- public void setData(String data) {\r
- for(IG2DNode node : getSortedNodes()) // Pass value to children\r
- if(node instanceof AnimatedSVGNode) {\r
- ((AnimatedSVGNode)node).setData(data);\r
- }\r
- }\r
-\r
- @PropertySetter("Stroke Width")\r
- @SyncField("border")\r
- public void setBorderWidth(Float borderWidth) {\r
- this.borderWidth = borderWidth;\r
- }\r
-\r
- @PropertySetter("Bounds")\r
- @SyncField("bounds")\r
- public void setBounds(Rectangle2D bounds) {\r
- this.bounds = bounds;\r
- }\r
-\r
- @Override\r
- public void render(Graphics2D g2d) {\r
- Rectangle2D cb = getBoundsInLocal(false);\r
- double scaleX = bounds.getWidth() / cb.getWidth();\r
- double scaleY = bounds.getHeight() / cb.getHeight();\r
- double scale = Math.min(scaleX, scaleY);\r
-\r
- if(borderWidth != null && borderWidth > 0.0f && bounds != null) {\r
- Graphics2D g2 = (Graphics2D)g2d.create();\r
- g2.transform(transform);\r
- g2.setStroke(new BasicStroke(this.borderWidth));\r
- g2.setColor(Color.BLACK);\r
- g2.draw(bounds);\r
- g2.dispose();\r
- }\r
-\r
- @SuppressWarnings("unused")\r
- int noBounds = 0;\r
- @SuppressWarnings("unused")\r
- int clipped = 0;\r
- @SuppressWarnings("unused")\r
- int rendered = 0;\r
-\r
- AffineTransform ot = g2d.getTransform();\r
- g2d.transform(transform);\r
-\r
- g2d.translate(-cb.getMinX()*scale+bounds.getMinX(), -cb.getMinY()*scale+bounds.getMinY());\r
- g2d.scale(scale, scale);\r
-\r
- // Get transformed clip bounds\r
- Shape clipShape = g2d.getClip();\r
- Rectangle2D bounds = null;\r
- if (clipShape instanceof Rectangle2D)\r
- bounds = (Rectangle2D) clipShape;\r
- else if (clipShape != null)\r
- bounds = clipShape.getBounds2D();\r
-\r
- boolean noClipBounds = bounds == null;\r
-\r
- for(IG2DNode node : getSortedNodes()) {\r
- Rectangle2D localBounds = node.getBoundsInLocal();\r
- boolean hasNoBounds = localBounds == null;\r
- boolean visible = false;\r
- if (!noClipBounds && !hasNoBounds) {\r
- visible = node.intersects(bounds);\r
- } else {\r
- ++noBounds;\r
- }\r
- if (noClipBounds || hasNoBounds || visible) {\r
- // TODO: consider removing this g2d.create ?\r
- // Will definitely current cause bugs to appear.\r
- if (node.validate()) {\r
- node.render(g2d);\r
- }\r
- ++rendered;\r
- } else {\r
- ++clipped;\r
- }\r
- }\r
-\r
- g2d.setTransform(ot);\r
- }\r
-\r
- @Override\r
- public Rectangle2D getBoundsInLocal() {\r
- return bounds; // FIXME: not sure if it's a good idea to return different value than the getBoundsInLocal(boolean nulls) returns..\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.scenegraph.g2d.nodes;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scenegraph.g2d.IG2DNode;
+
+/**
+ *
+ * Holder node that scales content to fit (and scales SVG inside those bounds)
+ *
+ * @author jplaine
+ *
+ */
+public class SVGHolderNode extends G2DParentNode {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8698435757824280001L;
+
+ protected Rectangle2D bounds = null;
+ protected Float borderWidth = null;
+
+
+ @PropertySetter("VariableFilter")
+ public void setScript(String script) {
+ for(IG2DNode node : getSortedNodes()) // Pass value to children
+ if(node instanceof AnimatedSVGNode) {
+ ((AnimatedSVGNode)node).setScript(script);
+ }
+ }
+
+ @PropertySetter("SVG")
+ public void setData(String data) {
+ for(IG2DNode node : getSortedNodes()) // Pass value to children
+ if(node instanceof AnimatedSVGNode) {
+ ((AnimatedSVGNode)node).setData(data);
+ }
+ }
+
+ @PropertySetter("Stroke Width")
+ @SyncField("border")
+ public void setBorderWidth(Float borderWidth) {
+ this.borderWidth = borderWidth;
+ }
+
+ @PropertySetter("Bounds")
+ @SyncField("bounds")
+ public void setBounds(Rectangle2D bounds) {
+ this.bounds = bounds;
+ }
+
+ @Override
+ public void render(Graphics2D g2d) {
+ Rectangle2D cb = getBoundsInLocal(false);
+ double scaleX = bounds.getWidth() / cb.getWidth();
+ double scaleY = bounds.getHeight() / cb.getHeight();
+ double scale = Math.min(scaleX, scaleY);
+
+ if(borderWidth != null && borderWidth > 0.0f && bounds != null) {
+ Graphics2D g2 = (Graphics2D)g2d.create();
+ g2.transform(transform);
+ g2.setStroke(new BasicStroke(this.borderWidth));
+ g2.setColor(Color.BLACK);
+ g2.draw(bounds);
+ g2.dispose();
+ }
+
+ @SuppressWarnings("unused")
+ int noBounds = 0;
+ @SuppressWarnings("unused")
+ int clipped = 0;
+ @SuppressWarnings("unused")
+ int rendered = 0;
+
+ AffineTransform ot = g2d.getTransform();
+ g2d.transform(transform);
+
+ g2d.translate(-cb.getMinX()*scale+bounds.getMinX(), -cb.getMinY()*scale+bounds.getMinY());
+ g2d.scale(scale, scale);
+
+ // Get transformed clip bounds
+ Shape clipShape = g2d.getClip();
+ Rectangle2D bounds = null;
+ if (clipShape instanceof Rectangle2D)
+ bounds = (Rectangle2D) clipShape;
+ else if (clipShape != null)
+ bounds = clipShape.getBounds2D();
+
+ boolean noClipBounds = bounds == null;
+
+ for(IG2DNode node : getSortedNodes()) {
+ Rectangle2D localBounds = node.getBoundsInLocal();
+ boolean hasNoBounds = localBounds == null;
+ boolean visible = false;
+ if (!noClipBounds && !hasNoBounds) {
+ visible = node.intersects(bounds);
+ } else {
+ ++noBounds;
+ }
+ if (noClipBounds || hasNoBounds || visible) {
+ // TODO: consider removing this g2d.create ?
+ // Will definitely current cause bugs to appear.
+ if (node.validate()) {
+ node.render(g2d);
+ }
+ ++rendered;
+ } else {
+ ++clipped;
+ }
+ }
+
+ g2d.setTransform(ot);
+ }
+
+ @Override
+ public Rectangle2D getBoundsInLocal() {
+ return bounds; // FIXME: not sure if it's a good idea to return different value than the getBoundsInLocal(boolean nulls) returns..
+ }
+
+}