46804e6569a3b7fa2512f90a4fba4a9e83844528
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / nodes / BackgroundNode.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.scenegraph.g2d.nodes;
13
14 import java.awt.Color;
15 import java.awt.Graphics2D;
16 import java.awt.Paint;
17 import java.awt.geom.Rectangle2D;
18
19 import org.simantics.scenegraph.g2d.G2DNode;
20
21 public class BackgroundNode extends G2DNode {
22     /**
23      * 
24      */
25     private static final long serialVersionUID = 2805713128639560702L;
26
27     protected Color color = null;
28     protected Paint paint = null;
29     protected Rectangle2D bounds = null;
30
31     @SyncField("color")
32     public void setColor(Color color) {
33         this.color = color;
34     }
35
36     @SyncField("paint")
37     public void setPaint(Paint paint) {
38         this.paint = paint;
39     }
40
41     @SyncField("bounds")
42     public void setBounds(Rectangle2D bounds) {
43         this.bounds = bounds;
44     }
45
46     @Override
47     public void render(Graphics2D g) {
48         Rectangle2D drawBounds = bounds;
49         if(drawBounds == null) {
50                 drawBounds = (Rectangle2D)g.getClipBounds().clone(); // Fill whole clip area if bounds is not defined
51         }
52         
53         if (color!=null) {
54             g.setColor(color);
55             g.fill(drawBounds);
56         } else
57             if (paint!=null) {
58                 g.setPaint(paint);
59                 g.fill(drawBounds);
60             }
61     }
62
63     @Override
64     public String toString() {
65         return super.toString() + " [color=" + color + "]";
66     }
67
68         @Override
69         public Rectangle2D getBoundsInLocal() {
70                 return bounds;
71         }
72 }