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.elementclass.canvas;
14 import java.awt.geom.Rectangle2D;
16 import org.simantics.g2d.canvas.ICanvasContext;
17 import org.simantics.g2d.element.ElementUtils;
18 import org.simantics.g2d.element.IElement;
19 import org.simantics.g2d.element.SceneGraphNodeKey;
20 import org.simantics.g2d.element.handler.SceneGraph;
21 import org.simantics.scenegraph.Node;
22 import org.simantics.scenegraph.g2d.G2DParentNode;
23 import org.simantics.scenegraph.g2d.nodes.ClippingNode;
24 import org.simantics.utils.datastructures.hints.IHintContext.Key;
27 * An element handler that "paints" a canvas bound to an element.
29 * Keys: CanvasClass.KEY_CANVAS
31 * @author Toni Kalajainen
33 public class CanvasPainter implements SceneGraph {
35 private static final long serialVersionUID = -182067379834789790L;
37 public static final CanvasPainter INSTANCE = new CanvasPainter();
39 public static final Key SG_NODE = new SceneGraphNodeKey(Node.class, "SUB_SG_NODE");
42 public void cleanup(IElement e) {
43 ElementUtils.removePossibleNode(e, SG_NODE);
47 public void init(IElement e, G2DParentNode parent) {
48 ICanvasContext ctx = e.getHint(CanvasClass.KEY_CANVAS);
50 ElementUtils.removePossibleNode(e, SG_NODE);
54 ClippingNode node = ElementUtils.getOrCreateNode(e, parent, SG_NODE, ClippingNode.class);
56 Rectangle2D bounds = ElementUtils.getElementBounds(e);