1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
/*
* Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package javax.media.j3d;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
/**
* The J3DGraphics2D class extends Graphics2D to provide 2D rendering
* into a Canvas3D. It is an abstract base class that is further
* extended by a non-public Java 3D implementation class. This class
* allows Java 2D rendering to be mixed with Java 3D rendering in the
* same Canvas3D, subject to the same restrictions as imposed for 3D
* immediate-mode rendering: In mixed-mode rendering, all Java 2D
* requests must be done from one of the Canvas3D callback methods; in
* pure-immediate mode, the Java 3D renderer must be stopped for the
* Canvas3D being rendered into.
*
* <p>
* An application obtains a J3D 2D graphics context object from the
* Canvas3D object that the application wishes to render into by using
* the getGraphics2D method. A new J3DGraphics2D object is created if
* one does not already exist.
*
* <p>
* Note that the drawing methods in this class, including those
* inherited from Graphics2D, are not necessarily executed
* immediately. They may be buffered up for future execution.
* Applications must call the <code><a
* href="#flush(boolean)">flush</a>(boolean)</code> method to ensure
* that the rendering actually happens. The flush method is implicitly
* called in the following cases:
*
* <ul>
* <li>The <code>Canvas3D.swap</code> method calls
* <code>flush(true)</code></li>
* <li>The Java 3D renderer calls <code>flush(true)</code> prior to
* swapping the buffer for a double buffered on-screen Canvas3D</li>
* <li>The Java 3D renderer calls <code>flush(true)</code> prior to
* copying into the off-screen buffer of an off-screen Canvas3D</li>
* <li>The Java 3D renderer calls <code>flush(false)</code> after
* calling the preRender, renderField, postRender, and postSwap
* Canvas3D callback methods.</li>
* </ul>
*
* <p>
* A single-buffered, pure-immediate mode application must explicitly
* call flush to ensure that the graphics will be rendered to the
* Canvas3D.
*
* @see Canvas3D#getGraphics2D
*
* @since Java 3D 1.2
*/
public abstract class J3DGraphics2D extends Graphics2D {
// Package scope contructor
J3DGraphics2D() {
}
/**
* This method is not supported. The only way to obtain a
* J3DGraphics2D is from the associated Canvas3D.
*
* @exception UnsupportedOperationException this method is not supported
*
* @see Canvas3D#getGraphics2D
*/
@Override
public final Graphics create() {
throw new UnsupportedOperationException();
}
/**
* This method is not supported. The only way to obtain a
* J3DGraphics2D is from the associated Canvas3D.
*
* @exception UnsupportedOperationException this method is not supported
*
* @see Canvas3D#getGraphics2D
*/
@Override
public final Graphics create(int x, int y, int width, int height) {
throw new UnsupportedOperationException();
}
/**
* This method is not supported. Clearing a Canvas3D is done implicitly
* via a Background node in the scene graph or explicitly via the clear
* method in a 3D graphics context.
*
* @exception UnsupportedOperationException this method is not supported
*
* @see Background
* @see GraphicsContext3D#setBackground
* @see GraphicsContext3D#clear
*/
@Override
public final void setBackground(Color color) {
throw new UnsupportedOperationException();
}
/**
* This method is not supported. Clearing a Canvas3D is done implicitly
* via a Background node in the scene graph or explicitly via the clear
* method in a 3D graphics context.
*
* @exception UnsupportedOperationException this method is not supported
*
* @see Background
* @see GraphicsContext3D#getBackground
* @see GraphicsContext3D#clear
*/
@Override
public final Color getBackground() {
throw new UnsupportedOperationException();
}
/**
* This method is not supported. Clearing a Canvas3D is done implicitly
* via a Background node in the scene graph or explicitly via the clear
* method in a 3D graphics context.
*
* @exception UnsupportedOperationException this method is not supported
*
* @see Background
* @see GraphicsContext3D#setBackground
* @see GraphicsContext3D#clear
*/
@Override
public final void clearRect(int x, int y, int width, int height) {
throw new UnsupportedOperationException();
}
/**
* Flushes all previously executed rendering operations to the
* drawing buffer for this 2D graphics object.
*
* @param wait flag indicating whether or not to wait for the
* rendering to be complete before returning from this call.
*/
public abstract void flush(boolean wait);
/**
* Draws the specified image and flushes the buffer. This is
* functionally equivalent to calling <code>drawImage(...)</code>
* followed by <code>flush(false)</code>, but can avoid the cost
* of making an extra copy of the image in some cases. Anything
* previously drawn to this J3DGraphics2D will be flushed before
* the image is drawn.
*
* @param img The image to draw
* @param x The x location to draw at
* @param y The y location to draw at
* @param observer The ImageObserver
*
* @since Java 3D 1.3
*/
public abstract void drawAndFlushImage(BufferedImage img, int x, int y,
ImageObserver observer);
}
|