summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java20
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java33
-rw-r--r--src/junit/com/jogamp/test/junit/util/AWTFocusAdapter.java10
-rw-r--r--src/junit/com/jogamp/test/junit/util/AWTKeyAdapter.java5
-rw-r--r--src/junit/com/jogamp/test/junit/util/AWTMouseAdapter.java5
-rw-r--r--src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java45
-rw-r--r--src/junit/com/jogamp/test/junit/util/EventCountAdapter.java2
-rw-r--r--src/junit/com/jogamp/test/junit/util/EventCountAdapterUtil.java49
-rw-r--r--src/junit/com/jogamp/test/junit/util/NEWTFocusAdapter.java7
-rw-r--r--src/junit/com/jogamp/test/junit/util/NEWTKeyAdapter.java5
-rw-r--r--src/junit/com/jogamp/test/junit/util/NEWTMouseAdapter.java5
11 files changed, 154 insertions, 32 deletions
diff --git a/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java b/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java
index 514749459..97b37aec0 100644
--- a/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java
+++ b/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java
@@ -42,13 +42,17 @@ import java.awt.Robot;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.lang.reflect.InvocationTargetException;
-import java.io.IOException;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.swing.JFrame;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Iterator;
+import java.io.IOException;
+
import org.junit.BeforeClass;
import org.junit.Test;
@@ -100,6 +104,8 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
private void testFocus01ProgrFocusImpl(Robot robot) throws AWTException,
InvocationTargetException, InterruptedException {
+ ArrayList eventCountAdapters = new ArrayList();
+
// Create a window.
GLWindow glWindow1 = GLWindow.create(glCaps);
glWindow1.setTitle("testNewtChildFocus");
@@ -107,10 +113,12 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
TestListenerCom01AWT.setDemoFields(demo1, glWindow1, false);
glWindow1.addGLEventListener(demo1);
NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1");
+ eventCountAdapters.add(glWindow1FA);
glWindow1.addWindowListener(glWindow1FA);
// Monitor NEWT focus and keyboard events.
NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1");
+ eventCountAdapters.add(glWindow1KA);
glWindow1.addKeyListener(glWindow1KA);
// Wrap the window in a canvas.
@@ -119,8 +127,10 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
// Monitor AWT focus and keyboard events.
AWTKeyAdapter newtCanvasAWTKA = new AWTKeyAdapter("NewtCanvasAWT");
newtCanvasAWT.addKeyListener(newtCanvasAWTKA);
+ eventCountAdapters.add(newtCanvasAWTKA);
AWTFocusAdapter newtCanvasAWTFA = new AWTFocusAdapter("NewtCanvasAWT");
newtCanvasAWT.addFocusListener(newtCanvasAWTFA);
+ eventCountAdapters.add(newtCanvasAWTFA);
// Add the canvas to a frame, and make it all visible.
JFrame frame1 = new JFrame("Swing AWT Parent Frame: "
@@ -129,8 +139,10 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
Button button = new Button("Click me ..");
AWTFocusAdapter buttonFA = new AWTFocusAdapter("Button");
button.addFocusListener(buttonFA);
+ eventCountAdapters.add(buttonFA);
AWTKeyAdapter buttonKA = new AWTKeyAdapter("Button");
button.addKeyListener(buttonKA);
+ eventCountAdapters.add(buttonKA);
frame1.getContentPane().add(button, BorderLayout.NORTH);
frame1.setSize(width, height);
frame1.setVisible(true);
@@ -148,7 +160,9 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
// Button Focus
Thread.sleep(100); // allow event sync
System.err.println("FOCUS AWT Button request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, button, button));
+ Assert.assertEquals(1, buttonFA.getCount());
Assert.assertEquals(0, glWindow1FA.getCount());
Assert.assertEquals(0, newtCanvasAWTFA.getCount());
System.err.println("FOCUS AWT Button sync");
@@ -157,9 +171,11 @@ public class TestFocus01SwingAWTRobot extends UITestCase {
// Request the AWT focus, which should automatically provide the NEWT window with focus.
Thread.sleep(100); // allow event sync
System.err.println("FOCUS NEWT Canvas/GLWindow request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild()));
+ Assert.assertEquals(1, glWindow1FA.getCount());
Assert.assertEquals(0, newtCanvasAWTFA.getCount());
- Assert.assertEquals(0, buttonFA.getCount());
+ // Assert.assertEquals(-1, buttonFA.getCount()); // lost focus
System.err.println("FOCUS NEWT Canvas/GLWindow sync");
Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA));
Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount());
diff --git a/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java b/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java
index dfca6c10b..a7602b49b 100644
--- a/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java
+++ b/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java
@@ -43,6 +43,9 @@ import java.awt.Robot;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Iterator;
import javax.media.opengl.*;
@@ -85,6 +88,8 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
int x = 0;
int y = 0;
+ ArrayList eventCountAdapters = new ArrayList();
+
/**
* JFrame . JPanel . Container . NewtCanvasAWT . GLWindow
*/
@@ -94,26 +99,35 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
glWindow1.addGLEventListener(demo1);
NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1");
glWindow1.addWindowListener(glWindow1FA);
+ eventCountAdapters.add(glWindow1FA);
NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1");
glWindow1.addKeyListener(glWindow1KA);
+ eventCountAdapters.add(glWindow1KA);
NEWTMouseAdapter glWindow1MA = new NEWTMouseAdapter("GLWindow1");
glWindow1.addMouseListener(glWindow1MA);
+ eventCountAdapters.add(glWindow1MA);
NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
AWTFocusAdapter newtCanvasAWTFA = new AWTFocusAdapter("NewtCanvasAWT");
newtCanvasAWT.addFocusListener(newtCanvasAWTFA);
+ eventCountAdapters.add(newtCanvasAWTFA);
AWTKeyAdapter newtCanvasAWTKA = new AWTKeyAdapter("NewtCanvasAWT");
newtCanvasAWT.addKeyListener(newtCanvasAWTKA);
+ eventCountAdapters.add(newtCanvasAWTKA);
AWTMouseAdapter newtCanvasAWTMA = new AWTMouseAdapter("NewtCanvasAWT");
newtCanvasAWT.addMouseListener(newtCanvasAWTMA);
+ eventCountAdapters.add(newtCanvasAWTMA);
Button buttonNorthInner = new Button("north");
AWTFocusAdapter buttonNorthInnerFA = new AWTFocusAdapter("ButtonNorthInner");
buttonNorthInner.addFocusListener(buttonNorthInnerFA);
+ eventCountAdapters.add(buttonNorthInnerFA);
AWTKeyAdapter buttonNorthInnerKA = new AWTKeyAdapter("ButtonNorthInner");
buttonNorthInner.addKeyListener(buttonNorthInnerKA);
+ eventCountAdapters.add(buttonNorthInnerKA);
AWTMouseAdapter buttonNorthInnerMA = new AWTMouseAdapter("ButtonNorthInner");
buttonNorthInner.addMouseListener(buttonNorthInnerMA);
+ eventCountAdapters.add(buttonNorthInnerMA);
Container container1 = new Container();
container1.setLayout(new BorderLayout());
container1.add(buttonNorthInner, BorderLayout.NORTH);
@@ -125,10 +139,13 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
Button buttonNorthOuter = new Button("north");
AWTFocusAdapter buttonNorthOuterFA = new AWTFocusAdapter("ButtonNorthOuter");
buttonNorthOuter.addFocusListener(buttonNorthOuterFA);
+ eventCountAdapters.add(buttonNorthOuterFA);
AWTKeyAdapter buttonNorthOuterKA = new AWTKeyAdapter("ButtonNorthOuter");
buttonNorthOuter.addKeyListener(buttonNorthOuterKA);
+ eventCountAdapters.add(buttonNorthOuterKA);
AWTMouseAdapter buttonNorthOuterMA = new AWTMouseAdapter("ButtonNorthOuter");
buttonNorthOuter.addMouseListener(buttonNorthOuterMA);
+ eventCountAdapters.add(buttonNorthOuterMA);
JPanel jPanel1 = new JPanel();
jPanel1.setLayout(new BorderLayout());
jPanel1.add(buttonNorthOuter, BorderLayout.NORTH);
@@ -159,7 +176,9 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
// Button Outer Focus
Thread.sleep(100); // allow event sync
System.err.println("FOCUS AWT Button Outer request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, buttonNorthOuter, buttonNorthOuter));
+ Assert.assertEquals(1, buttonNorthOuterFA.getCount());
Assert.assertEquals(0, glWindow1FA.getCount());
Assert.assertEquals(0, newtCanvasAWTFA.getCount());
Assert.assertEquals(0, buttonNorthInnerFA.getCount());
@@ -174,10 +193,12 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
// NEWT Focus
Thread.sleep(100); // allow event sync
System.err.println("FOCUS NEWT Canvas/GLWindow request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild()));
+ Assert.assertEquals(1, glWindow1FA.getCount());
Assert.assertEquals(0, newtCanvasAWTFA.getCount());
Assert.assertEquals(0, buttonNorthInnerFA.getCount());
- Assert.assertEquals(0, buttonNorthOuterFA.getCount());
+ // Assert.assertEquals(-1, buttonNorthOuterFA.getCount()); // lost focus
Assert.assertEquals(0, jFrame1FA.getCount());
System.err.println("FOCUS NEWT Canvas/GLWindow sync");
Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA));
@@ -191,8 +212,10 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
// Button Inner Focus
Thread.sleep(100); // allow event sync
System.err.println("FOCUS AWT Button request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, buttonNorthInner, buttonNorthInner));
- Assert.assertEquals(0, glWindow1FA.getCount());
+ Assert.assertEquals(1, buttonNorthInnerFA.getCount());
+ // Assert.assertEquals(-1, glWindow1FA.getCount()); // lost focus
Assert.assertEquals(0, newtCanvasAWTFA.getCount());
Assert.assertEquals(0, buttonNorthOuterFA.getCount());
Assert.assertEquals(0, jFrame1FA.getCount());
@@ -206,9 +229,11 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
// NEWT Focus
Thread.sleep(100); // allow event sync
System.err.println("FOCUS NEWT Canvas/GLWindow request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild()));
+ Assert.assertEquals(1, glWindow1FA.getCount());
Assert.assertEquals(0, newtCanvasAWTFA.getCount());
- Assert.assertEquals(0, buttonNorthInnerFA.getCount());
+ // Assert.assertEquals(-1, buttonNorthInnerFA.getCount()); // lost focus
Assert.assertEquals(0, buttonNorthOuterFA.getCount());
Assert.assertEquals(0, jFrame1FA.getCount());
System.err.println("FOCUS NEWT Canvas/GLWindow sync");
@@ -237,7 +262,7 @@ public class TestFocus02SwingAWTRobot extends UITestCase {
glWindow1.destroy(true);
}
-// @Test
+ @Test
public void testFocus01ProgrFocus() throws AWTException, InterruptedException, InvocationTargetException {
testFocus01ProgrFocusImpl(null);
}
diff --git a/src/junit/com/jogamp/test/junit/util/AWTFocusAdapter.java b/src/junit/com/jogamp/test/junit/util/AWTFocusAdapter.java
index 6fa9d47a3..174152639 100644
--- a/src/junit/com/jogamp/test/junit/util/AWTFocusAdapter.java
+++ b/src/junit/com/jogamp/test/junit/util/AWTFocusAdapter.java
@@ -34,11 +34,12 @@ import java.awt.event.FocusListener;
public class AWTFocusAdapter implements EventCountAdapter, FocusListener {
String prefix;
- int focusGained = 0;
- boolean wasTemporary = false;
+ int focusGained;
+ boolean wasTemporary;
public AWTFocusAdapter(String prefix) {
this.prefix = prefix;
+ reset();
}
/** @return the balance of focus gained/lost, ie should be 0 or 1 */
@@ -46,6 +47,11 @@ public class AWTFocusAdapter implements EventCountAdapter, FocusListener {
return focusGained;
}
+ public void reset() {
+ focusGained = 0;
+ wasTemporary = false;
+ }
+
/** @return true, if the last change was temporary */
public boolean getWasTemporary() {
return wasTemporary;
diff --git a/src/junit/com/jogamp/test/junit/util/AWTKeyAdapter.java b/src/junit/com/jogamp/test/junit/util/AWTKeyAdapter.java
index 607ccc220..8e255acb6 100644
--- a/src/junit/com/jogamp/test/junit/util/AWTKeyAdapter.java
+++ b/src/junit/com/jogamp/test/junit/util/AWTKeyAdapter.java
@@ -35,12 +35,17 @@ public class AWTKeyAdapter extends java.awt.event.KeyAdapter implements EventCou
public AWTKeyAdapter(String prefix) {
this.prefix = prefix;
+ reset();
}
public int getCount() {
return keyTyped;
}
+ public void reset() {
+ keyTyped = 0;
+ }
+
public void keyTyped(java.awt.event.KeyEvent e) {
++keyTyped;
System.err.println("KEY AWT TYPED ["+keyTyped+"]: "+prefix+", "+e);
diff --git a/src/junit/com/jogamp/test/junit/util/AWTMouseAdapter.java b/src/junit/com/jogamp/test/junit/util/AWTMouseAdapter.java
index e841dc8e1..d78b3ed61 100644
--- a/src/junit/com/jogamp/test/junit/util/AWTMouseAdapter.java
+++ b/src/junit/com/jogamp/test/junit/util/AWTMouseAdapter.java
@@ -34,12 +34,17 @@ public class AWTMouseAdapter extends java.awt.event.MouseAdapter implements Even
public AWTMouseAdapter(String prefix) {
this.prefix = prefix;
+ reset();
}
public int getCount() {
return mouseClicked;
}
+ public void reset() {
+ mouseClicked = 0;
+ }
+
public void mouseClicked(java.awt.event.MouseEvent e) {
mouseClicked+=e.getClickCount();
System.err.println("MOUSE AWT CLICKED ["+mouseClicked+"]: "+prefix+", "+e);
diff --git a/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java b/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java
index a167766f5..48563b190 100644
--- a/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java
+++ b/src/junit/com/jogamp/test/junit/util/AWTRobotUtil.java
@@ -43,6 +43,8 @@ import javax.swing.JFrame;
public class AWTRobotUtil {
public static int TIME_OUT = 1000; // 1s
+ public static int ROBOT_DELAY = 50; // ms
+ public static int POLL_DIVIDER = 20; // TO/20
public static Point getCenterLocation(Object obj, boolean frameTitlebar)
throws InterruptedException, InvocationTargetException {
@@ -100,7 +102,7 @@ public class AWTRobotUtil {
Point p0 = getCenterLocation(window, false);
System.err.println("robot pos: "+p0);
robot.mouseMove( (int) p0.getX(), (int) p0.getY() );
- robot.delay(50);
+ robot.delay(ROBOT_DELAY);
final Window f_window = window;
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
@@ -109,14 +111,14 @@ public class AWTRobotUtil {
f_window.toFront();
f_window.requestFocus();
}});
- robot.delay(200);
+ robot.delay(ROBOT_DELAY);
KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
int wait;
- for (wait=0; wait<10 && window != kfm.getFocusedWindow(); wait++) {
- Thread.sleep(TIME_OUT/10);
+ for (wait=0; wait<POLL_DIVIDER && window != kfm.getFocusedWindow(); wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
}
- return wait<10;
+ return wait<POLL_DIVIDER;
}
/**
@@ -144,7 +146,7 @@ public class AWTRobotUtil {
System.err.println("robot pos: "+p0);
robot.mouseMove( (int) p0.getX(), (int) p0.getY() );
- robot.delay(50);
+ robot.delay(ROBOT_DELAY);
}
/**
@@ -179,11 +181,11 @@ public class AWTRobotUtil {
centerMouse(robot, obj);
- robot.delay(50);
+ robot.delay(ROBOT_DELAY);
robot.mousePress(InputEvent.BUTTON1_MASK);
- robot.delay(50);
+ robot.delay(ROBOT_DELAY);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
- robot.delay(50);
+ robot.delay(ROBOT_DELAY);
}
/**
@@ -195,18 +197,18 @@ public class AWTRobotUtil {
if(obj instanceof Component) {
Component comp = (Component) obj;
KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
- for (wait=0; wait<10 && comp != kfm.getPermanentFocusOwner(); wait++) {
- Thread.sleep(TIME_OUT/10);
+ for (wait=0; wait<POLL_DIVIDER && comp != kfm.getPermanentFocusOwner(); wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
}
} else if(obj instanceof com.jogamp.newt.Window) {
com.jogamp.newt.Window win = (com.jogamp.newt.Window) obj;
- for (wait=0; wait<10 && !win.hasFocus(); wait++) {
- Thread.sleep(TIME_OUT/10);
+ for (wait=0; wait<POLL_DIVIDER && !win.hasFocus(); wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
}
} else {
throw new RuntimeException("Neither AWT nor NEWT: "+obj);
}
- return wait<10;
+ return wait<POLL_DIVIDER;
}
public static boolean requestFocusAndWait(Robot robot, Object requestFocus, Object waitForFocus)
@@ -236,15 +238,15 @@ public class AWTRobotUtil {
for(int i=0; i<typeCount; i++) {
robot.keyPress(java.awt.event.KeyEvent.VK_A);
- robot.delay(50);
+ robot.delay(ROBOT_DELAY);
robot.keyRelease(java.awt.event.KeyEvent.VK_A);
- robot.delay(50);
+ robot.delay(ROBOT_DELAY);
}
// Wait for the key events to be processed.
int wait;
- for (wait=0; wait<10 && (keyTypedCounter.getCount()-c0)<typeCount; wait++) {
- Thread.sleep(TIME_OUT/10);
+ for (wait=0; wait<POLL_DIVIDER && (keyTypedCounter.getCount()-c0)<typeCount; wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
}
return keyTypedCounter.getCount()-c0;
}
@@ -267,7 +269,7 @@ public class AWTRobotUtil {
centerMouse(robot, obj);
- robot.delay(2*clickTO);
+ robot.delay(clickTO);
int c0 = mouseClickCounter.getCount();
@@ -277,12 +279,11 @@ public class AWTRobotUtil {
robot.mouseRelease(mouseButton);
robot.delay(clickTO/4);
}
- robot.delay(50);
// Wait for the key events to be processed.
int wait;
- for (wait=0; wait<10 && (mouseClickCounter.getCount()-c0)<clickCount; wait++) {
- Thread.sleep(TIME_OUT/10);
+ for (wait=0; wait<POLL_DIVIDER && (mouseClickCounter.getCount()-c0)<clickCount; wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
}
return mouseClickCounter.getCount()-c0;
}
diff --git a/src/junit/com/jogamp/test/junit/util/EventCountAdapter.java b/src/junit/com/jogamp/test/junit/util/EventCountAdapter.java
index 3087d5c99..e0561218a 100644
--- a/src/junit/com/jogamp/test/junit/util/EventCountAdapter.java
+++ b/src/junit/com/jogamp/test/junit/util/EventCountAdapter.java
@@ -31,6 +31,6 @@ package com.jogamp.test.junit.util;
public interface EventCountAdapter {
int getCount();
-
+ void reset();
}
diff --git a/src/junit/com/jogamp/test/junit/util/EventCountAdapterUtil.java b/src/junit/com/jogamp/test/junit/util/EventCountAdapterUtil.java
new file mode 100644
index 000000000..40b192a01
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/EventCountAdapterUtil.java
@@ -0,0 +1,49 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.test.junit.util;
+
+import java.util.List;
+import java.util.Iterator;
+
+public abstract class EventCountAdapterUtil {
+
+ public static void reset(EventCountAdapter[] adapters) {
+ for(int i=0; i<adapters.length; i++) {
+ adapters[i].reset();
+ }
+ }
+
+ public static void reset(List/*<EventCountAdapter>*/ adapters) {
+ for(Iterator i = adapters.iterator(); i.hasNext(); ) {
+ EventCountAdapter adapter = (EventCountAdapter) i.next();
+ adapter.reset();
+ }
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/util/NEWTFocusAdapter.java b/src/junit/com/jogamp/test/junit/util/NEWTFocusAdapter.java
index 48d2fd565..5cbd9fd15 100644
--- a/src/junit/com/jogamp/test/junit/util/NEWTFocusAdapter.java
+++ b/src/junit/com/jogamp/test/junit/util/NEWTFocusAdapter.java
@@ -34,16 +34,21 @@ import com.jogamp.newt.event.WindowEvent;
public class NEWTFocusAdapter extends WindowAdapter implements EventCountAdapter {
String prefix;
- int focusGained = 0;
+ int focusGained;
public NEWTFocusAdapter(String prefix) {
this.prefix = prefix;
+ reset();
}
public int getCount() {
return focusGained;
}
+ public void reset() {
+ focusGained = 0;
+ }
+
@Override
public void windowGainedFocus(WindowEvent e) {
++focusGained;
diff --git a/src/junit/com/jogamp/test/junit/util/NEWTKeyAdapter.java b/src/junit/com/jogamp/test/junit/util/NEWTKeyAdapter.java
index ab00f4f61..73caa1846 100644
--- a/src/junit/com/jogamp/test/junit/util/NEWTKeyAdapter.java
+++ b/src/junit/com/jogamp/test/junit/util/NEWTKeyAdapter.java
@@ -38,12 +38,17 @@ public class NEWTKeyAdapter extends KeyAdapter implements EventCountAdapter {
public NEWTKeyAdapter(String prefix) {
this.prefix = prefix;
+ reset();
}
public int getCount() {
return keyTyped;
}
+ public void reset() {
+ keyTyped = 0;
+ }
+
@Override
public void keyTyped(KeyEvent e) {
++keyTyped;
diff --git a/src/junit/com/jogamp/test/junit/util/NEWTMouseAdapter.java b/src/junit/com/jogamp/test/junit/util/NEWTMouseAdapter.java
index 36943a805..fc5c653f2 100644
--- a/src/junit/com/jogamp/test/junit/util/NEWTMouseAdapter.java
+++ b/src/junit/com/jogamp/test/junit/util/NEWTMouseAdapter.java
@@ -38,12 +38,17 @@ public class NEWTMouseAdapter extends MouseAdapter implements EventCountAdapter
public NEWTMouseAdapter(String prefix) {
this.prefix = prefix;
+ reset();
}
public int getCount() {
return mouseClicked;
}
+ public void reset() {
+ mouseClicked = 0;
+ }
+
public void mouseClicked(MouseEvent e) {
mouseClicked+=e.getClickCount();
System.err.println("MOUSE NEWT CLICKED ["+mouseClicked+"]: "+prefix+", "+e);