]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNode.java
Sync git svn branch with SVN repository r33269.
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / IG2DNode.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.scenegraph.g2d;\r
13 \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
19 \r
20 import org.simantics.scenegraph.INode;\r
21 import org.simantics.scenegraph.g2d.events.IEventHandler;\r
22 \r
23 /**\r
24  * \r
25  * \r
26  * @author Tuukka Lehtonen\r
27  */\r
28 public interface IG2DNode extends INode, IEventHandler {\r
29 \r
30     /**\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
33      * \r
34      * @param z\r
35      */\r
36     @SyncField("z")\r
37     public void setZIndex(int z);\r
38 \r
39     /**\r
40      * @return the rendering order of this 2D node.\r
41      */\r
42     public int getZIndex();\r
43 \r
44     /**\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
48      *         default.\r
49      */\r
50     public boolean validate();\r
51 \r
52     /**\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
58      * \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
63      * \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
66      * \r
67      * @param g2d\r
68      * \r
69      * @see #setTransform(AffineTransform)\r
70      * @see #getTransform()\r
71      */\r
72     public void render(Graphics2D g2d);\r
73 \r
74     /**\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
77      */\r
78     public void repaint();\r
79 \r
80     // Bounds and transformation\r
81 \r
82     /**\r
83      * @return affine transformation set for this node to transform it into its\r
84      *         parent's coordinate space\r
85      */\r
86     public AffineTransform getTransform();\r
87 \r
88     /**\r
89      * Set an affine transformation for this node that transforms its local\r
90      * coordinates into its parent's coordinate space\r
91      * \r
92      * @param transform local &rarr; parent transform\r
93      */\r
94     public void setTransform(AffineTransform transform);\r
95 \r
96     /**\r
97      * Return bounds transformed with local transformation\r
98      * \r
99      * @return transformed bounds\r
100      */\r
101     public Rectangle2D getBounds();\r
102 \r
103     /**\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
106      * \r
107      * @return bounds\r
108      */\r
109     public Rectangle2D getBoundsInLocal();\r
110 \r
111     public Rectangle2D getBoundsInLocal(boolean ignoreNulls);\r
112 \r
113     // Helper methods for bounds checking\r
114 \r
115     public boolean contains(Point2D point);\r
116 \r
117     public boolean intersects(Rectangle2D rect);\r
118 \r
119     public Point2D localToParent(Point2D point);\r
120 \r
121     public Rectangle2D localToParent(Rectangle2D rect);\r
122 \r
123     public Point2D parentToLocal(Point2D point);\r
124 \r
125     public Rectangle2D parentToLocal(Rectangle2D rect);\r
126 \r
127     public Point2D localToControl(Point2D point);\r
128 \r
129     public Rectangle2D localToControl(Rectangle2D rect);\r
130 \r
131     public Point2D controlToLocal(Point2D point);\r
132 \r
133     public Rectangle2D controlToLocal(Rectangle2D rect);\r
134 \r
135     /**\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
138      */\r
139     public G2DSceneGraph getRootNode2D();\r
140 \r
141     /**\r
142      * @return true if this node has focus in the owner scene graph\r
143      */\r
144     public boolean hasFocus();\r
145 \r
146     /**\r
147      * @return the node that has focus in the owner scene graph\r
148      */\r
149     public IG2DNode getFocusNode();\r
150 \r
151     /**\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
154      */\r
155     public void setFocusNode(IG2DNode node);\r
156 \r
157 }\r