]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/BorderDecoratorNode.java
G2DParentNode handles "undefined" child bounds separately
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / nodes / BorderDecoratorNode.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.BasicStroke;
15 import java.awt.Color;
16 import java.awt.Composite;
17 import java.awt.Graphics2D;
18 import java.awt.geom.AffineTransform;
19 import java.awt.geom.Rectangle2D;
20
21 public class BorderDecoratorNode extends TransformNode {
22     /**
23      * 
24      */
25     private static final long serialVersionUID = -4982578347433716440L;
26
27     protected Composite composite;
28     protected Boolean visible = Boolean.TRUE;
29     protected Rectangle2D bounds = null;
30     protected float border = 1.0f;
31
32     @SyncField("composite")
33     public void setComposite(Composite composite) {
34         this.composite = composite;
35     }
36
37     @SyncField("visible")
38     public void setVisible(Boolean visible) {
39         this.visible = visible;
40     }
41
42     @PropertySetter("Stroke Width")
43     @SyncField("border")
44     public void setBorderWidth(Float borderWidth) {
45         this.border = borderWidth != null ? borderWidth : 1.0f;
46     }
47
48     public boolean isVisible() {
49         return visible;
50     }
51
52     @PropertySetter("Bounds")
53     @SyncField("bounds")
54     public void setBounds(Rectangle2D bounds) {
55         this.bounds = bounds;
56     }
57
58     @Override
59     public Rectangle2D getBoundsInLocal() {
60         return bounds;
61     }
62
63     @Override
64     public void render(Graphics2D g) {
65         if(!visible) return;
66         if(composite != null) {
67             g.setComposite(composite);
68         }
69
70         if(this.border > 0.0f && bounds != null) {
71             AffineTransform ot = g.getTransform();
72             g.transform(transform);
73             g.setStroke(new BasicStroke(this.border));
74             g.setColor(Color.BLACK);
75             g.draw(bounds);
76
77             g.setTransform(ot);
78         }
79         super.render(g);
80     }
81 }