29package com.jogamp.opengl.test.junit.newt.event;
31import org.junit.Assert;
32import org.junit.AfterClass;
33import org.junit.Assume;
35import java.awt.AWTException;
36import java.awt.BorderLayout;
37import java.awt.Button;
38import java.awt.Container;
40import java.lang.reflect.InvocationTargetException;
42import com.jogamp.opengl.GLCapabilities;
43import com.jogamp.opengl.GLEventListener;
44import javax.swing.JFrame;
46import java.util.ArrayList;
47import java.io.IOException;
49import org.junit.BeforeClass;
51import org.junit.FixMethodOrder;
52import org.junit.runners.MethodSorters;
54import com.jogamp.newt.awt.NewtCanvasAWT;
55import com.jogamp.newt.opengl.GLWindow;
56import com.jogamp.opengl.util.Animator;
57import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
58import com.jogamp.opengl.test.junit.newt.TestListenerCom01AWT;
59import com.jogamp.opengl.test.junit.util.*;
70@FixMethodOrder(MethodSorters.NAME_ASCENDING)
72 static int width, height;
73 static long durationPerTest = 10;
74 static long awtWaitTimeout = 1000;
91 testFocus01ProgrFocusImpl(
null);
96 final Robot robot =
new Robot();
97 robot.setAutoWaitForIdle(
true);
98 testFocus01ProgrFocusImpl(robot);
101 private void testFocus01ProgrFocusImpl(
final Robot robot)
throws AWTException,
102 InvocationTargetException, InterruptedException {
103 final ArrayList<EventCountAdapter> eventCountAdapters =
new ArrayList<EventCountAdapter>();
107 glWindow1.
setTitle(
"testNewtChildFocus");
116 eventCountAdapters.add(glWindow1KA);
125 newtCanvasAWT.addKeyListener(newtCanvasAWTKA);
126 eventCountAdapters.add(newtCanvasAWTKA);
128 newtCanvasAWT.addFocusListener(newtCanvasAWTFA);
131 final JFrame frame1 =
new JFrame(
"Swing AWT Parent Frame: "
133 frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER);
134 final Button button =
new Button(
"Click me ..");
136 button.addFocusListener(buttonFA);
138 button.addKeyListener(buttonKA);
139 eventCountAdapters.add(buttonKA);
141 button.addMouseListener(buttonMA);
142 eventCountAdapters.add(buttonMA);
144 frame1.getContentPane().add(button, BorderLayout.NORTH);
145 frame1.setSize(width, height);
146 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
148 frame1.setVisible(
true);
155 Thread.sleep(durationPerTest);
158 while(wait<awtWaitTimeout/100 && glWindow1.
getTotalFPSFrames()<1) { Thread.sleep(awtWaitTimeout/10); wait++; }
159 System.err.println(
"Frames for initial setVisible(true): "+glWindow1.
getTotalFPSFrames());
160 Assert.assertTrue(glWindow1.
isVisible());
164 final Animator animator =
new Animator(glWindow1);
170 System.err.println(
"FOCUS AWT Button request");
173 Assert.assertEquals(
false, glWindow1FA.
focusGained());
174 Assert.assertEquals(
false, newtCanvasAWTFA.
focusGained());
175 System.err.println(
"FOCUS AWT Button sync");
184 System.err.println(
"FOCUS NEWT Canvas/GLWindow request");
192 System.err.println(
"Info: Focus prev. gained, but NewtCanvasAWT didn't loose it. Gainer: "+glWindow1FA+
"; Looser "+newtCanvasAWTFA);
194 System.err.println(
"FOCUS NEWT Canvas/GLWindow sync");
196 Assert.assertEquals(
"AWT parent canvas received non consumed keyboard events", newtCanvasAWTKA.
getConsumedCount(), newtCanvasAWTKA.
getCount());
198 Assert.assertEquals(
"AWT parent canvas received consumed keyboard events", 0, newtCanvasAWTKA.
getConsumedCount());
204 newtCanvasAWT.removeKeyListener(newtCanvasAWTKA);
205 newtCanvasAWT.removeFocusListener(newtCanvasAWTFA);
210 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
212 frame1.setVisible(
false);
215 }
catch(
final Throwable throwable ) {
216 throwable.printStackTrace();
217 Assume.assumeNoException( throwable );
223 static int atoi(
final String a) {
226 i = Integer.parseInt(a);
227 }
catch (
final Exception ex) { ex.printStackTrace(); }
231 public static void main(
final String args[])
throws IOException {
232 for(
int i=0; i<args.length; i++) {
233 if(args[i].equals(
"-time")) {
234 durationPerTest = atoi(args[++i]);
242 System.out.println(
"durationPerTest: "+durationPerTest);
244 org.junit.runner.JUnitCore.
main(tstname);
AWT Canvas containing a NEWT Window using native parenting.
final boolean isAWTEventPassThrough()
Returns true if Key and Mouse input events will be passed through AWT, otherwise only the NEWT child ...
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
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 void removeWindowListener(final WindowListener l)
final boolean isVisible()
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
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.
static void setDemoFields(final GLEventListener demo, final GLWindow glWindow, final boolean debug)
Testing focus mouse-click and programmatic traversal of an AWT component tree with NewtCanvasAWT atta...
void testFocus01ProgrFocus()
static void main(final String args[])
void testFocus02RobotFocus()
synchronized int getCount()
synchronized int getConsumedCount()
static void assertKeyType(Robot robot, final int keyCode, final int typeCount, final Object obj, final KeyEventCountAdapter counter)
FIXME: AWTRobotUtil Cleanup: Use specific type for argument object.
static void assertMouseClick(Robot robot, final int mouseButton, final int clickCount, final Object obj, final InputEventCountAdapter counter)
FIXME: AWTRobotUtil Cleanup: Use specific type for argument object.
static boolean toFrontAndRequestFocus(Robot robot, final java.awt.Window window)
toFront, call setVisible(true) and toFront(), after positioning the mouse in the middle of the window...
static void clearAWTFocus(Robot robot)
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 reset(final EventCountAdapter[] adapters)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
static boolean waitForFocus(final FocusEventCountAdapter gain, final FocusEventCountAdapter lost, 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.