29package com.jogamp.opengl.test.junit.newt.event;
31import org.junit.After;
32import org.junit.Assert;
33import org.junit.AfterClass;
34import org.junit.Assume;
35import org.junit.Before;
37import java.awt.AWTException;
38import java.awt.BorderLayout;
40import java.lang.reflect.InvocationTargetException;
42import com.jogamp.opengl.GLCapabilities;
43import com.jogamp.opengl.GLEventListener;
44import javax.swing.JFrame;
46import java.io.IOException;
48import jogamp.nativewindow.jawt.JAWTUtil;
50import org.junit.BeforeClass;
52import org.junit.FixMethodOrder;
53import org.junit.runners.MethodSorters;
55import com.jogamp.newt.awt.NewtCanvasAWT;
56import com.jogamp.newt.event.InputEvent;
57import com.jogamp.newt.event.KeyEvent;
58import com.jogamp.newt.event.KeyListener;
59import com.jogamp.newt.opengl.GLWindow;
60import com.jogamp.opengl.util.Animator;
61import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
63import com.jogamp.opengl.test.junit.util.*;
68@FixMethodOrder(MethodSorters.NAME_ASCENDING)
70 static int width, height;
71 static long durationPerTest = 100;
72 static long awtWaitTimeout = 1000;
96 public
void test01NEWT() throws AWTException, InterruptedException, InvocationTargetException {
98 glWindow.
setSize(width, height);
106 private void testNewtCanvasAWT_Impl(
final boolean onscreen)
throws AWTException, InterruptedException, InvocationTargetException {
116 final JFrame frame1 =
new JFrame(
"Swing AWT Parent Frame: "+ glWindow.
getTitle());
117 frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER);
118 frame1.setSize(width, height);
119 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
121 frame1.setVisible(
true);
129 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
131 frame1.setVisible(
false);
134 }
catch(
final Throwable throwable ) {
135 throwable.printStackTrace();
136 Assume.assumeNoException( throwable );
141 @Test(timeout=180000)
142 public
void test02NewtCanvasAWT_Onscreen() throws AWTException, InterruptedException, InvocationTargetException {
143 if( JAWTUtil.isOffscreenLayerRequired() ) {
144 System.err.println(
"Platform doesn't support onscreen rendering.");
147 testNewtCanvasAWT_Impl(
true);
150 @Test(timeout=180000)
151 public
void test03NewtCanvasAWT_Offsccreen() throws AWTException, InterruptedException, InvocationTargetException {
152 if( !JAWTUtil.isOffscreenLayerSupported() ) {
153 System.err.println(
"Platform doesn't support offscreen rendering.");
156 testNewtCanvasAWT_Impl(
false);
159 void testImpl(
final GLWindow glWindow)
throws AWTException, InterruptedException, InvocationTargetException {
160 final Robot robot =
new Robot();
161 robot.setAutoWaitForIdle(
true);
166 final SimpleKeyPressRelease simpleKeyPressRelease =
new SimpleKeyPressRelease();
175 Thread.sleep(durationPerTest);
187 static int atoi(
final String a) {
190 i = Integer.parseInt(a);
191 }
catch (
final Exception ex) { ex.printStackTrace(); }
195 static class SimpleKeyPressRelease
implements KeyListener {
198 SimpleKeyPressRelease() {
202 public void reset() {
207 public void keyPressed(
final KeyEvent e) {
210 System.err.println(seq+
": "+e);
215 public void keyReleased(
final KeyEvent e) {
218 System.err.println(seq+
": "+e);
223 public static void main(
final String args[])
throws IOException {
224 for(
int i=0; i<args.length; i++) {
225 if(args[i].equals(
"-time")) {
226 durationPerTest = atoi(args[++i]);
234 System.out.println(
"durationPerTest: "+durationPerTest);
236 org.junit.runner.JUnitCore.
main(tstname);
AWT Canvas containing a NEWT Window using native parenting.
void setShallUseOffscreenLayer(final boolean v)
Request an offscreen layer, if supported.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void removeKeyListener(final KeyListener l)
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
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.
Testing key press and release events w/o AUTO-REPEAT.
static void main(final String args[])
static void requestFocus(final Robot robot, final Object obj)
FIXME: AWTRobotUtil Cleanup: Use specific type for argument object.
static boolean waitForVisible(final java.awt.Component comp, final boolean visible, final Runnable waitAction)
static void assertRequestFocusAndWait(final Robot robot, final Object requestFocus, final Object waitForFocus, final FocusEventCountAdapter gain, final FocusEventCountAdapter lost)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
final synchronized boolean start()
Starts this animator, if not running.
final synchronized 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.