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