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.*;
43import com.jogamp.newt.*;
44import com.jogamp.newt.event.*;
45import com.jogamp.newt.opengl.*;
46import com.jogamp.newt.awt.NewtCanvasAWT;
48import java.io.IOException;
49import java.lang.reflect.InvocationTargetException;
51import com.jogamp.opengl.test.junit.util.*;
52import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
54@FixMethodOrder(MethodSorters.NAME_ASCENDING)
56 static int width, height;
57 static long durationPerTest = 500;
58 static long waitReparent = 300;
59 static boolean verbose =
false;
69 runNewtChildOnAWTParent(
true,
false);
74 runNewtChildOnAWTParent(
true,
true);
79 runNewtChildOnAWTParent(
false,
false);
84 runNewtChildOnAWTParent(
false,
true);
87 public void runNewtChildOnAWTParent(
final boolean useLayout,
final boolean deferredPeer)
throws InterruptedException, InvocationTargetException {
92 Assert.assertNotNull(glWindow);
97 setDemoFields(demo, glWindow,
false);
102 Assert.assertNotNull(newtCanvasAWT);
103 Assert.assertEquals(
false, glWindow.
isVisible());
107 final Frame frame =
new Frame(
"AWT Parent Frame");
108 Assert.assertNotNull(frame);
110 frame.setLayout(
new BorderLayout());
111 frame.add(
new Button(
"North"), BorderLayout.NORTH);
112 frame.add(
new Button(
"South"), BorderLayout.SOUTH);
113 frame.add(
new Button(
"East"), BorderLayout.EAST);
114 frame.add(
new Button(
"West"), BorderLayout.WEST);
116 frame.add(newtCanvasAWT, BorderLayout.CENTER);
120 frame.add(newtCanvasAWT);
124 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
127 frame.setBounds(100, 100, width, height);
128 frame.setVisible(
true);
133 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
136 frame.add(newtCanvasAWT, BorderLayout.CENTER);
138 frame.add(newtCanvasAWT);
157 Assert.assertNotNull(glWindow.
getParent());
159 System.out.println(
"+++++++++++++++++++ 1st ADDED");
161 Thread.sleep(waitReparent);
165 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
167 frame.remove(newtCanvasAWT);
170 Assert.assertEquals(
false, glWindow.
isVisible());
176 System.out.println(
"+++++++++++++++++++ REMOVED!");
178 Thread.sleep(waitReparent);
181 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
183 frame.add(newtCanvasAWT, BorderLayout.CENTER);
187 Assert.assertEquals(
true, glWindow.
isVisible());
189 Assert.assertNotNull(glWindow.
getParent());
191 System.out.println(
"+++++++++++++++++++ 2nd ADDED");
193 Thread.sleep(waitReparent);
196 long duration = durationPerTest;
197 final long step = 20;
199 boolean shouldQuit =
false;
201 while (duration>0 && !shouldQuit) {
206 while(
null != ( event = eventFifo.
get() ) ) {
222 System.out.println(
"+++++++++++++++++++ END");
224 Thread.sleep(waitReparent);
228 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
230 frame.remove(newtCanvasAWT);
234 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
241 Assert.assertNotNull(demo);
242 Assert.assertNotNull(glWindow);
253 static int atoi(
final String a) {
256 i = Integer.parseInt(a);
257 }
catch (
final Exception ex) { ex.printStackTrace(); }
261 public static void main(
final String args[])
throws IOException {
263 for(
int i=0; i<args.length; i++) {
264 if(args[i].equals(
"-time")) {
265 durationPerTest = atoi(args[++i]);
266 }
else if(args[i].equals(
"-wait")) {
267 waitReparent = atoi(args[++i]);
271 org.junit.runner.JUnitCore.
main(tstname);
AWT Canvas containing a NEWT Window using native parenting.
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
synchronized NEWTEvent get()
Remove NEWTEvent from head.
NEWT events are provided for notification purposes ONLY; The NEWT will automatically handle the even...
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final NativeWindow getParent()
final boolean isNativeValid()
final void setTitle(final String title)
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
final boolean isVisible()
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
final CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
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 test04NewtChildOnAWTParentDirectDef()
void test01NewtChildOnAWTParentLayouted()
void runNewtChildOnAWTParent(final boolean useLayout, final boolean deferredPeer)
static void setDemoFields(final GLEventListener demo, final GLWindow glWindow, final boolean debug)
static void main(final String args[])
void test03NewtChildOnAWTParentDirect()
void test02NewtChildOnAWTParentLayoutedDef()
static boolean setFieldIfExists(final Object instance, final String fieldName, final Object value)
boolean isOnscreen()
Returns whether an on- or offscreen surface is requested, available or chosen.
Specifying NEWT's Window functionality:
boolean setFullscreen(boolean fullscreen)
Enable or disable fullscreen mode for this window.
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.