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;
41import java.util.ArrayList;
42import java.util.EventObject;
45import com.jogamp.opengl.GLCapabilities;
46import com.jogamp.opengl.GLEventListener;
47import javax.swing.JFrame;
49import java.io.IOException;
51import jogamp.nativewindow.jawt.JAWTUtil;
53import org.junit.BeforeClass;
55import org.junit.FixMethodOrder;
56import org.junit.runners.MethodSorters;
58import com.jogamp.newt.awt.NewtCanvasAWT;
59import com.jogamp.newt.event.KeyEvent;
60import com.jogamp.newt.opengl.GLWindow;
61import com.jogamp.opengl.util.Animator;
62import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
63import com.jogamp.opengl.test.junit.util.*;
64import com.jogamp.opengl.test.junit.util.NEWTKeyUtil.CodeSeg;
69@FixMethodOrder(MethodSorters.NAME_ASCENDING)
71 static int width, height;
72 static long durationPerTest = 100;
73 static long awtWaitTimeout = 1000;
97 public
void test01NEWT() throws AWTException, InterruptedException, InvocationTargetException {
99 glWindow.
setSize(width, height);
107 private void testNewtCanvasAWT_Impl(
final boolean onscreen)
throws AWTException, InterruptedException, InvocationTargetException {
117 final JFrame frame1 =
new JFrame(
"Swing AWT Parent Frame: "+ glWindow.
getTitle());
118 frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER);
119 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
121 frame1.setSize(width, height);
122 frame1.setVisible(
true);
130 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
132 frame1.setVisible(
false);
135 }
catch(
final Throwable throwable ) {
136 throwable.printStackTrace();
137 Assume.assumeNoException( throwable );
142 @Test(timeout=180000)
143 public
void test02NewtCanvasAWT_Onscreen() throws AWTException, InterruptedException, InvocationTargetException {
144 if( JAWTUtil.isOffscreenLayerRequired() ) {
145 System.err.println(
"Platform doesn't support onscreen rendering.");
148 testNewtCanvasAWT_Impl(
true);
151 @Test(timeout=180000)
152 public
void test03NewtCanvasAWT_Offsccreen() throws AWTException, InterruptedException, InvocationTargetException {
153 if( !JAWTUtil.isOffscreenLayerSupported() ) {
154 System.err.println(
"Platform doesn't support offscreen rendering.");
157 testNewtCanvasAWT_Impl(
false);
191 static void testKeyCodes(
final Robot robot,
final Object obj,
final NEWTKeyAdapter keyAdapter)
throws InterruptedException, InvocationTargetException {
192 final List<List<EventObject>> cse =
new ArrayList<List<EventObject>>();
194 keyAdapter.setVerbose(
true);
197 for(
int i=0; i<codeSegments.length; i++) {
199 final CodeSeg codeSeg = codeSegments[i];
202 for(
short c=codeSeg.min; c<=codeSeg.max; c++) {
207 }
catch (
final Exception e) {
208 System.err.println(
"Exception @ AWT Robot.PRESS "+
MiscUtils.
toHexString(c)+
" - "+e.getMessage());
214 }
catch (
final Exception e) {
215 System.err.println(
"Exception @ AWT Robot.RELEASE "+
MiscUtils.
toHexString(c)+
" - "+e.getMessage());
221 for(
int j=0; j < NEWTKeyUtil.POLL_DIVIDER && keyAdapter.getQueueSize() < eventCount; j++) {
224 final int off = 0==j%2 ? 1 : -1;
228 cse.add(keyAdapter.copyQueue());
233 void testImpl(
final GLWindow glWindow)
throws AWTException, InterruptedException, InvocationTargetException {
234 final Robot robot =
new Robot();
235 robot.setAutoWaitForIdle(
true);
249 final Animator animator =
new Animator(glWindow);
252 Thread.sleep(durationPerTest);
258 testKeyCodes(robot, glWindow, glWindow1KA);
267 static int atoi(
final String a) {
270 i = Integer.parseInt(a);
271 }
catch (
final Exception ex) { ex.printStackTrace(); }
275 public static void main(
final String args[])
throws IOException {
276 for(
int i=0; i<args.length; i++) {
277 if(args[i].equals(
"-time")) {
278 durationPerTest = atoi(args[++i]);
286 System.out.println(
"durationPerTest: "+durationPerTest);
288 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.
static final short VK_DELETE
Constant for the DEL key, matching ASCII.
static final short VK_COMMA
Constant for the comma key, ",".
static final short VK_SHIFT
Constant for the CTRL function key.
static final short VK_CLOSE_BRACKET
Constant for the close bracket key, "]".
static final short VK_A
VK_A thru VK_Z are the same as Capital UTF16/ASCII 'A' thru 'Z' (0x41 - 0x5A)
static final short VK_ESCAPE
Constant for the ESCAPE function key.
static final short VK_ENTER
Constant for the ENTER key, i.e.
static final short VK_OPEN_BRACKET
Constant for the open bracket key, "[".
static final short VK_LEFT
Constant for the cursor- or numerical-pad left arrow key.
static final short VK_SEMICOLON
Constant for the semicolon key, ";".
static final short VK_BACK_QUOTE
Constant for the "`" key.
static final short VK_DOWN
Constant for the cursor- or numerical pad down arrow key.
static final short VK_PAGE_DOWN
Constant for the PAGE DOWN function key.
static final short VK_SPACE
Constant for the SPACE function key.
static final short VK_9
See VK_0.
static final short VK_ALT
Constant for the left ALT function key.
static final short VK_Z
See VK_A.
static final short VK_0
VK_0 thru VK_9 are the same as UTF16/ASCII '0' thru '9' [0x30 - 0x39].
static final short VK_QUOTE
Constant for the "'" key.
static final short VK_F8
Constant for the F8 function key.
static final short VK_SLASH
Constant for the forward slash key, "/".
static final short VK_F1
Small UTF/ASCII 'a' thru 'z' (0x61 - 0x7a) - Not used for keyCode / keySym.
static final short VK_BACK_SPACE
Constant for the BACK SPACE key "\b", matching ASCII.
static final short VK_EQUALS
Constant for the equals key, "=".
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 code of key events.
static void main(final String args[])
static void awtRobotMouseMove(final Robot robot, final int x, final int y)
static int newtKeyPress(final int i, final Robot robot, final boolean press, final short newtKeyCode, final int msDelay)
No validation is performed .
static void requestFocus(final Robot robot, final Object obj)
FIXME: AWTRobotUtil Cleanup: Use specific type for argument object.
static int[] getCenterLocation(final Object obj, final boolean onTitleBarIfWindow)
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 void waitForIdle(final Robot robot)
Issuing validateAWTEDTIsAlive() before calling Robot#waitForIdle().
static String toHexString(final byte hex)
synchronized void setVerbose(final boolean v)
Instance starts in verbose mode, call w/ false to disable verbosity.
synchronized void reset()
static boolean validateKeyCodes(final CodeSeg[] codeSegments, final List< List< EventObject > > keyEventsList, final boolean verbose)
static final int TIME_SLICE
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
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.