29package com.jogamp.opengl.test.junit.jogl.tile;
31import java.awt.BorderLayout;
32import java.awt.Button;
33import java.awt.Container;
34import java.awt.Dimension;
36import java.awt.Graphics2D;
37import java.awt.Insets;
39import java.awt.RenderingHints;
40import java.awt.image.BufferedImage;
41import java.io.BufferedReader;
43import java.io.IOException;
44import java.io.InputStreamReader;
45import java.lang.reflect.InvocationTargetException;
47import javax.imageio.ImageIO;
48import com.jogamp.opengl.GLCapabilities;
49import com.jogamp.opengl.GLProfile;
50import com.jogamp.opengl.awt.GLJPanel;
51import javax.swing.BorderFactory;
52import javax.swing.JButton;
53import javax.swing.JComponent;
54import javax.swing.JFrame;
55import javax.swing.JLayeredPane;
56import javax.swing.JPanel;
57import javax.swing.SwingUtilities;
59import org.junit.AfterClass;
60import org.junit.Assert;
61import org.junit.BeforeClass;
62import org.junit.FixMethodOrder;
64import org.junit.runners.MethodSorters;
66import com.jogamp.common.util.awt.AWTEDTExecutor;
67import com.jogamp.nativewindow.awt.AWTPrintLifecycle;
68import com.jogamp.nativewindow.awt.DirectDataBufferInt;
69import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
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.UITestCase;
73import com.jogamp.opengl.util.texture.TextureIO;
75@FixMethodOrder(MethodSorters.NAME_ASCENDING)
78 static boolean waitForKey =
false;
80 static boolean allow600dpi =
false;
82 static int width, height;
88 Assert.assertNotNull(glp);
92 setTestSupported(
false);
103 final Insets frameInsets = frame.getInsets();
104 final int frameWidth = frame.getWidth();
105 final int frameHeight= frame.getHeight();
106 final int imageWidth = image.getWidth();
107 final int imageHeight= image.getHeight();
108 final double scaleComp72;
111 final double sx = (double)imageWidth / frameWidth;
112 final double sy = (double)imageHeight / frameHeight;
113 scaleComp72 = Math.min(sx, sy);
115 System.err.println(
"PRINT DPI: scaleComp72 "+scaleComp72+
", image-size "+imageWidth+
"x"+imageHeight+
", frame[border "+frameInsets+
", size "+frameWidth+
"x"+frameHeight+
"]");
117 System.err.println(
"XXX: image "+image);
118 System.err.println(
"XXX: cm "+image.getColorModel());
119 System.err.println(
"XXX: raster "+image.getRaster());
120 System.err.println(
"XXX: dataBuffer "+image.getRaster().getDataBuffer());
122 AWTEDTExecutor.singleton.invoke(
true,
new Runnable() {
124 final Graphics2D g2d = (Graphics2D) image.getGraphics();
125 g2d.setClip(0, 0, image.getWidth(), image.getHeight());
126 g2d.scale(scaleComp72, scaleComp72);
128 g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
138 final String fname = getSnapshotFilename(num, detail, caps, image.getWidth(), image.getHeight(),
false,
TextureIO.
PNG,
null);
139 System.err.println(
"XXX file "+fname);
140 final File fout =
new File(fname);
142 ImageIO.write(image,
"png", fout);
143 }
catch (
final IOException e) {
149 protected void runTestGL(
final GLCapabilities caps,
final boolean layered)
throws InterruptedException, InvocationTargetException {
150 final int layerStepX = width/6, layerStepY = height/6;
151 final Dimension glc_sz =
new Dimension(layered ? width - 2*layerStepX : width/2, layered ? height - 2*layerStepY : height);
153 Assert.assertNotNull(glJPanel1);
154 glJPanel1.setMinimumSize(glc_sz);
155 glJPanel1.setPreferredSize(glc_sz);
157 glJPanel1.setBounds(layerStepX/2, layerStepY/2, glc_sz.width, glc_sz.height);
159 glJPanel1.setBounds(0, 0, glc_sz.width, glc_sz.height);
164 Assert.assertNotNull(glJPanel2);
165 glJPanel2.setMinimumSize(glc_sz);
166 glJPanel2.setPreferredSize(glc_sz);
168 glJPanel2.setBounds(3*layerStepY, 2*layerStepY, glc_sz.width, glc_sz.height);
170 glJPanel2.setBounds(0, 0, glc_sz.width, glc_sz.height);
175 final JComponent demoPanel;
179 final Dimension lsz =
new Dimension(width, height);
180 demoPanel =
new JLayeredPane();
181 demoPanel.setMinimumSize(lsz);
182 demoPanel.setPreferredSize(lsz);
183 demoPanel.setBounds(0, 0, lsz.width, lsz.height);
184 demoPanel.setBorder(BorderFactory.createTitledBorder(
"Layered Pane"));
185 demoPanel.add(glJPanel1, JLayeredPane.DEFAULT_LAYER);
186 demoPanel.add(glJPanel2, Integer.valueOf(1));
187 final JButton tb =
new JButton(
"On Top");
188 tb.setBounds(4*layerStepY, 3*layerStepY, 100, 50);
189 demoPanel.add(tb, Integer.valueOf(2));
191 demoPanel =
new JPanel();
192 demoPanel.add(glJPanel1);
193 demoPanel.add(glJPanel2);
196 final JFrame frame =
new JFrame(
"Swing Print");
197 Assert.assertNotNull(frame);
199 final Button print72DPIButton =
new Button(
"72dpi");
200 final Button print300DPIButton =
new Button(
"300dpi");
201 final Button print600DPIButton =
new Button(
"600dpi");
203 final JPanel printPanel =
new JPanel();
204 printPanel.add(print72DPIButton);
205 printPanel.add(print300DPIButton);
206 printPanel.add(print600DPIButton);
207 final JPanel southPanel =
new JPanel();
208 southPanel.add(
new Label(
"South"));
209 final JPanel eastPanel =
new JPanel();
210 eastPanel.add(
new Label(
"East"));
211 final JPanel westPanel =
new JPanel();
212 westPanel.add(
new Label(
"West"));
214 SwingUtilities.invokeAndWait(
new Runnable() {
216 final Container fcont = frame.getContentPane();
217 fcont.setLayout(
new BorderLayout());
218 fcont.add(printPanel, BorderLayout.NORTH);
219 fcont.add(demoPanel, BorderLayout.CENTER);
220 fcont.add(southPanel, BorderLayout.SOUTH);
221 fcont.add(eastPanel, BorderLayout.EAST);
222 fcont.add(westPanel, BorderLayout.WEST);
225 frame.setVisible(
true);
234 final BufferedImage image =
new BufferedImage(frame.getWidth(), frame.getHeight(), BufferedImage.TYPE_INT_ARGB);
235 printOffscreenToFile(image, frame, caps, 0,
"array_072dpi_argb");
240 printOffscreenToFile(image, frame, caps, 1,
"newio_072dpi_argb");
244 final int scale = (int) ( 150.0 / 72.0 + 0.5 );
246 printOffscreenToFile(image, frame, caps, 2,
"newio_150dpi_argb");
250 final int scale = (int) ( 150.0 / 72.0 + 0.5 );
252 printOffscreenToFile(image, frame, caps, 2,
"newio_150dpi_argbp");
256 final int scale = (int) ( 150.0 / 72.0 + 0.5 );
258 printOffscreenToFile(image, frame, caps, 2,
"newio_150dpi_rgb");
262 final int scale = (int) ( 150.0 / 72.0 + 0.5 );
264 printOffscreenToFile(image, frame, caps, 2,
"newio_150dpi_bgr");
267 Assert.assertNotNull(frame);
268 Assert.assertNotNull(glJPanel1);
269 Assert.assertNotNull(glJPanel2);
271 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
273 frame.setVisible(
false);
275 Assert.assertEquals(
false, frame.isVisible());
276 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
278 final Frame _frame = frame;
279 _frame.remove(demoPanel);
287 runTestGL(caps,
false);
293 runTestGL(caps,
true);
296 static long duration = 500;
298 public static void main(
final String args[]) {
299 for(
int i=0; i<args.length; i++) {
300 if(args[i].equals(
"-time")) {
303 duration = Integer.parseInt(args[i]);
304 }
catch (
final Exception ex) { ex.printStackTrace(); }
305 }
else if(args[i].equals(
"-600dpi")) {
307 }
else if(args[i].equals(
"-wait")) {
312 final BufferedReader stdin =
new BufferedReader(
new InputStreamReader(System.in));
313 System.err.println(
"Press enter to continue");
315 System.err.println(stdin.readLine());
316 }
catch (
final IOException e) { }
Convenient AWTPrintLifecycle context simplifying calling setupPrint(..) and AWTPrintLifecycle#release...
static Context setupPrint(final Container c, final double scaleMatX, final double scaleMatY, final int numSamples, final int tileWidth, final int tileHeight)
DataBuffer specialization using NIO direct buffer of type DataBuffer#TYPE_INT as storage.
static BufferedImageInt createBufferedImage(final int width, final int height, final int imageType, Point location, final Hashtable<?,?> properties)
Creates a BufferedImageInt using a direct color model in sRGB color space.
Specifies a set of OpenGL capabilities.
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.
void setOpaque(final boolean opaque)
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
void printOffscreenToFile(final BufferedImage image, final Frame frame, final GLCapabilities caps, final int num, final String detail)
void test01_Offscreen_aa0()
void runTestGL(final GLCapabilities caps, final boolean layered)
void test01_Offscreen_aa0_layered()
static void releaseClass()
static void main(final String args[])
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 final String PNG
Constant which can be used as a file suffix to indicate a PNG file, value {@value}.
Interface describing print lifecycle to support AWT printing, e.g.