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;
39import java.awt.Container;
42import com.jogamp.opengl.*;
43import javax.swing.SwingUtilities;
45import com.jogamp.opengl.util.Animator;
46import com.jogamp.newt.opengl.*;
47import com.jogamp.newt.awt.NewtCanvasAWT;
49import java.io.IOException;
50import java.lang.reflect.InvocationTargetException;
52import com.jogamp.opengl.test.junit.util.*;
53import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
55@FixMethodOrder(MethodSorters.NAME_ASCENDING)
57 static int width, height;
58 static long durationPerTest = 800;
59 static long waitReparent = 0;
63 public static void initClass() throws InterruptedException {
73 Assert.assertNotNull(glWindow1);
74 Assert.assertEquals(
false, glWindow1.
isVisible());
77 glWindow1.
setTitle(
"testWindowParenting01CreateVisibleDestroy");
79 setDemoFields(demo1, glWindow1,
false);
83 Assert.assertNotNull(newtCanvasAWT);
84 Assert.assertEquals(
false, glWindow1.
isVisible());
88 final Frame frame1 =
new Frame(
"AWT Parent Frame");
89 frame1.setLayout(
new BorderLayout());
90 frame1.add(
new Button(
"North"), BorderLayout.NORTH);
91 frame1.add(
new Button(
"South"), BorderLayout.SOUTH);
92 frame1.add(
new Button(
"East"), BorderLayout.EAST);
93 frame1.add(
new Button(
"West"), BorderLayout.WEST);
95 final Container container1 =
new Container();
96 container1.setLayout(
new BorderLayout());
97 container1.add(
new Button(
"north"), BorderLayout.NORTH);
98 container1.add(
new Button(
"south"), BorderLayout.SOUTH);
99 container1.add(
new Button(
"east"), BorderLayout.EAST);
100 container1.add(
new Button(
"west"), BorderLayout.WEST);
101 container1.add(newtCanvasAWT, BorderLayout.CENTER);
103 frame1.add(container1, BorderLayout.CENTER);
106 SwingUtilities.invokeAndWait(
new Runnable() {
108 frame1.setSize(width, height);
109 frame1.setVisible(
true);
124 Assert.assertEquals(
false, animator1.isAnimating());
126 SwingUtilities.invokeAndWait(
new Runnable() {
128 frame1.setVisible(
false);
132 SwingUtilities.invokeAndWait(
new Runnable() {
134 frame1.setVisible(
true);
140 SwingUtilities.invokeAndWait(
new Runnable() {
142 frame1.remove(newtCanvasAWT);
149 SwingUtilities.invokeAndWait(
new Runnable() {
164 Assert.assertNotNull(glWindow1);
165 Assert.assertEquals(
false, glWindow1.
isVisible());
167 Assert.assertNull(glWindow1.
getParent());
169 setDemoFields(demo1, glWindow1,
false);
173 Assert.assertNotNull(newtCanvasAWT);
174 Assert.assertEquals(
false, glWindow1.
isVisible());
176 Assert.assertNull(glWindow1.
getParent());
178 final Frame frame =
new Frame(
"AWT Parent Frame");
179 Assert.assertNotNull(frame);
182 SwingUtilities.invokeAndWait(
new Runnable() {
184 frame.setSize(width, height);
185 frame.setVisible(
true);
189 SwingUtilities.invokeAndWait(
new Runnable() {
191 frame.add(newtCanvasAWT);
204 Assert.assertEquals(
false, animator1.isAnimating());
206 SwingUtilities.invokeAndWait(
new Runnable() {
217 setDemoFields(demo1, glWindow1,
false);
222 final Frame frame =
new Frame(
"AWT Parent Frame");
223 Assert.assertNotNull(frame);
226 SwingUtilities.invokeAndWait(
new Runnable() {
228 frame.setSize(width, height);
229 frame.setVisible(
true);
233 SwingUtilities.invokeAndWait(
new Runnable() {
235 frame.add(newtCanvasAWT);
243 Assert.assertEquals(
true, animator1.
isStarted());
244 Assert.assertEquals(
true, animator1.isAnimating());
249 Assert.assertEquals(
true, animator1.isAnimating());
251 SwingUtilities.invokeAndWait(
new Runnable() {
262 setDemoFields(demo1, glWindow1,
false);
267 final Frame frame =
new Frame(
"AWT Parent Frame");
268 SwingUtilities.invokeAndWait(
new Runnable() {
270 frame.setSize(width, height);
271 frame.setLocation(640, 480);
272 frame.setVisible(
true);
276 SwingUtilities.invokeAndWait(
new Runnable() {
278 frame.add(newtCanvasAWT);
291 Thread.sleep(durationPerTest);
294 System.err.println(
"Reparent CHILD -> TOP: "+glWindow1.
reparentWindow(
null, -1, -1, 0 ));
296 Assert.assertNull(glWindow1.
getParent());
308 Assert.assertEquals(
false, animator1.isAnimating());
310 SwingUtilities.invokeAndWait(
new Runnable() {
321 setDemoFields(demo1, glWindow1,
false);
326 final Frame frame =
new Frame(
"AWT Parent Frame");
327 frame.setLayout(
new BorderLayout());
328 frame.add(
new Button(
"North"), BorderLayout.NORTH);
329 frame.add(
new Button(
"South"), BorderLayout.SOUTH);
330 frame.add(
new Button(
"East"), BorderLayout.EAST);
331 frame.add(
new Button(
"West"), BorderLayout.WEST);
333 SwingUtilities.invokeAndWait(
new Runnable() {
335 frame.setSize(width, height);
336 frame.setLocation(640, 480);
337 frame.setVisible(
true);
341 SwingUtilities.invokeAndWait(
new Runnable() {
343 frame.add(newtCanvasAWT, BorderLayout.CENTER);
356 Thread.sleep(durationPerTest);
359 System.err.println(
"Reparent CHILD -> TOP: "+glWindow1.
reparentWindow(
null, -1, -1, 0 ));
361 Assert.assertNull(glWindow1.
getParent());
373 Assert.assertEquals(
false, animator1.isAnimating());
375 SwingUtilities.invokeAndWait(
new Runnable() {
387 setDemoFields(demo1, glWindow1,
false);
392 final Frame frame1 =
new Frame(
"AWT Parent Frame");
393 frame1.setLayout(
new BorderLayout());
394 frame1.add(
new Button(
"North"), BorderLayout.NORTH);
395 frame1.add(
new Button(
"South"), BorderLayout.SOUTH);
396 frame1.add(
new Button(
"East"), BorderLayout.EAST);
397 frame1.add(
new Button(
"West"), BorderLayout.WEST);
398 SwingUtilities.invokeAndWait(
new Runnable() {
400 frame1.setSize(width, height);
401 frame1.setLocation(0, 0);
402 frame1.setVisible(
true);
406 final Frame frame2 =
new Frame(
"AWT Parent Frame");
407 frame2.setLayout(
new BorderLayout());
408 frame2.add(
new Button(
"North"), BorderLayout.NORTH);
409 frame2.add(
new Button(
"South"), BorderLayout.SOUTH);
410 frame2.add(
new Button(
"East"), BorderLayout.EAST);
411 frame2.add(
new Button(
"West"), BorderLayout.WEST);
412 SwingUtilities.invokeAndWait(
new Runnable() {
414 frame2.setSize(width, height);
415 frame2.setLocation(640, 480);
416 frame2.setVisible(
true);
420 SwingUtilities.invokeAndWait(
new Runnable() {
422 frame1.add(newtCanvasAWT, BorderLayout.CENTER);
435 Thread.sleep(durationPerTest);
438 SwingUtilities.invokeAndWait(
new Runnable() {
440 frame1.remove(newtCanvasAWT);
441 frame2.add(newtCanvasAWT, BorderLayout.CENTER);
448 SwingUtilities.invokeAndWait(
new Runnable() {
450 frame2.remove(newtCanvasAWT);
451 frame1.add(newtCanvasAWT, BorderLayout.CENTER);
462 Assert.assertEquals(
false, animator1.isAnimating());
464 SwingUtilities.invokeAndWait(
new Runnable() {
473 Assert.assertNotNull(demo);
474 Assert.assertNotNull(glWindow);
484 static int atoi(
final String a) {
487 i = Integer.parseInt(a);
488 }
catch (
final Exception ex) { ex.printStackTrace(); }
492 public static void main(
final String args[])
throws IOException {
493 for(
int i=0; i<args.length; i++) {
494 if(args[i].equals(
"-time")) {
495 durationPerTest = atoi(args[++i]);
496 }
else if(args[i].equals(
"-wait")) {
497 waitReparent = atoi(args[++i]);
501 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 boolean isNativeValid()
final ReparentOperation reparentWindow(final NativeWindow newParent, final int x, final int y, final int hints)
Change this window's parent window.
final void setTitle(final String title)
final boolean isVisible()
final CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
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 test05WindowParenting04ReparentNewtWin2TopLayouted()
void test06WindowParenting05ReparentAWTWinHopFrame2Frame()
void test02WindowParenting02CreateVisibleDestroy2Defered()
void test01WindowParenting01CreateVisibleDestroy1()
void test04WindowParenting03ReparentNewtWin2Top()
void test03WindowParenting02CreateVisibleDestroy3Odd()
static void main(final String args[])
static void setDemoFields(final GLEventListener demo, final GLWindow glWindow, final boolean debug)
static boolean setFieldIfExists(final Object instance, final String fieldName, final Object value)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final Window win, final boolean visible, final Runnable waitAction)
final long getTotalFPSDuration()
final void setUpdateFPSFrames(final int frames, final PrintStream out)
synchronized boolean isStarted()
Indicates whether this animator has been started.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
boolean isOnscreen()
Returns whether an on- or offscreen surface is requested, available or chosen.
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.