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 should be avoided in
54 * this method. This method should not change the transform of the g2d
55 * instance. You should call g2d.create or copy the original transform and
56 * put it back at the end of this method according to what is specified in
57 * {@link Graphics2D#setTransform(AffineTransform)}.
59 * This method is always invoked so that the local transform of this
60 * {@link IG2DNode} has not been applied to the Graphics2D rendering
61 * context. It is this node's responsibility to apply its own transform
62 * during rendering if necessary.
64 * The method must also make sure that it returns the {@link Composite} of
65 * g2d to its original state using (see {@link Graphics2D#setComposite(Composite)).
69 * @see #setTransform(AffineTransform)
70 * @see #getTransform()
72 public void render(Graphics2D g2d);
75 * Visit the IG2DNode substructure of this node using the provided visitor.
77 * @param visitor the visitor to use
80 public void accept(IG2DNodeVisitor visitor);
83 * Mark the scene graph to be repainted in its current rendering context (UI
84 * component) as soon as is appropriate for the backend system.
86 public void repaint();
88 // Bounds and transformation
91 * @return affine transformation set for this node to transform it into its
92 * parent's coordinate space
94 public AffineTransform getTransform();
97 * Set an affine transformation for this node that transforms its local
98 * coordinates into its parent's coordinate space
100 * @param transform local → parent transform
102 public void setTransform(AffineTransform transform);
105 * Return bounds transformed with local transformation
107 * @return transformed bounds
109 public Rectangle2D getBounds();
112 * Return bounds in local coordinates. May expose internal state of the
113 * node. The client is not allowed to modify the returned value.
117 public Rectangle2D getBoundsInLocal();
119 public Rectangle2D getBoundsInLocal(boolean ignoreNulls);
121 // Helper methods for bounds checking
123 public boolean contains(Point2D point);
125 public boolean intersects(Rectangle2D rect);
127 public Point2D localToParent(Point2D point);
129 public Rectangle2D localToParent(Rectangle2D rect);
131 public Point2D parentToLocal(Point2D point);
133 public Rectangle2D parentToLocal(Rectangle2D rect);
135 public Point2D localToControl(Point2D point);
137 public Rectangle2D localToControl(Rectangle2D rect);
139 public Point2D controlToLocal(Point2D point);
141 public Rectangle2D controlToLocal(Rectangle2D rect);
144 * @return root node of the 2D scene graph or <code>null</code> if this node is
145 * not part of a properly rooted scene graph hierarchy
147 public G2DSceneGraph getRootNode2D();
150 * @return true if this node has focus in the owner scene graph
152 public boolean hasFocus();
155 * @return the node that has focus in the owner scene graph
157 public IG2DNode getFocusNode();
160 * @param node the node to have focus in the owner scene graph. The
161 * specified node must be a part of the same scene graph.
163 public void setFocusNode(IG2DNode node);