JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestTiledPrintingGearsSwingAWT2.java
Go to the documentation of this file.
1/**
2 * Copyright 2013 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.jogl.tile;
30
31import java.awt.BorderLayout;
32import java.awt.Button;
33import java.awt.Container;
34import java.awt.Dimension;
35import java.awt.Frame;
36import java.awt.Label;
37import java.awt.event.ActionEvent;
38import java.awt.event.ActionListener;
39import java.awt.print.PageFormat;
40import java.io.BufferedReader;
41import java.io.IOException;
42import java.io.InputStreamReader;
43import java.lang.reflect.InvocationTargetException;
44
45import com.jogamp.opengl.GLCapabilities;
46import com.jogamp.opengl.GLProfile;
47import com.jogamp.opengl.awt.GLJPanel;
48import javax.swing.BorderFactory;
49import javax.swing.JButton;
50import javax.swing.JComponent;
51import javax.swing.JFrame;
52import javax.swing.JLayeredPane;
53import javax.swing.JPanel;
54import javax.swing.SwingUtilities;
55
56import org.junit.AfterClass;
57import org.junit.Assert;
58import org.junit.BeforeClass;
59import org.junit.FixMethodOrder;
60import org.junit.Test;
61import org.junit.runners.MethodSorters;
62
63import com.jogamp.common.os.Platform;
64import com.jogamp.newt.event.TraceKeyAdapter;
65import com.jogamp.newt.event.TraceWindowAdapter;
66import com.jogamp.newt.event.awt.AWTKeyAdapter;
67import com.jogamp.newt.event.awt.AWTWindowAdapter;
68import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
69import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
70import com.jogamp.opengl.test.junit.util.MiscUtils;
71import com.jogamp.opengl.test.junit.util.QuitAdapter;
72import com.jogamp.opengl.util.Animator;
73
74@FixMethodOrder(MethodSorters.NAME_ASCENDING)
76
77 static boolean waitForKey = false;
78 static GLProfile glp;
79 static int width, height;
80
81 @BeforeClass
82 public static void initClass() {
85 Assert.assertNotNull(glp);
86 width = 560; // 640;
87 height = 420; // 480;
88 } else {
89 setTestSupported(false);
90 }
91 // Runtime.getRuntime().traceInstructions(true);
92 // Runtime.getRuntime().traceMethodCalls(true);
93 }
94
95 @AfterClass
96 public static void releaseClass() {
97 }
98
99 protected void runTestGL(final GLCapabilities caps, final boolean addLayout, final boolean layered, final boolean skipGLOrientationVerticalFlip, final boolean useAnim) throws InterruptedException, InvocationTargetException {
100 final Dimension glc_sz = new Dimension(width, height);
101 final GLJPanel glJPanel1 = new GLJPanel(caps);
102 Assert.assertNotNull(glJPanel1);
103 glJPanel1.setSkipGLOrientationVerticalFlip(skipGLOrientationVerticalFlip);
104 glJPanel1.setMinimumSize(glc_sz);
105 glJPanel1.setPreferredSize(glc_sz);
106 glJPanel1.setBounds(0, 0, glc_sz.width, glc_sz.height);
107 {
108 final Gears demo = new Gears();
109 demo.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip);
110 glJPanel1.addGLEventListener(demo);
111 }
112
113 final JComponent tPanel, demoPanel;
114 if( layered ) {
115 glJPanel1.setOpaque(true);
116 final JButton tb = new JButton("On Top");
117 tb.setBounds(width/2, height/2, 200, 50);
118 if( addLayout ) {
119 tPanel = null;
120 final Dimension lsz = new Dimension(width, height);
121 demoPanel = new JLayeredPane();
122 demoPanel.setMinimumSize(lsz);
123 demoPanel.setPreferredSize(lsz);
124 demoPanel.setBounds(0, 0, lsz.width, lsz.height);
125 demoPanel.setBorder(BorderFactory.createTitledBorder("Layered Pane"));
126 demoPanel.add(glJPanel1, JLayeredPane.DEFAULT_LAYER);
127 demoPanel.add(tb, Integer.valueOf(2));
128 } else {
129 tPanel = new TransparentPanel();
130 tPanel.setBounds(0, 0, width, height);
131 tPanel.setLayout(null);
132 tPanel.add(tb);
133 demoPanel = glJPanel1;
134 }
135 } else {
136 tPanel = null;
137 if( addLayout ) {
138 demoPanel = new JPanel();
139 demoPanel.add(glJPanel1);
140 } else {
141 demoPanel = glJPanel1;
142 }
143 }
144
145 final JFrame frame = new JFrame("Swing Print");
146 Assert.assertNotNull(frame);
147
148 final ActionListener print72DPIAction = new ActionListener() {
149 public void actionPerformed(final ActionEvent e) {
150 doPrintManual(frame, 72, 0, -1, -1);
151 } };
152 final ActionListener print150DPIAction = new ActionListener() {
153 public void actionPerformed(final ActionEvent e) {
154 doPrintManual(frame, 150, -1, -1, -1);
155 } };
156 final ActionListener print300DPIAction = new ActionListener() {
157 public void actionPerformed(final ActionEvent e) {
158 doPrintManual(frame, 300, -1, -1, -1);
159 } };
160 final Button print72DPIButton = new Button("72dpi");
161 print72DPIButton.addActionListener(print72DPIAction);
162 final Button print150DPIButton = new Button("150dpi");
163 print150DPIButton.addActionListener(print150DPIAction);
164 final Button print300DPIButton = new Button("300dpi");
165 print300DPIButton.addActionListener(print300DPIAction);
166
167 final JPanel printPanel = new JPanel();
168 printPanel.add(print72DPIButton);
169 printPanel.add(print150DPIButton);
170 printPanel.add(print300DPIButton);
171 final JPanel southPanel = new JPanel();
172 southPanel.add(new Label("South"));
173 final JPanel eastPanel = new JPanel();
174 eastPanel.add(new Label("East"));
175 final JPanel westPanel = new JPanel();
176 westPanel.add(new Label("West"));
177
178 final Animator animator = useAnim ? new Animator() : null;
179 if( null != animator ) {
180 animator.add(glJPanel1);
181 }
182 final QuitAdapter quitAdapter = new QuitAdapter();
183 new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter), glJPanel1).addTo(glJPanel1);
184 new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glJPanel1).addTo(frame);
185
186 SwingUtilities.invokeAndWait(new Runnable() {
187 public void run() {
188 final Container fcont = frame.getContentPane();
189 if( addLayout ) {
190 fcont.setLayout(new BorderLayout());
191 fcont.add(printPanel, BorderLayout.NORTH);
192 fcont.add(demoPanel, BorderLayout.CENTER);
193 fcont.add(southPanel, BorderLayout.SOUTH);
194 fcont.add(eastPanel, BorderLayout.EAST);
195 fcont.add(westPanel, BorderLayout.WEST);
196 fcont.validate();
197 frame.pack();
198 } else {
199 frame.setSize(glc_sz);
200 fcont.setLayout(null);
201 if( null != tPanel ) {
202 fcont.add(tPanel);
203 }
204 fcont.add(demoPanel);
205 }
206 frame.setVisible(true);
207 } } ) ;
208
209 Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true, null));
210 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glJPanel1, true, null));
211
212 if( null != animator ) {
213 animator.setUpdateFPSFrames(60, System.err);
214 animator.start();
215 Assert.assertEquals(true, animator.isAnimating());
216 }
217
218 final long t0 = System.currentTimeMillis();
219 long t1 = t0;
220 boolean printDone = false;
221 while( !quitAdapter.shouldQuit() && ( 0 == duration || ( t1 - t0 ) < duration ) ) {
222 Thread.sleep(200);
223 if( !printDone ) {
224 printDone = true;
225 {
226 // No AA needed for 150 dpi and greater :)
227 final PrintableBase p = doPrintAuto(frame, PageFormat.PORTRAIT, null, -1 /* offscreen-type */, 150, -1, -1, -1, false);
228 waitUntilPrintJobsIdle(p);
229 }
230 }
231 t1 = System.currentTimeMillis();
232 }
233
234 Assert.assertNotNull(frame);
235 Assert.assertNotNull(glJPanel1);
236
237 if( null != animator ) {
238 animator.stop();
239 Assert.assertEquals(false, animator.isAnimating());
240 }
241 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
242 public void run() {
243 frame.setVisible(false);
244 }});
245 Assert.assertEquals(false, frame.isVisible());
246 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
247 public void run() {
248 final Frame _frame = frame;
249 _frame.remove(demoPanel);
250 _frame.dispose();
251 }});
252 }
253
254 @Test
255 public void test001_flip1_norm_layout0_layered0() throws InterruptedException, InvocationTargetException {
256 final GLCapabilities caps = new GLCapabilities(glp);
257 runTestGL(caps, false /* addLayout */, false /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */);
258 }
259
260 @Test
261 public void test002_flip1_norm_layout1_layered0() throws InterruptedException, InvocationTargetException {
262 final GLCapabilities caps = new GLCapabilities(glp);
263 runTestGL(caps, true /* addLayout */, false /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */);
264 }
265
266 @Test
267 public void test003_flip1_norm_layout0_layered1() throws InterruptedException, InvocationTargetException {
268 final GLCapabilities caps = new GLCapabilities(glp);
269 runTestGL(caps, false /* addLayout */, true /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */);
270 }
271
272 @Test
273 public void test004_flip1_norm_layout1_layered1() throws InterruptedException, InvocationTargetException {
274 final GLCapabilities caps = new GLCapabilities(glp);
275 runTestGL(caps, true /* addLayout */, true /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */);
276 }
277
278 @Test
279 public void test011_flip1_bitm_layout0_layered0() throws InterruptedException, InvocationTargetException {
280 if( Platform.OSType.WINDOWS != Platform.getOSType() ) {
281 return;
282 }
283 final GLCapabilities caps = new GLCapabilities(glp);
284 caps.setBitmap(true);
285 runTestGL(caps, false /* addLayout */, false /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */);
286 }
287
288 @Test
289 public void test012_flip1_bitm_layout1_layered0() throws InterruptedException, InvocationTargetException {
290 if( Platform.OSType.WINDOWS != Platform.getOSType() ) {
291 return;
292 }
293 final GLCapabilities caps = new GLCapabilities(glp);
294 caps.setBitmap(true);
295 runTestGL(caps, true /* addLayout */, false /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */);
296 }
297
298 @Test
299 public void test013_flip1_bitm_layout0_layered1() throws InterruptedException, InvocationTargetException {
300 if( Platform.OSType.WINDOWS != Platform.getOSType() ) {
301 return;
302 }
303 final GLCapabilities caps = new GLCapabilities(glp);
304 caps.setBitmap(true);
305 runTestGL(caps, false /* addLayout */, true /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */);
306 }
307
308 @Test
309 public void test014_flip1_bitm_layout1_layered1() throws InterruptedException, InvocationTargetException {
310 if( Platform.OSType.WINDOWS != Platform.getOSType() ) {
311 return;
312 }
313 final GLCapabilities caps = new GLCapabilities(glp);
314 caps.setBitmap(true);
315 runTestGL(caps, true /* addLayout */, true /* layered */, false /* skipGLOrientationVerticalFlip */, false /* useAnim */);
316 }
317
318 @Test
319 public void test101_flip1_norm_layout0_layered0() throws InterruptedException, InvocationTargetException {
320 final GLCapabilities caps = new GLCapabilities(glp);
321 runTestGL(caps, false /* addLayout */, false /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */);
322 }
323
324 @Test
325 public void test102_flip1_norm_layout1_layered0() throws InterruptedException, InvocationTargetException {
326 final GLCapabilities caps = new GLCapabilities(glp);
327 runTestGL(caps, true /* addLayout */, false /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */);
328 }
329
330 @Test
331 public void test103_flip1_norm_layout0_layered1() throws InterruptedException, InvocationTargetException {
332 final GLCapabilities caps = new GLCapabilities(glp);
333 runTestGL(caps, false /* addLayout */, true /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */);
334 }
335
336 @Test
337 public void test104_flip1_norm_layout1_layered1() throws InterruptedException, InvocationTargetException {
338 final GLCapabilities caps = new GLCapabilities(glp);
339 runTestGL(caps, true /* addLayout */, true /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */);
340 }
341
342 @Test
343 public void test111_flip1_bitm_layout0_layered0() throws InterruptedException, InvocationTargetException {
344 if( Platform.OSType.WINDOWS != Platform.getOSType() ) {
345 return;
346 }
347 final GLCapabilities caps = new GLCapabilities(glp);
348 caps.setBitmap(true);
349 runTestGL(caps, false /* addLayout */, false /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */);
350 }
351
352 @Test
353 public void test112_flip1_bitm_layout1_layered0() throws InterruptedException, InvocationTargetException {
354 if( Platform.OSType.WINDOWS != Platform.getOSType() ) {
355 return;
356 }
357 final GLCapabilities caps = new GLCapabilities(glp);
358 caps.setBitmap(true);
359 runTestGL(caps, true /* addLayout */, false /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */);
360 }
361
362 @Test
363 public void test113_flip1_bitm_layout0_layered1() throws InterruptedException, InvocationTargetException {
364 if( Platform.OSType.WINDOWS != Platform.getOSType() ) {
365 return;
366 }
367 final GLCapabilities caps = new GLCapabilities(glp);
368 caps.setBitmap(true);
369 runTestGL(caps, false /* addLayout */, true /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */);
370 }
371
372 @Test
373 public void test114_flip1_bitm_layout1_layered1() throws InterruptedException, InvocationTargetException {
374 if( Platform.OSType.WINDOWS != Platform.getOSType() ) {
375 return;
376 }
377 final GLCapabilities caps = new GLCapabilities(glp);
378 caps.setBitmap(true);
379 runTestGL(caps, true /* addLayout */, true /* layered */, true /* skipGLOrientationVerticalFlip */, false /* useAnim */);
380 }
381
382 static long duration = 500; // ms
383
384 public static void main(final String args[]) {
385 for(int i=0; i<args.length; i++) {
386 if(args[i].equals("-time")) {
387 i++;
388 duration = MiscUtils.atol(args[i], duration);
389 } else if(args[i].equals("-width")) {
390 i++;
391 width = MiscUtils.atoi(args[i], width);
392 } else if(args[i].equals("-height")) {
393 i++;
394 height = MiscUtils.atoi(args[i], height);
395 } else if(args[i].equals("-wait")) {
396 waitForKey = true;
397 }
398 }
399 if(waitForKey) {
400 final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
401 System.err.println("Press enter to continue");
402 try {
403 System.err.println(stdin.readLine());
404 } catch (final IOException e) { }
405 }
406 org.junit.runner.JUnitCore.main(TestTiledPrintingGearsSwingAWT2.class.getName());
407 }
408}
void setBitmap(final boolean enable)
Requesting offscreen bitmap mode.
AWT: printable: PRESSED (t0), TYPED (t0), RELEASED (t1) non-printable: PRESSED (t0),...
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
Definition: GLProfile.java:305
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
Definition: GLProfile.java:579
A lightweight Swing component which provides OpenGL rendering support.
Definition: GLJPanel.java:189
final void setSkipGLOrientationVerticalFlip(final boolean v)
Skip isGLOriented() based vertical flip, which usually is required by the offscreen backend,...
Definition: GLJPanel.java:1255
void setOpaque(final boolean opaque)
Definition: GLJPanel.java:981
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLJPanel.java:989
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
Definition: Gears.java:34
void setFlipVerticalInGLOrientation(final boolean v)
Definition: Gears.java:84
void runTestGL(final GLCapabilities caps, final boolean addLayout, final boolean layered, final boolean skipGLOrientationVerticalFlip, final boolean useAnim)
Base unit test class implementing issuing PrinterJob#print() on a Printable implementation,...
static boolean waitForRealized(final java.awt.Component comp, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final java.awt.Component comp, final boolean visible, final Runnable waitAction)
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368