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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.scenegraph.g2d.nodes;
\r
14 import java.awt.Graphics2D;
\r
15 import java.awt.Rectangle;
\r
16 import java.awt.geom.Rectangle2D;
\r
18 import org.simantics.scenegraph.g2d.G2DNode;
\r
19 import org.simantics.scenegraph.g2d.G2DRenderingHints;
\r
22 * @author Tuukka Lehtonen
\r
24 public class BoundsNode extends G2DNode {
\r
26 public interface ResizeListener {
\r
27 void controlResized(Rectangle2D bounds);
\r
30 private static final long serialVersionUID = -3215912248617879834L;
\r
32 private Rectangle2D controlbounds = new Rectangle();
\r
34 @SyncField("controlbounds")
\r
35 protected void setControlBounds(Rectangle2D r) {
\r
36 this.controlbounds = r.getBounds2D();
\r
40 public Rectangle2D getBoundsInLocal() {
\r
41 // This node performs no real rendering but returning null
\r
42 // guarantees that its render method will get called.
\r
46 public Rectangle2D getControlBounds() {
\r
47 return controlbounds;
\r
51 public void render(Graphics2D g2d) {
\r
52 Rectangle2D r = (Rectangle2D) g2d.getRenderingHint(G2DRenderingHints.KEY_CONTROL_BOUNDS);
\r
54 if (!r.equals(controlbounds)) {
\r
55 //System.out.println("new control bounds: " + r);
\r
56 setControlBounds(r);
\r
63 public String toString() {
\r
64 return super.toString() + " [controlbounds=" + controlbounds + "]";
\r
67 private ResizeListener resizeListener = null;
\r
69 public void setResizeListener(ResizeListener listener) {
\r
70 this.resizeListener = listener;
\r
74 public void controlResized(Rectangle2D bounds) {
\r
75 if (resizeListener != null && bounds != null)
\r
76 resizeListener.controlResized(bounds);
\r