]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNode.java
0afebc2db387857a305a8458001755c28766e973
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / IG2DNode.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.scenegraph.g2d;
13
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;
19
20 import org.simantics.scenegraph.INode;
21 import org.simantics.scenegraph.g2d.events.IEventHandler;
22
23 /**
24  * 
25  * 
26  * @author Tuukka Lehtonen
27  */
28 public interface IG2DNode extends INode, IEventHandler {
29
30     /**
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.
33      * 
34      * @param z
35      */
36     @SyncField("z")
37     public void setZIndex(int z);
38
39     /**
40      * @return the rendering order of this 2D node.
41      */
42     public int getZIndex();
43
44     /**
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
48      *         default.
49      */
50     public boolean validate();
51
52     /**
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)}.
58      * 
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.
63      * 
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)).
66      * 
67      * @param g2d
68      * 
69      * @see #setTransform(AffineTransform)
70      * @see #getTransform()
71      */
72     public void render(Graphics2D g2d);
73
74     /**
75      * Mark the scene graph to be repainted in its current rendering context (UI
76      * component) as soon as is appropriate for the backend system.
77      */
78     public void repaint();
79
80     // Bounds and transformation
81
82     /**
83      * @return affine transformation set for this node to transform it into its
84      *         parent's coordinate space
85      */
86     public AffineTransform getTransform();
87
88     /**
89      * Set an affine transformation for this node that transforms its local
90      * coordinates into its parent's coordinate space
91      * 
92      * @param transform local &rarr; parent transform
93      */
94     public void setTransform(AffineTransform transform);
95
96     /**
97      * Return bounds transformed with local transformation
98      * 
99      * @return transformed bounds
100      */
101     public Rectangle2D getBounds();
102
103     /**
104      * Return bounds in local coordinates. May expose internal state of the
105      * node. The client is not allowed to modify the returned value.
106      * 
107      * @return bounds
108      */
109     public Rectangle2D getBoundsInLocal();
110
111     public Rectangle2D getBoundsInLocal(boolean ignoreNulls);
112
113     // Helper methods for bounds checking
114
115     public boolean contains(Point2D point);
116
117     public boolean intersects(Rectangle2D rect);
118
119     public Point2D localToParent(Point2D point);
120
121     public Rectangle2D localToParent(Rectangle2D rect);
122
123     public Point2D parentToLocal(Point2D point);
124
125     public Rectangle2D parentToLocal(Rectangle2D rect);
126
127     public Point2D localToControl(Point2D point);
128
129     public Rectangle2D localToControl(Rectangle2D rect);
130
131     public Point2D controlToLocal(Point2D point);
132
133     public Rectangle2D controlToLocal(Rectangle2D rect);
134
135     /**
136      * @return root node of the 2D scene graph or <code>null</code> if this node is
137      *         not part of a properly rooted scene graph hierarchy
138      */
139     public G2DSceneGraph getRootNode2D();
140
141     /**
142      * @return true if this node has focus in the owner scene graph
143      */
144     public boolean hasFocus();
145
146     /**
147      * @return the node that has focus in the owner scene graph
148      */
149     public IG2DNode getFocusNode();
150
151     /**
152      * @param node the node to have focus in the owner scene graph. The
153      *        specified node must be a part of the same scene graph.
154      */
155     public void setFocusNode(IG2DNode node);
156
157 }