]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/BackgroundNode.java
Sync git svn branch with SVN repository r33269.
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / nodes / BackgroundNode.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.Color;\r
15 import java.awt.Graphics2D;\r
16 import java.awt.Paint;\r
17 import java.awt.geom.Rectangle2D;\r
18 \r
19 import org.simantics.scenegraph.g2d.G2DNode;\r
20 \r
21 public class BackgroundNode extends G2DNode {\r
22     /**\r
23      * \r
24      */\r
25     private static final long serialVersionUID = 2805713128639560702L;\r
26 \r
27     protected Color color = null;\r
28     protected Paint paint = null;\r
29     protected Rectangle2D bounds = null;\r
30 \r
31     @SyncField("color")\r
32     public void setColor(Color color) {\r
33         this.color = color;\r
34     }\r
35 \r
36     @SyncField("paint")\r
37     public void setPaint(Paint paint) {\r
38         this.paint = paint;\r
39     }\r
40 \r
41     @SyncField("bounds")\r
42     public void setBounds(Rectangle2D bounds) {\r
43         this.bounds = bounds;\r
44     }\r
45 \r
46     @Override\r
47     public void render(Graphics2D g) {\r
48         Rectangle2D drawBounds = bounds;\r
49         if(drawBounds == null) {\r
50                 drawBounds = (Rectangle2D)g.getClipBounds().clone(); // Fill whole clip area if bounds is not defined\r
51         }\r
52         \r
53         if (color!=null) {\r
54             g.setColor(color);\r
55             g.fill(drawBounds);\r
56         } else\r
57             if (paint!=null) {\r
58                 g.setPaint(paint);\r
59                 g.fill(drawBounds);\r
60             }\r
61     }\r
62 \r
63     @Override\r
64     public String toString() {\r
65         return super.toString() + " [color=" + color + "]";\r
66     }\r
67 \r
68         @Override\r
69         public Rectangle2D getBoundsInLocal() {\r
70                 return bounds;\r
71         }\r
72 }\r