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