29package com.jogamp.opengl.test.junit.jogl.awt;
31import com.jogamp.opengl.GLProfile;
32import com.jogamp.opengl.awt.GLJPanel;
33import javax.swing.JFrame;
34import javax.swing.JLabel;
36import com.jogamp.opengl.util.Animator;
37import com.jogamp.opengl.test.junit.util.UITestCase;
38import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
39import com.jogamp.opengl.test.junit.util.MiscUtils;
41import java.awt.BorderLayout;
42import java.awt.Dimension;
44import jogamp.nativewindow.SurfaceScaleUtils;
46import org.junit.Assert;
47import org.junit.Assume;
48import org.junit.Before;
49import org.junit.BeforeClass;
50import org.junit.After;
52import org.junit.FixMethodOrder;
53import org.junit.runners.MethodSorters;
56@FixMethodOrder(MethodSorters.NAME_ASCENDING)
58 static long durationPerTest = 500;
60 final static int sizeEps = 64;
61 final static Dimension size1 =
new Dimension(512, 512-sizeEps-1);
62 final static Dimension size2 =
new Dimension(512+sizeEps+1+256, 512+256);
63 final static Dimension size3 =
new Dimension(512-256, 512-sizeEps-1-256);
82 Assert.assertNotNull(glComp);
88 label1 =
new JLabel(
"L1 - No GLJPanel");
89 label1.setMinimumSize(size1);
90 label1.setPreferredSize(size1);
91 frame1 =
new JFrame(
"Frame 1");
92 Assert.assertNotNull(frame1);
94 frame1.setLocation(0, 0);
96 label2 =
new JLabel(
"L2 - No GLJPanel");
97 label2.setMinimumSize(size2);
98 label2.setPreferredSize(size2);
99 frame2 =
new JFrame(
"Frame 2");
100 Assert.assertNotNull(frame2);
102 frame2.setLocation(size1.width, 0);
104 label3 =
new JLabel(
"L3 - No GLJPanel");
105 label3.setMinimumSize(size3);
106 label3.setPreferredSize(size3);
107 frame3 =
new JFrame(
"Frame 3");
108 Assert.assertNotNull(frame3);
110 frame3.setLocation(0, size1.height);
115 Assert.assertNotNull(frame1);
116 Assert.assertNotNull(frame2);
117 Assert.assertNotNull(glComp);
119 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
126 }
catch (
final Throwable t) {
128 Assume.assumeNoException(t);
139 private void addCanvas(
final JFrame frame,
final JLabel label,
final Dimension size) {
141 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
143 frame.getContentPane().remove(label);
144 glComp.setPreferredSize(size);
145 glComp.setMinimumSize(size);
146 frame.getContentPane().add(glComp, BorderLayout.CENTER);
149 }
catch (
final Throwable t) {
151 Assume.assumeNoException(t);
155 private void removeCanvas(
final JFrame frame,
final JLabel label) {
157 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
159 frame.getContentPane().remove(glComp);
160 frame.getContentPane().add(label);
164 }
catch (
final Throwable t) {
166 Assume.assumeNoException(t);
170 private void setVisible(
final JFrame frame,
final boolean v) {
172 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
177 }
catch (
final Throwable t) {
179 Assume.assumeNoException(t);
183 private void assertSize(
final Dimension expSize) {
184 final float[] scale = { 1f, 1f };
187 final Dimension hasSize = glComp.getSize(
null);
189 Assert.assertTrue(
"AWT Size.width mismatch: expected "+expSize+
", has "+hasSize,
190 Math.abs(expSize.width-hasSize.width) <= sizeEps);
191 Assert.assertTrue(
"AWT Size.height mismatch: expected "+expSize+
", has "+hasSize,
192 Math.abs(expSize.height-hasSize.height) <= sizeEps);
194 final int expSurfWidth = SurfaceScaleUtils.scale(expSize.width, scale[0]);
195 final int expSurfHeight = SurfaceScaleUtils.scale(expSize.height, scale[0]);
199 Assert.assertTrue(
"GL Size.width mismatch: expected "+expSurfWidth+
", has "+hasSurfWidth,
200 Math.abs(expSurfWidth-hasSurfWidth) <= sizeEps);
201 Assert.assertTrue(
"GL Size.height mismatch: expected "+expSurfHeight+
", has "+hasSurfHeight,
202 Math.abs(expSurfHeight-hasSurfHeight) <= sizeEps);
207 setVisible(frame1,
true);
208 setVisible(frame2,
true);
209 setVisible(frame3,
true);
212 addCanvas(frame1, label1, size1);
213 Thread.sleep(durationPerTest);
217 removeCanvas(frame1, label1);
218 addCanvas(frame2, label2, size2);
219 Thread.sleep(durationPerTest);
223 removeCanvas(frame2, label2);
224 addCanvas(frame3, label3, size3);
225 Thread.sleep(durationPerTest);
229 removeCanvas(frame3, label3);
230 addCanvas(frame1, label1, size1);
231 Thread.sleep(durationPerTest);
235 public static void main(
final String args[]) {
236 for(
int i=0; i<args.length; i++) {
237 if(args[i].equals(
"-time")) {
238 durationPerTest =
MiscUtils.
atoi(args[++i], (
int)durationPerTest);
Specifies the the OpenGL profile.
static String glAvailabilityToString(final AbstractGraphicsDevice device)
A lightweight Swing component which provides OpenGL rendering support.
void destroy()
Just an alias for removeNotify.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
float[] getMaximumSurfaceScale(final float[] result)
Returns the maximum pixel scale of the associated NativeSurface.The maximum pixel scale maybe used to...
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
static void main(final String args[])
void testAddRemove3Times()
static int atoi(final String str, final int def)
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.