JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestTiledPrintingGearsNewtAWT.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;
48
49import org.junit.AfterClass;
50import org.junit.Assert;
51import org.junit.BeforeClass;
52import org.junit.FixMethodOrder;
53import org.junit.Test;
54import org.junit.runners.MethodSorters;
55
56import com.jogamp.newt.awt.NewtCanvasAWT;
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.newt.opengl.GLWindow;
62import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
63import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
64import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
65import com.jogamp.opengl.test.junit.util.QuitAdapter;
66import com.jogamp.opengl.util.Animator;
67
68@FixMethodOrder(MethodSorters.NAME_ASCENDING)
70
71 static boolean waitForKey = false;
72 /** only when run manually .. */
73 static boolean allow600dpi = false;
74 static GLProfile glp;
75 static int width, height;
76
77 @BeforeClass
78 public static void initClass() {
81 Assert.assertNotNull(glp);
82 width = 640;
83 height = 480;
84 } else {
85 setTestSupported(false);
86 }
87 // Runtime.getRuntime().traceInstructions(true);
88 // Runtime.getRuntime().traceMethodCalls(true);
89 }
90
91 @AfterClass
92 public static void releaseClass() {
93 }
94
95 protected void runTestGL(final GLCapabilities caps) throws InterruptedException, InvocationTargetException {
96 final Dimension glc_sz = new Dimension(width/2, height);
97 final GLWindow glad1 = GLWindow.create(caps);
98 Assert.assertNotNull(glad1);
99 final NewtCanvasAWT canvas1 = new NewtCanvasAWT(glad1);
100 Assert.assertNotNull(canvas1);
101 canvas1.setMinimumSize(glc_sz);
102 canvas1.setPreferredSize(glc_sz);
103 canvas1.setSize(glc_sz);
104 glad1.addGLEventListener(new Gears());
105
106 final GLWindow glad2 = GLWindow.create(caps);
107 Assert.assertNotNull(glad2);
108 final NewtCanvasAWT canvas2 = new NewtCanvasAWT(glad2);
109 Assert.assertNotNull(canvas2);
110 canvas2.setMinimumSize(glc_sz);
111 canvas2.setPreferredSize(glc_sz);
112 canvas2.setSize(glc_sz);
113 glad2.addGLEventListener(new RedSquareES2());
114
115 final Panel demoPanel = new Panel();
116 demoPanel.add(canvas1);
117 demoPanel.add(canvas2);
118
119 final Frame frame = new Frame("Newt/AWT Print");
120 Assert.assertNotNull(frame);
121
122 final ActionListener print72DPIAction = new ActionListener() {
123 public void actionPerformed(final ActionEvent e) {
124 doPrintManual(frame, 72, 0, -1, -1);
125 } };
126 final ActionListener print300DPIAction = new ActionListener() {
127 public void actionPerformed(final ActionEvent e) {
128 doPrintManual(frame, 300, -1, -1, -1);
129 } };
130 final ActionListener print600DPIAction = new ActionListener() {
131 public void actionPerformed(final ActionEvent e) {
132 doPrintManual(frame, 600, -1, -1, -1);
133 } };
134 final Button print72DPIButton = new Button("72dpi");
135 print72DPIButton.addActionListener(print72DPIAction);
136 final Button print300DPIButton = new Button("300dpi");
137 print300DPIButton.addActionListener(print300DPIAction);
138 final Button print600DPIButton = new Button("600dpi");
139 print600DPIButton.addActionListener(print600DPIAction);
140
141 frame.setLayout(new BorderLayout());
142 final Panel printPanel = new Panel();
143 printPanel.add(print72DPIButton);
144 printPanel.add(print300DPIButton);
145 printPanel.add(print600DPIButton);
146 final Panel southPanel = new Panel();
147 southPanel.add(new Label("South"));
148 final Panel eastPanel = new Panel();
149 eastPanel.add(new Label("East"));
150 final Panel westPanel = new Panel();
151 westPanel.add(new Label("West"));
152 frame.add(printPanel, BorderLayout.NORTH);
153 frame.add(demoPanel, BorderLayout.CENTER);
154 frame.add(southPanel, BorderLayout.SOUTH);
155 frame.add(eastPanel, BorderLayout.EAST);
156 frame.add(westPanel, BorderLayout.WEST);
157 frame.setTitle("Tiles Newt/AWT Print Test");
158
159 final Animator animator = new Animator();
160 animator.add(glad1);
161 animator.add(glad2);
162
163 final QuitAdapter quitAdapter = new QuitAdapter();
164 new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter), canvas1.getNEWTChild()).addTo(canvas1);
165 new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter), canvas2.getNEWTChild()).addTo(canvas2);
166 new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), canvas2.getNEWTChild()).addTo(frame);
167
168 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
169 public void run() {
170 frame.pack();
171 frame.setVisible(true);
172 }});
173 Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true, null));
174 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(canvas1, true, null));
175 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(canvas2, true, null));
176
177 animator.setUpdateFPSFrames(60, System.err);
178 animator.start();
179
180 boolean printDone = false;
181 while(!quitAdapter.shouldQuit() && animator.isAnimating() && ( 0 == duration || animator.getTotalFPSDuration()<duration )) {
182 Thread.sleep(200);
183 if( !printDone ) {
184 printDone = true;
185 {
186 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 72, 0, -1, -1, false /* resizeWithinPrint */);
187 waitUntilPrintJobsIdle(p);
188 }
189 {
190 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 72, 8, -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, -1, -1, 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, 2048, 2048, false /* resizeWithinPrint */);
201 waitUntilPrintJobsIdle(p);
202 }
203 {
204 // No AA needed for 150 dpi and greater :)
205 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 150, -1, -1, -1, true /* 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, false /* resizeWithinPrint */);
211 waitUntilPrintJobsIdle(p);
212 }
213 {
214 // No AA needed for 150 dpi and greater :)
215 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, BufferedImage.TYPE_INT_ARGB_PRE /* offscreen-type */, 150, -1, -1, -1, true /* resizeWithinPrint */);
216 waitUntilPrintJobsIdle(p);
217 }
218 if( allow600dpi ) {
219 // No AA needed for 300 dpi and greater :)
220 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 600, -1, -1, -1, false /* resizeWithinPrint */);
221 waitUntilPrintJobsIdle(p);
222 }
223 }
224 }
225
226 Assert.assertNotNull(frame);
227 Assert.assertNotNull(canvas1);
228 Assert.assertNotNull(canvas2);
229 Assert.assertNotNull(animator);
230
231 animator.stop();
232 Assert.assertEquals(false, animator.isAnimating());
233 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
234 public void run() {
235 frame.setVisible(false);
236 }});
237 Assert.assertEquals(false, frame.isVisible());
238 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
239 public void run() {
240 final Frame _frame = frame;
241 _frame.remove(demoPanel);
242 _frame.dispose();
243 }});
244 glad1.destroy();
245 glad2.destroy();
246 }
247
248 @Test
249 public void test01_aa0() throws InterruptedException, InvocationTargetException {
250 final GLCapabilities caps = new GLCapabilities(glp);
251 runTestGL(caps);
252 }
253
254 @Test
255 public void test02_aa8() throws InterruptedException, InvocationTargetException {
256 final GLCapabilities caps = new GLCapabilities(glp);
257 caps.setSampleBuffers(true);
258 caps.setNumSamples(8);
259 runTestGL(caps);
260 }
261
262 static long duration = 500; // ms
263
264 public static void main(final String args[]) {
265 for(int i=0; i<args.length; i++) {
266 if(args[i].equals("-time")) {
267 i++;
268 try {
269 duration = Integer.parseInt(args[i]);
270 } catch (final Exception ex) { ex.printStackTrace(); }
271 } else if(args[i].equals("-600dpi")) {
272 allow600dpi = true;
273 } else if(args[i].equals("-wait")) {
274 waitForKey = true;
275 }
276 }
277 if(waitForKey) {
278 final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
279 System.err.println("Press enter to continue");
280 try {
281 System.err.println(stdin.readLine());
282 } catch (final IOException e) { }
283 }
284 org.junit.runner.JUnitCore.main(TestTiledPrintingGearsNewtAWT.class.getName());
285 }
286}
AWT Canvas containing a NEWT Window using native parenting.
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...
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
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
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 addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.