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