29package com.jogamp.opengl.test.junit.newt.parenting;
31import org.junit.Assert;
32import org.junit.BeforeClass;
34import org.junit.FixMethodOrder;
35import org.junit.runners.MethodSorters;
37import java.awt.Button;
38import java.awt.BorderLayout;
41import com.jogamp.opengl.*;
42import javax.swing.SwingUtilities;
44import com.jogamp.opengl.util.Animator;
45import com.jogamp.opengl.util.FPSAnimator;
46import com.jogamp.newt.*;
47import com.jogamp.newt.opengl.*;
48import com.jogamp.newt.awt.NewtCanvasAWT;
50import java.io.IOException;
51import java.lang.reflect.InvocationTargetException;
53import com.jogamp.opengl.test.junit.util.*;
54import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
56@FixMethodOrder(MethodSorters.NAME_ASCENDING)
58 static int width, height;
59 static long durationPerTest = 800;
60 static long waitReparent = 0;
72 testAWTWinHopFrame2FrameImpl(25);
77 testAWTWinHopFrame2FrameImpl(0);
84 setDemoFields(demo1, glWindow1,
false);
89 final Frame frame1 =
new Frame(
"AWT Parent Frame");
90 frame1.setLayout(
new BorderLayout());
91 frame1.add(
new Button(
"North"), BorderLayout.NORTH);
92 frame1.add(
new Button(
"South"), BorderLayout.SOUTH);
93 frame1.add(
new Button(
"East"), BorderLayout.EAST);
94 frame1.add(
new Button(
"West"), BorderLayout.WEST);
95 SwingUtilities.invokeAndWait(
new Runnable() {
97 frame1.setSize(width, height);
98 frame1.setLocation(0, 0);
99 frame1.setVisible(
true);
103 final Frame frame2 =
new Frame(
"AWT Parent Frame");
104 frame2.setLayout(
new BorderLayout());
105 frame2.add(
new Button(
"North"), BorderLayout.NORTH);
106 frame2.add(
new Button(
"South"), BorderLayout.SOUTH);
107 frame2.add(
new Button(
"East"), BorderLayout.EAST);
108 frame2.add(
new Button(
"West"), BorderLayout.WEST);
109 SwingUtilities.invokeAndWait(
new Runnable() {
111 frame2.setSize(width, height);
112 frame2.setLocation(640, 480);
113 frame2.setVisible(
true);
117 SwingUtilities.invokeAndWait(
new Runnable() {
119 frame1.add(newtCanvasAWT, BorderLayout.CENTER);
129 animator1 =
new Animator(glWindow1);
134 for(state=0; state<3; state++) {
135 Thread.sleep(durationPerTest);
138 SwingUtilities.invokeAndWait(
new Runnable() {
140 frame1.remove(newtCanvasAWT);
141 frame2.add(newtCanvasAWT, BorderLayout.CENTER);
148 SwingUtilities.invokeAndWait(
new Runnable() {
150 frame2.remove(newtCanvasAWT);
151 frame1.add(newtCanvasAWT, BorderLayout.CENTER);
160 Assert.assertEquals(
true, animator1.
isAnimating());
161 Assert.assertEquals(
false, animator1.
isPaused());
162 Assert.assertNotNull(animator1.
getThread());
164 Assert.assertEquals(
false, animator1.
isAnimating());
165 Assert.assertEquals(
false, animator1.
isPaused());
166 Assert.assertEquals(
null, animator1.
getThread());
168 SwingUtilities.invokeAndWait(
new Runnable() {
177 Assert.assertNotNull(demo);
178 Assert.assertNotNull(glWindow);
189 static int atoi(
final String a) {
192 i = Integer.parseInt(a);
193 }
catch (
final Exception ex) { ex.printStackTrace(); }
197 public static void main(
final String args[])
throws IOException {
198 for(
int i=0; i<args.length; i++) {
199 if(args[i].equals(
"-time")) {
200 durationPerTest = atoi(args[++i]);
201 }
else if(args[i].equals(
"-wait")) {
202 waitReparent = atoi(args[++i]);
206 org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.
main(
new String[] {
210 "haltOnFailure=false",
212 "outputtoformatters=true",
213 "logfailedtests=true",
214 "logtestlistenerevents=true",
215 "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
216 "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+
".xml" } );
AWT Canvas containing a NEWT Window using native parenting.
NativeWindow getNativeWindow()
Returns the associated NativeWindow of this NativeWindowHolder, which is identical to getNativeSurfac...
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final NativeWindow getParent()
final void setUndecorated(final boolean value)
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
void test01AWTWinHopFrame2FrameFPS25Animator()
static void main(final String args[])
void testAWTWinHopFrame2FrameImpl(final int fps)
void test02AWTWinHopFrame2FrameStdAnimator()
static void setDemoFields(final GLEventListener demo, final GLWindow glWindow, final boolean debug)
static boolean setFieldIfExists(final Object instance, final String fieldName, final Object value)
An Animator subclass which attempts to achieve a target frames-per-second rate to avoid using all CPU...
Specifying NEWT's Window functionality:
An animator control interface, which implementation may drive a com.jogamp.opengl....
boolean start()
Starts this animator, if not running.
boolean isPaused()
Indicates whether this animator is started and either manually paused or paused automatically due to ...
boolean isAnimating()
Indicates whether this animator is started and is not paused.
boolean stop()
Stops this animator.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.