29package com.jogamp.opengl.test.junit.newt.parenting;
31import java.lang.reflect.*;
33import org.junit.Assert;
34import org.junit.BeforeClass;
36import org.junit.FixMethodOrder;
37import org.junit.runners.MethodSorters;
39import java.awt.BorderLayout;
40import java.awt.Button;
41import java.awt.Container;
42import java.awt.Dimension;
45import com.jogamp.opengl.*;
47import com.jogamp.opengl.util.Animator;
48import com.jogamp.newt.*;
49import com.jogamp.newt.opengl.*;
50import com.jogamp.newt.opengl.util.NEWTDemoListener;
51import com.jogamp.newt.awt.NewtCanvasAWT;
53import java.io.IOException;
55import com.jogamp.opengl.test.junit.util.*;
56import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
66@FixMethodOrder(MethodSorters.NAME_ASCENDING)
68 static Dimension glSize, fSize;
69 static long durationPerTest = 1100;
70 static long waitAdd2nd = 500;
75 glSize =
new Dimension(400,200);
76 fSize =
new Dimension(3*400,2*200);
90 public void testImpl(
final boolean use2nd)
throws InterruptedException, InvocationTargetException {
91 final Frame frame1 =
new Frame(
"AWT Parent Frame");
95 newtCanvasAWT1.setPreferredSize(glSize);
98 setDemoFields(demo1, glWindow1,
false);
111 newtCanvasAWT2.setPreferredSize(glSize);
114 setDemoFields(demo2, glWindow2,
false);
117 animator2 =
new Animator(glWindow2);
121 final Container cont1 =
new Container();
122 cont1.setLayout(
new BorderLayout());
123 cont1.add(
new Button(
"NORTH"), BorderLayout.NORTH);
124 cont1.add(
new Button(
"SOUTH"), BorderLayout.SOUTH);
125 cont1.add(
new Button(
"EAST"), BorderLayout.EAST);
126 cont1.add(
new Button(
"WEST"), BorderLayout.WEST);
127 cont1.add(newtCanvasAWT1, BorderLayout.CENTER);
128 System.err.println(
"******* Cont1 setVisible");
129 cont1.setVisible(
true);
131 final Container cont2 =
new Container();
132 cont2.setLayout(
new BorderLayout());
134 cont2.add(
new Button(
"north"), BorderLayout.NORTH);
135 cont2.add(
new Button(
"sourth"), BorderLayout.SOUTH);
136 cont2.add(
new Button(
"east"), BorderLayout.EAST);
137 cont2.add(
new Button(
"west"), BorderLayout.WEST);
138 cont2.add(newtCanvasAWT2, BorderLayout.CENTER);
140 System.err.println(
"******* Cont2 setVisible");
141 cont2.setVisible(
true);
143 frame1.setLayout(
new BorderLayout());
144 frame1.add(
new Button(
"NORTH"), BorderLayout.NORTH);
145 frame1.add(
new Button(
"CENTER"), BorderLayout.CENTER);
146 frame1.add(
new Button(
"SOUTH"), BorderLayout.SOUTH);
147 frame1.add(cont1, BorderLayout.EAST);
148 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
150 System.err.println(
"******* Frame setVisible");
151 frame1.setLocation(0, 0);
152 frame1.setSize(fSize);
154 frame1.setVisible(
true);
159 Assert.assertEquals(
true, animator1.
isAnimating());
160 Assert.assertEquals(
false, animator1.
isPaused());
161 Assert.assertNotNull(animator1.
getThread());
164 Assert.assertEquals(
true, animator2.
isAnimating());
165 Assert.assertEquals(
false, animator2.
isPaused());
166 Assert.assertNotNull(animator2.
getThread());
168 Thread.sleep(waitAdd2nd);
170 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
172 frame1.add(cont2, BorderLayout.WEST);
179 Thread.sleep(durationPerTest);
182 Assert.assertEquals(
false, animator1.
isAnimating());
183 Assert.assertEquals(
false, animator1.
isPaused());
184 Assert.assertEquals(
null, animator1.
getThread());
188 Assert.assertEquals(
false, animator2.
isAnimating());
189 Assert.assertEquals(
false, animator2.
isPaused());
190 Assert.assertEquals(
null, animator2.
getThread());
193 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
204 Assert.assertNotNull(demo);
205 Assert.assertNotNull(glWindow);
216 static int atoi(
final String a) {
219 i = Integer.parseInt(a);
220 }
catch (
final Exception ex) { ex.printStackTrace(); }
224 public static void main(
final String args[])
throws IOException {
225 for(
int i=0; i<args.length; i++) {
226 if(args[i].equals(
"-time")) {
227 durationPerTest = atoi(args[++i]);
228 }
else if(args[i].equals(
"-wait")) {
229 waitAdd2nd = atoi(args[++i]);
245 org.junit.runner.JUnitCore.
main(tstname);
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 addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
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.
AWT specializing demo functionality of NewtReparentingKeyAdapter, includes NEWTDemoListener.
void test02AWTTwoNewtChilds01()
static void main(final String args[])
void test01AWTOneNewtChilds01()
static void setDemoFields(final GLEventListener demo, final GLWindow glWindow, final boolean debug)
void testImpl(final boolean use2nd)
static boolean setFieldIfExists(final Object instance, final String fieldName, final Object value)
Specifying NEWT's Window functionality:
void setUpdateFPSFrames(int frames, PrintStream out)
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.