29package com.jogamp.opengl.test.junit.jogl.acore.anim;
32import java.lang.reflect.InvocationTargetException;
34import com.jogamp.opengl.GLCapabilities;
35import com.jogamp.opengl.awt.GLJPanel;
37import com.jogamp.opengl.util.Animator;
38import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
39import com.jogamp.opengl.test.junit.util.GLTestUtil;
40import com.jogamp.opengl.test.junit.util.UITestCase;
41import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
43import org.junit.Assert;
45import org.junit.FixMethodOrder;
46import org.junit.runners.MethodSorters;
48@FixMethodOrder(MethodSorters.NAME_ASCENDING)
50 static final int width = 400;
51 static final int height = 400;
55 Assert.assertNotNull(glCanvas);
58 frame.setLocation(x, y);
59 frame.setSize(width, height);
60 frame.setTitle(
"GLJPanel: "+x+
"/"+y);
64 static void pauseAnimator(
final Animator animator,
final boolean pause) {
67 Assert.assertEquals(
true, animator.
isStarted());
68 Assert.assertEquals(
true, animator.
isPaused());
69 Assert.assertEquals(
false, animator.isAnimating());
72 Assert.assertEquals(
true, animator.
isStarted());
73 Assert.assertEquals(
false, animator.
isPaused());
74 Assert.assertEquals(
true, animator.isAnimating());
77 static void stopAnimator(
final Animator animator) {
79 Assert.assertEquals(
false, animator.isStarted());
80 Assert.assertEquals(
false, animator.isPaused());
81 Assert.assertEquals(
false, animator.isAnimating());
87 final Frame f1 =
new Frame();
90 Assert.assertEquals(
true, animator.
isStarted());
91 Assert.assertEquals(
true, animator.
isPaused());
92 Assert.assertEquals(
false, animator.isAnimating());
95 final GLJPanel c1 = createGLJPanel(caps, f1, 0, 0, g1);
97 Assert.assertEquals(
true, animator.
isStarted());
98 Assert.assertEquals(
false, animator.
isPaused());
99 Assert.assertEquals(
true, animator.isAnimating());
101 final Frame f2 =
new Frame();
103 final GLJPanel c2 = createGLJPanel(caps, f2, f1.getX()+width,
107 final Frame f3 =
new Frame();
109 final GLJPanel c3 = createGLJPanel(caps, f3, f1.getX()+0,
110 f1.getY()+height, g3);
113 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
124 Assert.assertTrue(
"Gears1 not initialized", g1.
waitForInit(
true));
129 Assert.assertTrue(
"Gears2 not initialized", g2.
waitForInit(
true));
134 Assert.assertTrue(
"Gears3 not initialized", g3.
waitForInit(
true));
137 Thread.sleep(duration/3);
138 }
catch(
final Exception e) {
142 pauseAnimator(animator,
true);
145 Thread.sleep(duration/3);
146 }
catch(
final Exception e) {
150 pauseAnimator(animator,
false);
153 Thread.sleep(duration/3);
154 }
catch(
final Exception e) {
160 stopAnimator(animator);
162 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
169 }
catch (
final Throwable t) {
170 throw new RuntimeException(t);
182 final Frame f1 =
new Frame();
185 final GLJPanel c1 = createGLJPanel(caps, f1, 0, 0, g1);
188 Assert.assertEquals(
true, a1.
isStarted());
189 Assert.assertEquals(
false, a1.
isPaused());
190 Assert.assertEquals(
true, a1.isAnimating());
191 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
197 final Frame f2 =
new Frame();
200 final GLJPanel c2 = createGLJPanel(caps, f2, f1.getX()+width, f1.getY()+0, g2);
203 Assert.assertEquals(
true, a2.
isStarted());
204 Assert.assertEquals(
false, a2.
isPaused());
205 Assert.assertEquals(
true, a2.isAnimating());
206 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
212 final Frame f3 =
new Frame();
215 final GLJPanel c3 = createGLJPanel(caps, f3, f1.getX()+0, f1.getY()+height, g3);
218 Assert.assertEquals(
true, a3.
isStarted());
219 Assert.assertEquals(
false, a3.
isPaused());
220 Assert.assertEquals(
true, a3.isAnimating());
221 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
230 Assert.assertTrue(
"Gears1 not initialized", g1.
waitForInit(
true));
235 Assert.assertTrue(
"Gears2 not initialized", g2.
waitForInit(
true));
240 Assert.assertTrue(
"Gears3 not initialized", g3.
waitForInit(
true));
243 Thread.sleep(duration/3);
244 }
catch(
final Exception e) {
248 pauseAnimator(a1,
true);
249 pauseAnimator(a2,
true);
250 pauseAnimator(a3,
true);
253 Thread.sleep(duration/3);
254 }
catch(
final Exception e) {
258 pauseAnimator(a1,
false);
259 pauseAnimator(a2,
false);
260 pauseAnimator(a3,
false);
263 Thread.sleep(duration/3);
264 }
catch(
final Exception e) {
274 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
281 }
catch (
final Throwable t) {
282 throw new RuntimeException(t);
291 static long duration = 3*500;
293 public static void main(
final String args[]) {
294 for(
int i=0; i<args.length; i++) {
295 if(args[i].equals(
"-time")) {
298 duration = Integer.parseInt(args[i]);
299 }
catch (
final Exception ex) { ex.printStackTrace(); }
Specifies a set of OpenGL capabilities.
A lightweight Swing component which provides OpenGL rendering support.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
void test01SyncedOneAnimator()
void test02AsyncEachAnimator()
GLJPanel createGLJPanel(final GLCapabilities caps, final Frame frame, final int x, final int y, final GearsES2 gears)
static void main(final String args[])
boolean waitForInit(final boolean initialized)
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 boolean waitForContextCreated(final GLAutoDrawable autoDrawable, final boolean created, final Runnable waitAction)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
synchronized boolean isStarted()
Indicates whether this animator has been started.
final synchronized boolean pause()
Pauses this animator.
final synchronized boolean resume()
Resumes animation if paused.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean isPaused()
Indicates whether this animator is started and either manually paused or paused automatically due to ...