]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/ClippingNode.java
Merge commit 'd186091'
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / nodes / ClippingNode.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.scenegraph.g2d.nodes;\r
13 \r
14 import java.awt.Graphics2D;\r
15 import java.awt.Shape;\r
16 import java.awt.geom.Rectangle2D;\r
17 \r
18 import org.simantics.scenegraph.g2d.G2DParentNode;\r
19 \r
20 /**\r
21  * @author Tuukka Lehtonen\r
22  */\r
23 public class ClippingNode extends G2DParentNode {\r
24 \r
25     private static final long serialVersionUID = -1064240485806430485L;\r
26 \r
27     protected Shape clipShape;\r
28 \r
29     @SyncField({"clipShape"})\r
30     public void setClip(Shape shape) {\r
31         this.clipShape = shape;\r
32     }\r
33 \r
34     public Shape getClip() {\r
35         return clipShape;\r
36     }\r
37 \r
38     @Override\r
39     public void render(Graphics2D g2d) {\r
40         Shape prevClip = g2d.getClip();\r
41         try {\r
42             g2d.setClip(clipShape);\r
43             super.render(g2d);\r
44         } finally {\r
45             g2d.setClip(prevClip);\r
46         }\r
47     }\r
48 \r
49     @Override\r
50     public String toString() {\r
51         return super.toString() + "[clip shape=" + clipShape + "]";\r
52     }\r
53 \r
54     @Override\r
55     public Rectangle2D getBoundsInLocal() {\r
56         if (clipShape == null)\r
57             return null;\r
58        return clipShape.getBounds2D();\r
59     }\r
60 \r
61 }