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;
14 import java.awt.Composite;
15 import java.awt.Graphics2D;
16 import java.awt.geom.AffineTransform;
17 import java.awt.geom.Point2D;
18 import java.awt.geom.Rectangle2D;
20 import org.simantics.scenegraph.INode;
21 import org.simantics.scenegraph.g2d.events.IEventHandler;
26 * @author Tuukka Lehtonen
28 public interface IG2DNode extends INode, IEventHandler {
31 * Set the z-index, i.e. the rendering order number for this 2D node.
32 * 2D nodes are sorted in ascending z-order for rendering.
37 public void setZIndex(int z);
40 * @return the rendering order of this 2D node.
42 public int getZIndex();
45 * @return <code>false</code> if this node will not render anything if
46 * {@link #render(Graphics2D)} was invoked. Serves as a means to
47 * optimize rendering. Should always return <code>true</code> by
50 public boolean validate();
53 * Perform the actual rendering. Node state changes must be avoided in
54 * this method. Implement node state changes to refresh method instead.
55 * This method should not change the transform of the g2d
56 * instance. You should call g2d.create or copy the original transform and
57 * put it back at the end of this method according to what is specified in
58 * {@link Graphics2D#setTransform(AffineTransform)}.
60 * This method is always invoked so that the local transform of this
61 * {@link IG2DNode} has not been applied to the Graphics2D rendering
62 * context. It is this node's responsibility to apply its own transform
63 * during rendering if necessary.
65 * The method must also make sure that it returns the {@link Composite} of
66 * g2d to its original state using (see {@link Graphics2D#setComposite(Composite)).
70 * @see #setTransform(AffineTransform)
71 * @see #getTransform()
73 public void render(Graphics2D g2d);
76 * Refresh the node state.
78 public void refresh();
81 * Visit the IG2DNode substructure of this node using the provided visitor.
83 * @param visitor the visitor to use
86 public void accept(IG2DNodeVisitor visitor);
89 * Mark the scene graph to be repainted in its current rendering context (UI
90 * component) as soon as is appropriate for the backend system.
92 public void repaint();
94 // Bounds and transformation
97 * @return affine transformation set for this node to transform it into its
98 * parent's coordinate space
100 public AffineTransform getTransform();
103 * Set an affine transformation for this node that transforms its local
104 * coordinates into its parent's coordinate space
106 * @param transform local → parent transform
108 public void setTransform(AffineTransform transform);
111 * Return bounds transformed with local transformation
113 * @return transformed bounds
115 public Rectangle2D getBounds();
118 * Return bounds in local coordinates. May expose internal state of the
119 * node. The client is not allowed to modify the returned value.
123 public Rectangle2D getBoundsInLocal();
125 public Rectangle2D getBoundsInLocal(boolean ignoreNulls);
127 // Helper methods for bounds checking
129 public boolean contains(Point2D point);
131 public boolean intersects(Rectangle2D rect);
133 public Point2D localToParent(Point2D point);
135 public Rectangle2D localToParent(Rectangle2D rect);
137 public Point2D parentToLocal(Point2D point);
139 public Rectangle2D parentToLocal(Rectangle2D rect);
141 public Point2D localToControl(Point2D point);
143 public Rectangle2D localToControl(Rectangle2D rect);
145 public Point2D controlToLocal(Point2D point);
147 public Rectangle2D controlToLocal(Rectangle2D rect);
150 * @return root node of the 2D scene graph or <code>null</code> if this node is
151 * not part of a properly rooted scene graph hierarchy
153 public G2DSceneGraph getRootNode2D();
156 * @return true if this node has focus in the owner scene graph
158 public boolean hasFocus();
161 * @return the node that has focus in the owner scene graph
163 public IG2DNode getFocusNode();
166 * @param node the node to have focus in the owner scene graph. The
167 * specified node must be a part of the same scene graph.
169 public void setFocusNode(IG2DNode node);