]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNode.java
Move state changes away from render method to refresh method
[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 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)}.
59      * 
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.
64      * 
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)).
67      * 
68      * @param g2d
69      * 
70      * @see #setTransform(AffineTransform)
71      * @see #getTransform()
72      */
73     public void render(Graphics2D g2d);
74     
75     /**
76      * Refresh the node state.  
77      */
78     public void refresh();
79     
80     /**
81      * Visit the IG2DNode substructure of this node using the provided visitor.
82      * 
83      * @param visitor the visitor to use
84      * @since 1.29.0
85      */
86     public void accept(IG2DNodeVisitor visitor);
87
88     /**
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.
91      */
92     public void repaint();
93
94     // Bounds and transformation
95
96     /**
97      * @return affine transformation set for this node to transform it into its
98      *         parent's coordinate space
99      */
100     public AffineTransform getTransform();
101
102     /**
103      * Set an affine transformation for this node that transforms its local
104      * coordinates into its parent's coordinate space
105      * 
106      * @param transform local &rarr; parent transform
107      */
108     public void setTransform(AffineTransform transform);
109
110     /**
111      * Return bounds transformed with local transformation
112      * 
113      * @return transformed bounds
114      */
115     public Rectangle2D getBounds();
116
117     /**
118      * Return bounds in local coordinates. May expose internal state of the
119      * node. The client is not allowed to modify the returned value.
120      * 
121      * @return bounds
122      */
123     public Rectangle2D getBoundsInLocal();
124
125     public Rectangle2D getBoundsInLocal(boolean ignoreNulls);
126
127     // Helper methods for bounds checking
128
129     public boolean contains(Point2D point);
130
131     public boolean intersects(Rectangle2D rect);
132
133     public Point2D localToParent(Point2D point);
134
135     public Rectangle2D localToParent(Rectangle2D rect);
136
137     public Point2D parentToLocal(Point2D point);
138
139     public Rectangle2D parentToLocal(Rectangle2D rect);
140
141     public Point2D localToControl(Point2D point);
142
143     public Rectangle2D localToControl(Rectangle2D rect);
144
145     public Point2D controlToLocal(Point2D point);
146
147     public Rectangle2D controlToLocal(Rectangle2D rect);
148
149     /**
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
152      */
153     public G2DSceneGraph getRootNode2D();
154
155     /**
156      * @return true if this node has focus in the owner scene graph
157      */
158     public boolean hasFocus();
159
160     /**
161      * @return the node that has focus in the owner scene graph
162      */
163     public IG2DNode getFocusNode();
164
165     /**
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.
168      */
169     public void setFocusNode(IG2DNode node);
170
171 }