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.Color;
16 import java.awt.geom.AffineTransform;
17 import java.awt.geom.Rectangle2D;
19 import org.simantics.g2d.element.ElementUtils;
20 import org.simantics.g2d.element.IElement;
21 import org.simantics.g2d.element.SceneGraphNodeKey;
22 import org.simantics.g2d.element.handler.InternalSize;
23 import org.simantics.g2d.element.handler.SceneGraph;
24 import org.simantics.g2d.element.handler.Text;
25 import org.simantics.scenegraph.Node;
26 import org.simantics.scenegraph.g2d.G2DParentNode;
27 import org.simantics.scenegraph.g2d.nodes.TextNode;
28 import org.simantics.utils.datastructures.hints.IHintContext.Key;
31 * @author Toni Kalajainen
33 public class TextPainter implements SceneGraph {
38 private static final long serialVersionUID = -4156239790629253738L;
40 static final Font FONT = Font.decode("Arial 6");
42 public static final Key SG_NODE = new SceneGraphNodeKey(Node.class, "SUB_SG_NODE");
45 public void cleanup(IElement e) {
46 Node node = e.removeHint(SG_NODE);
52 public void init(IElement e, G2DParentNode parent) {
53 TextNode node = (TextNode) e.getHint(SG_NODE);
55 node = parent.addNode(TextNode.class);
56 e.setHint(SG_NODE, node);
59 Color bc = ElementUtils.getTextColor(e, Color.BLACK);
60 InternalSize b = e.getElementClass().getSingleItem(InternalSize.class);
61 Rectangle2D r = b.getBounds(e, null);
64 Text t = e.getElementClass().getAtMostOneItemOfClass(Text.class);
67 String text = t.getText(e);
70 AffineTransform at = ElementUtils.getTransform(e);
76 node.setTransform(at);