-/*******************************************************************************\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.g2d.element.handler.impl;\r
-\r
-import java.awt.BasicStroke;\r
-import java.awt.Color;\r
-import java.awt.geom.AffineTransform;\r
-import java.awt.geom.Path2D;\r
-import java.awt.geom.Rectangle2D;\r
-\r
-import org.simantics.g2d.element.ElementUtils;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.SceneGraphNodeKey;\r
-import org.simantics.g2d.element.handler.SceneGraph;\r
-import org.simantics.g2d.multileveldiagram.TransitionFunction;\r
-import org.simantics.scenegraph.Node;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.scenegraph.g2d.nodes.ShapeNode;\r
-import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
-\r
-/**\r
- * @See {@link TransitionFunction}\r
- * @author Toni Kalajainen\r
- */\r
-public class TransitionFunctionPainter implements SceneGraph {\r
- /**\r
- * \r
- */\r
- private static final long serialVersionUID = 218125859645762515L;\r
- TransitionFunction func;\r
- Path2D path;\r
- final static BasicStroke STROKE = new BasicStroke(1.0f);\r
- \r
- public static final Key SG_NODE = new SceneGraphNodeKey(Node.class, "SUB_SG_NODE");\r
-\r
- public TransitionFunctionPainter(TransitionFunction func) {\r
- this.func = func;\r
- path = new Path2D.Double();\r
- for (int i=0; i<101; i++)\r
- {\r
- double x = ((double)i)/100;\r
- double y = func.f(x);\r
- if (i==0)\r
- path.moveTo(x, 1-y);\r
- else\r
- path.lineTo(x, 1-y);\r
- } \r
- }\r
-\r
- @Override\r
- public void cleanup(IElement e) {\r
- Node node = e.removeHint(SG_NODE);\r
- if (node != null)\r
- node.remove();\r
- }\r
-\r
- @Override\r
- public void init(IElement e, G2DParentNode parent) {\r
- ShapeNode node = (ShapeNode) e.getHint(SG_NODE);\r
- if (node == null) {\r
- node = parent.addNode(ShapeNode.class);\r
- e.setHint(SG_NODE, node);\r
- }\r
- \r
- Rectangle2D bounds = ElementUtils.getElementBounds(e);\r
- \r
- AffineTransform transform = AffineTransform.getTranslateInstance(-bounds.getMinX(), -bounds.getMinY());\r
- transform.scale(bounds.getWidth(), bounds.getHeight());\r
- \r
- node.setTransform(transform);\r
- node.setStroke(STROKE);\r
- node.setScaleStroke(true);\r
- node.setColor(Color.BLACK);\r
- node.setShape(path);\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.g2d.element.handler.impl;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Path2D;
+import java.awt.geom.Rectangle2D;
+
+import org.simantics.g2d.element.ElementUtils;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.SceneGraphNodeKey;
+import org.simantics.g2d.element.handler.SceneGraph;
+import org.simantics.g2d.multileveldiagram.TransitionFunction;
+import org.simantics.scenegraph.Node;
+import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scenegraph.g2d.nodes.ShapeNode;
+import org.simantics.utils.datastructures.hints.IHintContext.Key;
+
+/**
+ * @See {@link TransitionFunction}
+ * @author Toni Kalajainen
+ */
+public class TransitionFunctionPainter implements SceneGraph {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 218125859645762515L;
+ TransitionFunction func;
+ Path2D path;
+ final static BasicStroke STROKE = new BasicStroke(1.0f);
+
+ public static final Key SG_NODE = new SceneGraphNodeKey(Node.class, "SUB_SG_NODE");
+
+ public TransitionFunctionPainter(TransitionFunction func) {
+ this.func = func;
+ path = new Path2D.Double();
+ for (int i=0; i<101; i++)
+ {
+ double x = ((double)i)/100;
+ double y = func.f(x);
+ if (i==0)
+ path.moveTo(x, 1-y);
+ else
+ path.lineTo(x, 1-y);
+ }
+ }
+
+ @Override
+ public void cleanup(IElement e) {
+ Node node = e.removeHint(SG_NODE);
+ if (node != null)
+ node.remove();
+ }
+
+ @Override
+ public void init(IElement e, G2DParentNode parent) {
+ ShapeNode node = (ShapeNode) e.getHint(SG_NODE);
+ if (node == null) {
+ node = parent.addNode(ShapeNode.class);
+ e.setHint(SG_NODE, node);
+ }
+
+ Rectangle2D bounds = ElementUtils.getElementBounds(e);
+
+ AffineTransform transform = AffineTransform.getTranslateInstance(-bounds.getMinX(), -bounds.getMinY());
+ transform.scale(bounds.getWidth(), bounds.getHeight());
+
+ node.setTransform(transform);
+ node.setStroke(STROKE);
+ node.setScaleStroke(true);
+ node.setColor(Color.BLACK);
+ node.setShape(path);
+ }
+}