JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestTiledPrintingGearsAWT.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.Dimension;
34import java.awt.Frame;
35import java.awt.Label;
36import java.awt.Panel;
37import java.awt.event.ActionEvent;
38import java.awt.event.ActionListener;
39import java.awt.image.BufferedImage;
40import java.awt.print.PageFormat;
41import java.io.BufferedReader;
42import java.io.IOException;
43import java.io.InputStreamReader;
44import java.lang.reflect.InvocationTargetException;
45
46import com.jogamp.opengl.GLCapabilities;
47import com.jogamp.opengl.GLProfile;
48import com.jogamp.opengl.awt.GLCanvas;
49
50import org.junit.AfterClass;
51import org.junit.Assert;
52import org.junit.BeforeClass;
53import org.junit.FixMethodOrder;
54import org.junit.Test;
55import org.junit.runners.MethodSorters;
56
57import com.jogamp.newt.event.TraceKeyAdapter;
58import com.jogamp.newt.event.TraceWindowAdapter;
59import com.jogamp.newt.event.awt.AWTKeyAdapter;
60import com.jogamp.newt.event.awt.AWTWindowAdapter;
61import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
62import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
63import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
64import com.jogamp.opengl.test.junit.util.QuitAdapter;
65import com.jogamp.opengl.util.Animator;
66
67@FixMethodOrder(MethodSorters.NAME_ASCENDING)
69
70 static boolean waitForKey = false;
71 /** only when run manually .. */
72 static boolean allow600dpi = false;
73 static GLProfile glp;
74 static int width, height;
75
76 @BeforeClass
77 public static void initClass() {
80 Assert.assertNotNull(glp);
81 width = 640;
82 height = 480;
83 } else {
84 setTestSupported(false);
85 }
86 // Runtime.getRuntime().traceInstructions(true);
87 // Runtime.getRuntime().traceMethodCalls(true);
88 }
89
90 @AfterClass
91 public static void releaseClass() {
92 }
93
94 protected void runTestGL(final GLCapabilities caps) throws InterruptedException, InvocationTargetException {
95 final Dimension glc_sz = new Dimension(width/2, height);
96 final GLCanvas glCanvas1 = new GLCanvas(caps);
97 Assert.assertNotNull(glCanvas1);
98 glCanvas1.setMinimumSize(glc_sz);
99 glCanvas1.setPreferredSize(glc_sz);
100 glCanvas1.setSize(glc_sz);
101 glCanvas1.addGLEventListener(new Gears());
102
103 final GLCanvas glCanvas2 = new GLCanvas(caps);
104 Assert.assertNotNull(glCanvas2);
105 glCanvas2.setMinimumSize(glc_sz);
106 glCanvas2.setPreferredSize(glc_sz);
107 glCanvas2.setSize(glc_sz);
108 glCanvas2.addGLEventListener(new RedSquareES2());
109
110 final Panel demoPanel = new Panel();
111 demoPanel.add(glCanvas1);
112 demoPanel.add(glCanvas2);
113
114 final Frame frame = new Frame("AWT Print");
115 Assert.assertNotNull(frame);
116
117 final ActionListener print72DPIAction = new ActionListener() {
118 public void actionPerformed(final ActionEvent e) {
119 doPrintManual(frame, 72, 0, -1, -1);
120 } };
121 final ActionListener print300DPIAction = new ActionListener() {
122 public void actionPerformed(final ActionEvent e) {
123 doPrintManual(frame, 300, -1, -1, -1);
124 } };
125 final ActionListener print600DPIAction = new ActionListener() {
126 public void actionPerformed(final ActionEvent e) {
127 doPrintManual(frame, 600, -1, -1, -1);
128 } };
129 final Button print72DPIButton = new Button("72dpi");
130 print72DPIButton.addActionListener(print72DPIAction);
131 final Button print300DPIButton = new Button("300dpi");
132 print300DPIButton.addActionListener(print300DPIAction);
133 final Button print600DPIButton = new Button("600dpi");
134 print600DPIButton.addActionListener(print600DPIAction);
135
136 frame.setLayout(new BorderLayout());
137 final Panel printPanel = new Panel();
138 printPanel.add(print72DPIButton);
139 printPanel.add(print300DPIButton);
140 printPanel.add(print600DPIButton);
141 final Panel southPanel = new Panel();
142 southPanel.add(new Label("South"));
143 final Panel eastPanel = new Panel();
144 eastPanel.add(new Label("East"));
145 final Panel westPanel = new Panel();
146 westPanel.add(new Label("West"));
147 frame.add(printPanel, BorderLayout.NORTH);
148 frame.add(demoPanel, BorderLayout.CENTER);
149 frame.add(southPanel, BorderLayout.SOUTH);
150 frame.add(eastPanel, BorderLayout.EAST);
151 frame.add(westPanel, BorderLayout.WEST);
152 frame.setTitle("Tiles AWT Print Test");
153
154 final Animator animator = new Animator();
155 animator.add(glCanvas1);
156 animator.add(glCanvas2);
157
158 final QuitAdapter quitAdapter = new QuitAdapter();
159 new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter), glCanvas1).addTo(glCanvas1);
160 new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter), glCanvas2).addTo(glCanvas2);
161 new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas2).addTo(frame);
162
163 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
164 public void run() {
165 frame.pack();
166 frame.setVisible(true);
167 }});
168 Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true, null));
169 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas1, true, null));
170 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas2, true, null));
171
172 animator.setUpdateFPSFrames(60, System.err);
173 animator.start();
174
175 boolean printDone = false;
176 while(!quitAdapter.shouldQuit() && animator.isAnimating() && ( 0 == duration || animator.getTotalFPSDuration()<duration )) {
177 Thread.sleep(200);
178 if( !printDone ) {
179 printDone = true;
180 {
181 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 72, 0, -1, -1, false /* resizeWithinPrint */);
182 waitUntilPrintJobsIdle(p);
183 }
184 {
185 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 72, 8, -1, -1, false /* resizeWithinPrint */);
186 waitUntilPrintJobsIdle(p);
187 }
188 {
189 // No AA needed for 150 dpi and greater :)
190 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 150, -1, -1, -1, false /* resizeWithinPrint */);
191 waitUntilPrintJobsIdle(p);
192 }
193 {
194 // No AA needed for 150 dpi and greater :)
195 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 150, -1, 2048, 2048, false /* resizeWithinPrint */);
196 waitUntilPrintJobsIdle(p);
197 }
198 {
199 // No AA needed for 150 dpi and greater :)
200 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 150, -1, -1, -1, true /* resizeWithinPrint */);
201 waitUntilPrintJobsIdle(p);
202 }
203 {
204 // No AA needed for 150 dpi and greater :)
205 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, BufferedImage.TYPE_INT_ARGB_PRE /* offscreen-type */, 150, -1, -1, -1, false /* resizeWithinPrint */);
206 waitUntilPrintJobsIdle(p);
207 }
208 {
209 // No AA needed for 150 dpi and greater :)
210 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, BufferedImage.TYPE_INT_ARGB_PRE /* offscreen-type */, 150, -1, -1, -1, true/* resizeWithinPrint */);
211 waitUntilPrintJobsIdle(p);
212 }
213 if( allow600dpi ) {
214 // No AA needed for 300 dpi and greater :)
215 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 600, -1, -1, -1, false /* resizeWithinPrint */);
216 waitUntilPrintJobsIdle(p);
217 }
218 }
219 }
220
221 Assert.assertNotNull(frame);
222 Assert.assertNotNull(glCanvas1);
223 Assert.assertNotNull(glCanvas2);
224 Assert.assertNotNull(animator);
225
226 animator.stop();
227 Assert.assertEquals(false, animator.isAnimating());
228 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
229 public void run() {
230 frame.setVisible(false);
231 }});
232 Assert.assertEquals(false, frame.isVisible());
233 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
234 public void run() {
235 final Frame _frame = frame;
236 _frame.remove(demoPanel);
237 _frame.dispose();
238 }});
239 }
240
241 @Test
242 public void test01_aa0() throws InterruptedException, InvocationTargetException {
243 final GLCapabilities caps = new GLCapabilities(glp);
244 runTestGL(caps);
245 }
246
247 @Test
248 public void test02_aa8() throws InterruptedException, InvocationTargetException {
249 final GLCapabilities caps = new GLCapabilities(glp);
250 caps.setSampleBuffers(true);
251 caps.setNumSamples(8);
252 runTestGL(caps);
253 }
254
255 static long duration = 500; // ms
256
257 public static void main(final String args[]) {
258 for(int i=0; i<args.length; i++) {
259 if(args[i].equals("-time")) {
260 i++;
261 try {
262 duration = Integer.parseInt(args[i]);
263 } catch (final Exception ex) { ex.printStackTrace(); }
264 } else if(args[i].equals("-600dpi")) {
265 allow600dpi = true;
266 } else if(args[i].equals("-wait")) {
267 waitForKey = true;
268 }
269 }
270 if(waitForKey) {
271 final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
272 System.err.println("Press enter to continue");
273 try {
274 System.err.println(stdin.readLine());
275 } catch (final IOException e) { }
276 }
277 org.junit.runner.JUnitCore.main(TestTiledPrintingGearsAWT.class.getName());
278 }
279}
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.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
void setSampleBuffers(final boolean enable)
Defaults to false.
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 heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
Definition: Gears.java:34
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)
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
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.