1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.element.handler.impl;
14 import java.awt.BasicStroke;
15 import java.awt.Color;
16 import java.awt.geom.AffineTransform;
17 import java.awt.geom.Path2D;
18 import java.awt.geom.Rectangle2D;
20 import org.simantics.g2d.element.ElementUtils;
21 import org.simantics.g2d.element.IElement;
22 import org.simantics.g2d.element.SceneGraphNodeKey;
23 import org.simantics.g2d.element.handler.SceneGraph;
24 import org.simantics.g2d.multileveldiagram.TransitionFunction;
25 import org.simantics.scenegraph.Node;
26 import org.simantics.scenegraph.g2d.G2DParentNode;
27 import org.simantics.scenegraph.g2d.nodes.ShapeNode;
28 import org.simantics.utils.datastructures.hints.IHintContext.Key;
31 * @See {@link TransitionFunction}
32 * @author Toni Kalajainen
34 public class TransitionFunctionPainter implements SceneGraph {
38 private static final long serialVersionUID = 218125859645762515L;
39 TransitionFunction func;
41 final static BasicStroke STROKE = new BasicStroke(1.0f);
43 public static final Key SG_NODE = new SceneGraphNodeKey(Node.class, "SUB_SG_NODE");
45 public TransitionFunctionPainter(TransitionFunction func) {
47 path = new Path2D.Double();
48 for (int i=0; i<101; i++)
50 double x = ((double)i)/100;
60 public void cleanup(IElement e) {
61 Node node = e.removeHint(SG_NODE);
67 public void init(IElement e, G2DParentNode parent) {
68 ShapeNode node = (ShapeNode) e.getHint(SG_NODE);
70 node = parent.addNode(ShapeNode.class);
71 e.setHint(SG_NODE, node);
74 Rectangle2D bounds = ElementUtils.getElementBounds(e);
76 AffineTransform transform = AffineTransform.getTranslateInstance(-bounds.getMinX(), -bounds.getMinY());
77 transform.scale(bounds.getWidth(), bounds.getHeight());
79 node.setTransform(transform);
80 node.setStroke(STROKE);
81 node.setScaleStroke(true);
82 node.setColor(Color.BLACK);