29package com.jogamp.opengl.test.junit.newt.event;
31import java.lang.reflect.*;
33import org.junit.Assert;
34import org.junit.BeforeClass;
35import org.junit.AfterClass;
37import org.junit.FixMethodOrder;
38import org.junit.runners.MethodSorters;
40import java.awt.AWTException;
41import java.awt.Button;
42import java.awt.BorderLayout;
43import java.awt.Container;
46import javax.swing.JFrame;
47import javax.swing.JPanel;
48import javax.swing.SwingUtilities;
49import javax.swing.WindowConstants;
51import java.util.ArrayList;
53import com.jogamp.opengl.*;
55import com.jogamp.opengl.util.Animator;
56import com.jogamp.newt.opengl.*;
57import com.jogamp.newt.awt.NewtCanvasAWT;
59import java.io.IOException;
61import com.jogamp.opengl.test.junit.util.*;
62import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
73@FixMethodOrder(MethodSorters.NAME_ASCENDING)
75 static int width, height;
76 static long durationPerTest = 10;
77 static long awtWaitTimeout = 1000;
81 public static void initClass() throws AWTException, InterruptedException, InvocationTargetException {
85 final JFrame f =
new JFrame();
86 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
92 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
105 private void testFocus01ProgrFocusImpl(
final Robot robot)
106 throws AWTException, InterruptedException, InvocationTargetException {
108 final ArrayList<EventCountAdapter> eventCountAdapters =
new ArrayList<EventCountAdapter>();
111 glWindow1.
setTitle(
"testWindowParenting01CreateVisibleDestroy");
118 eventCountAdapters.add(glWindow1KA);
121 eventCountAdapters.add(glWindow1MA);
125 newtCanvasAWT.addFocusListener(newtCanvasAWTFA);
127 newtCanvasAWT.addKeyListener(newtCanvasAWTKA);
128 eventCountAdapters.add(newtCanvasAWTKA);
130 newtCanvasAWT.addMouseListener(newtCanvasAWTMA);
131 eventCountAdapters.add(newtCanvasAWTMA);
133 final Button buttonNorthInner =
new Button(
"north");
135 buttonNorthInner.addFocusListener(buttonNorthInnerFA);
137 buttonNorthInner.addKeyListener(buttonNorthInnerKA);
138 eventCountAdapters.add(buttonNorthInnerKA);
140 buttonNorthInner.addMouseListener(buttonNorthInnerMA);
141 eventCountAdapters.add(buttonNorthInnerMA);
142 final Container container1 =
new Container();
143 container1.setLayout(
new BorderLayout());
144 container1.add(buttonNorthInner, BorderLayout.NORTH);
145 container1.add(
new Button(
"south"), BorderLayout.SOUTH);
146 container1.add(
new Button(
"east"), BorderLayout.EAST);
147 container1.add(
new Button(
"west"), BorderLayout.WEST);
148 container1.add(newtCanvasAWT, BorderLayout.CENTER);
150 final Button buttonNorthOuter =
new Button(
"north");
152 buttonNorthOuter.addFocusListener(buttonNorthOuterFA);
154 buttonNorthOuter.addKeyListener(buttonNorthOuterKA);
155 eventCountAdapters.add(buttonNorthOuterKA);
157 buttonNorthOuter.addMouseListener(buttonNorthOuterMA);
158 eventCountAdapters.add(buttonNorthOuterMA);
159 final JPanel jPanel1 =
new JPanel();
160 jPanel1.setLayout(
new BorderLayout());
161 jPanel1.add(buttonNorthOuter, BorderLayout.NORTH);
162 jPanel1.add(
new Button(
"south"), BorderLayout.SOUTH);
163 jPanel1.add(
new Button(
"east"), BorderLayout.EAST);
164 jPanel1.add(
new Button(
"west"), BorderLayout.WEST);
165 jPanel1.add(container1, BorderLayout.CENTER);
167 final JFrame jFrame1 =
new JFrame(
"Swing Parent JFrame");
169 jFrame1.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
170 jFrame1.setContentPane(jPanel1);
171 jFrame1.setSize(width, height);
172 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
175 jFrame1.setVisible(
true);
183 while(wait<awtWaitTimeout/10 && glWindow1.
getTotalFPSFrames()<1) { Thread.sleep(awtWaitTimeout/100); wait++; }
184 System.err.println(
"Frames for initial setVisible(true): "+glWindow1.
getTotalFPSFrames());
185 Assert.assertTrue(glWindow1.
isVisible());
189 final Animator animator1 =
new Animator(glWindow1);
192 Thread.sleep(durationPerTest);
196 System.err.println(
"FOCUS AWT Button Outer request.1");
199 Assert.assertEquals(
false, glWindow1FA.
focusGained());
200 Assert.assertEquals(
false, newtCanvasAWTFA.
focusGained());
201 Assert.assertEquals(
false, buttonNorthInnerFA.
focusGained());
202 System.err.println(
"FOCUS AWT Button Outer sync.1");
205 buttonNorthOuter, buttonNorthOuterMA);
207 buttonNorthOuter, buttonNorthOuterMA);
211 System.err.println(
"FOCUS NEWT Canvas/GLWindow request.2");
219 System.err.println(
"Info: Focus prev. gained, but NewtCanvasAWT didn't loose it. Gainer: "+glWindow1FA+
"; Looser "+newtCanvasAWTFA);
221 Assert.assertEquals(
false, buttonNorthInnerFA.
focusGained());
222 System.err.println(
"FOCUS NEWT Canvas/GLWindow sync.2");
224 Assert.assertEquals(
"AWT parent canvas received non consumed keyboard events", newtCanvasAWTKA.
getConsumedCount(), newtCanvasAWTKA.
getCount());
225 System.err.println(
"FOCUS NEWT Canvas/GLWindow sync.2.2");
227 glWindow1, glWindow1MA);
228 System.err.println(
"FOCUS NEWT Canvas/GLWindow sync.2.3");
230 glWindow1, glWindow1MA);
231 System.err.println(
"FOCUS NEWT Canvas/GLWindow sync.2.4");
233 Assert.assertEquals(
"AWT parent canvas received consumed keyboard events", 0, newtCanvasAWTKA.
getConsumedCount());
234 Assert.assertEquals(
"AWT parent canvas received mouse events", 0, newtCanvasAWTMA.getCount());
239 System.err.println(
"FOCUS AWT Button request.3");
242 Assert.assertEquals(
false, glWindow1FA.
focusGained());
243 Assert.assertEquals(
false, newtCanvasAWTFA.
focusGained());
244 Assert.assertEquals(
false, buttonNorthOuterFA.
focusGained());
245 System.err.println(
"FOCUS AWT Button sync.3");
248 buttonNorthInner, buttonNorthInnerMA);
250 buttonNorthInner, buttonNorthInnerMA);
254 System.err.println(
"FOCUS NEWT Canvas/GLWindow request.4");
262 System.err.println(
"Info: Focus prev. gained, but NewtCanvasAWT didn't loose it. Gainer: "+glWindow1FA+
"; Looser "+newtCanvasAWTFA);
265 Assert.assertEquals(
false, buttonNorthOuterFA.
focusGained());
266 System.err.println(
"FOCUS NEWT Canvas/GLWindow sync.4");
268 Assert.assertEquals(
"AWT parent canvas received non consumed keyboard events", newtCanvasAWTKA.
getConsumedCount(), newtCanvasAWTKA.
getCount());
270 glWindow1, glWindow1MA);
272 glWindow1, glWindow1MA);
274 Assert.assertEquals(
"AWT parent canvas received consumed keyboard events", 0, newtCanvasAWTKA.
getConsumedCount());
275 Assert.assertEquals(
"AWT parent canvas received mouse events", 0, newtCanvasAWTMA.getCount());
279 Assert.assertEquals(
false, animator1.isAnimating());
281 SwingUtilities.invokeAndWait(
new Runnable() {
284 jFrame1.setVisible(
false);
285 jPanel1.remove(container1);
295 testFocus01ProgrFocusImpl(
null);
300 final Robot robot =
new Robot();
301 robot.setAutoWaitForIdle(
true);
302 testFocus01ProgrFocusImpl(robot);
305 static int atoi(
final String a) {
308 i = Integer.parseInt(a);
309 }
catch (
final Exception ex) { ex.printStackTrace(); }
313 @SuppressWarnings(
"unused")
314 public static
void main(final String args[])
315 throws IOException, AWTException, InterruptedException, InvocationTargetException
317 for(
int i=0; i<args.length; i++) {
318 if(args[i].equals(
"-time")) {
319 durationPerTest = atoi(args[++i]);
324 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 addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
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 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 focus mouse-click and programmatic traversal of an AWT component tree with NewtCanvasAWT atta...
void testFocus02RobotFocus()
static void main(final String args[])
void testFocus01ProgrFocus()
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.