29package com.jogamp.opengl.test.junit.jogl.tile;
31import java.awt.BorderLayout;
32import java.awt.Button;
33import java.awt.Container;
34import java.awt.Dimension;
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;
46import com.jogamp.opengl.GLCapabilities;
47import com.jogamp.opengl.GLProfile;
48import com.jogamp.opengl.awt.GLJPanel;
49import javax.swing.BorderFactory;
50import javax.swing.JButton;
51import javax.swing.JComponent;
52import javax.swing.JFrame;
53import javax.swing.JLayeredPane;
54import javax.swing.JPanel;
55import javax.swing.SwingUtilities;
57import org.junit.AfterClass;
58import org.junit.Assert;
59import org.junit.BeforeClass;
60import org.junit.FixMethodOrder;
62import org.junit.runners.MethodSorters;
64import com.jogamp.common.os.Platform;
65import com.jogamp.newt.event.TraceKeyAdapter;
66import com.jogamp.newt.event.TraceWindowAdapter;
67import com.jogamp.newt.event.awt.AWTKeyAdapter;
68import com.jogamp.newt.event.awt.AWTWindowAdapter;
69import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquareES1;
70import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
71import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
72import com.jogamp.opengl.test.junit.util.MiscUtils;
73import com.jogamp.opengl.test.junit.util.QuitAdapter;
74import com.jogamp.opengl.util.Animator;
76@FixMethodOrder(MethodSorters.NAME_ASCENDING)
79 static boolean waitForKey =
false;
81 static boolean allow600dpi =
false;
83 static int width, height;
89 Assert.assertNotNull(glp);
93 setTestSupported(
false);
103 protected void runTestGL(
final GLCapabilities caps,
final boolean layered,
final boolean skipGLOrientationVerticalFlip)
throws InterruptedException, InvocationTargetException {
104 final int layerStepX = width/6, layerStepY = height/6;
105 final Dimension glc_sz =
new Dimension(layered ? width - 2*layerStepX : width/2, layered ? height - 2*layerStepY : height);
107 Assert.assertNotNull(glJPanel1);
109 glJPanel1.setMinimumSize(glc_sz);
110 glJPanel1.setPreferredSize(glc_sz);
112 glJPanel1.setBounds(layerStepX/2, layerStepY/2, glc_sz.width, glc_sz.height);
114 glJPanel1.setBounds(0, 0, glc_sz.width, glc_sz.height);
123 Assert.assertNotNull(glJPanel2);
125 glJPanel2.setMinimumSize(glc_sz);
126 glJPanel2.setPreferredSize(glc_sz);
128 glJPanel2.setBounds(3*layerStepY, 2*layerStepY, glc_sz.width, glc_sz.height);
130 glJPanel2.setBounds(0, 0, glc_sz.width, glc_sz.height);
138 final JComponent demoPanel;
142 final Dimension lsz =
new Dimension(width, height);
143 demoPanel =
new JLayeredPane();
144 demoPanel.setMinimumSize(lsz);
145 demoPanel.setPreferredSize(lsz);
146 demoPanel.setBounds(0, 0, lsz.width, lsz.height);
147 demoPanel.setBorder(BorderFactory.createTitledBorder(
"Layered Pane"));
148 demoPanel.add(glJPanel1, JLayeredPane.DEFAULT_LAYER);
149 demoPanel.add(glJPanel2, Integer.valueOf(1));
150 final JButton tb =
new JButton(
"On Top");
151 tb.setBounds(4*layerStepY, 3*layerStepY, 100, 50);
152 demoPanel.add(tb, Integer.valueOf(2));
154 demoPanel =
new JPanel();
155 demoPanel.add(glJPanel1);
156 demoPanel.add(glJPanel2);
159 final JFrame frame =
new JFrame(
"Swing Print");
160 Assert.assertNotNull(frame);
162 final ActionListener print72DPIAction =
new ActionListener() {
163 public void actionPerformed(
final ActionEvent e) {
164 doPrintManual(frame, 72, 0, -1, -1);
166 final ActionListener print300DPIAction =
new ActionListener() {
167 public void actionPerformed(
final ActionEvent e) {
168 doPrintManual(frame, 300, -1, -1, -1);
170 final ActionListener print600DPIAction =
new ActionListener() {
171 public void actionPerformed(
final ActionEvent e) {
172 doPrintManual(frame, 600, -1, -1, -1);
174 final Button print72DPIButton =
new Button(
"72dpi");
175 print72DPIButton.addActionListener(print72DPIAction);
176 final Button print300DPIButton =
new Button(
"300dpi");
177 print300DPIButton.addActionListener(print300DPIAction);
178 final Button print600DPIButton =
new Button(
"600dpi");
179 print600DPIButton.addActionListener(print600DPIAction);
181 final JPanel printPanel =
new JPanel();
182 printPanel.add(print72DPIButton);
183 printPanel.add(print300DPIButton);
184 printPanel.add(print600DPIButton);
185 final JPanel southPanel =
new JPanel();
186 southPanel.add(
new Label(
"South"));
187 final JPanel eastPanel =
new JPanel();
188 eastPanel.add(
new Label(
"East"));
189 final JPanel westPanel =
new JPanel();
190 westPanel.add(
new Label(
"West"));
193 animator.
add(glJPanel1);
194 animator.
add(glJPanel2);
200 SwingUtilities.invokeAndWait(
new Runnable() {
202 final Container fcont = frame.getContentPane();
203 fcont.setLayout(
new BorderLayout());
204 fcont.add(printPanel, BorderLayout.NORTH);
205 fcont.add(demoPanel, BorderLayout.CENTER);
206 fcont.add(southPanel, BorderLayout.SOUTH);
207 fcont.add(eastPanel, BorderLayout.EAST);
208 fcont.add(westPanel, BorderLayout.WEST);
211 frame.setVisible(
true);
220 Assert.assertEquals(
true, animator.isAnimating());
222 boolean printDone =
false;
223 while(!quitAdapter.shouldQuit() && animator.isAnimating() && ( 0 == duration || animator.
getTotalFPSDuration()<duration )) {
228 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE,
null, -1 , 72, 0, -1, -1,
false );
229 waitUntilPrintJobsIdle(p);
232 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE,
null, -1 , 72, 8, -1, -1,
false );
233 waitUntilPrintJobsIdle(p);
237 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE,
null, -1 , 150, -1, -1, -1,
false );
238 waitUntilPrintJobsIdle(p);
242 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE,
null, -1 , 150, -1, 2048, 2048,
false );
243 waitUntilPrintJobsIdle(p);
247 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE,
null, -1 , 150, -1, -1, -1,
true );
248 waitUntilPrintJobsIdle(p);
252 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE,
null, BufferedImage.TYPE_INT_ARGB_PRE , 150, -1, -1, -1,
false );
253 waitUntilPrintJobsIdle(p);
257 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE,
null, BufferedImage.TYPE_INT_ARGB , 150, -1, -1, -1,
false );
258 waitUntilPrintJobsIdle(p);
262 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE,
null, BufferedImage.TYPE_INT_RGB , 150, -1, -1, -1,
false );
263 waitUntilPrintJobsIdle(p);
267 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE,
null, BufferedImage.TYPE_INT_BGR , 150, -1, -1, -1,
false );
268 waitUntilPrintJobsIdle(p);
272 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE,
null, BufferedImage.TYPE_INT_ARGB_PRE , 150, -1, -1, -1,
true );
273 waitUntilPrintJobsIdle(p);
277 final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE,
null, -1 , 600, -1, -1, -1,
false );
278 waitUntilPrintJobsIdle(p);
283 Assert.assertNotNull(frame);
284 Assert.assertNotNull(glJPanel1);
285 Assert.assertNotNull(glJPanel2);
286 Assert.assertNotNull(animator);
289 Assert.assertEquals(
false, animator.isAnimating());
290 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
292 frame.setVisible(
false);
294 Assert.assertEquals(
false, frame.isVisible());
295 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
297 final Frame _frame = frame;
298 _frame.remove(demoPanel);
306 runTestGL(caps,
false,
false);
313 runTestGL(caps,
true,
false);
318 if( Platform.OSType.WINDOWS == Platform.getOSType() ) {
321 runTestGL(caps,
false,
false);
327 if( Platform.OSType.WINDOWS == Platform.getOSType() ) {
331 runTestGL(caps,
true,
false);
340 runTestGL(caps,
false,
false);
346 runTestGL(caps,
false,
true);
353 runTestGL(caps,
true,
true);
358 if( Platform.OSType.WINDOWS == Platform.getOSType() ) {
361 runTestGL(caps,
false,
true);
367 if( Platform.OSType.WINDOWS == Platform.getOSType() ) {
371 runTestGL(caps,
true,
true);
380 runTestGL(caps,
false,
true);
383 static long duration = 500;
385 public static void main(
final String args[]) {
386 for(
int i=0; i<args.length; i++) {
387 if(args[i].equals(
"-time")) {
390 }
else if(args[i].equals(
"-width")) {
393 }
else if(args[i].equals(
"-height")) {
396 }
else if(args[i].equals(
"-600dpi")) {
398 }
else if(args[i].equals(
"-wait")) {
403 final BufferedReader stdin =
new BufferedReader(
new InputStreamReader(System.in));
404 System.err.println(
"Press enter to continue");
406 System.err.println(stdin.readLine());
407 }
catch (
final IOException e) { }
void setBitmap(final boolean enable)
Requesting offscreen bitmap mode.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
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.
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
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.
A lightweight Swing component which provides OpenGL rendering support.
final void setSkipGLOrientationVerticalFlip(final boolean v)
Skip isGLOriented() based vertical flip, which usually is required by the offscreen backend,...
void setOpaque(final boolean opaque)
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
void setFlipVerticalInGLOrientation(final boolean v)
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
void setFlipVerticalInGLOrientation(final boolean v)
Base Printable implementation class.
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)
static long atol(final String str, final long def)
final long getTotalFPSDuration()
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.
final synchronized boolean stop()
Stops this animator.