summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java122
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03aAWT.java (renamed from src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03AWT.java)18
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03bAWT.java171
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03cAWT.java173
4 files changed, 454 insertions, 30 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
index 069147d26..6e198d961 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
@@ -37,6 +37,7 @@
package com.jogamp.nativewindow.awt;
+import com.jogamp.common.os.Platform;
import com.jogamp.common.util.locks.LockFactory;
import com.jogamp.common.util.locks.RecursiveLock;
import com.jogamp.nativewindow.MutableGraphicsConfiguration;
@@ -46,6 +47,8 @@ import java.awt.Container;
import java.awt.Window;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
+import java.awt.event.HierarchyEvent;
+import java.awt.event.HierarchyListener;
import java.applet.Applet;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
@@ -76,10 +79,11 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
protected boolean shallUseOffscreenLayer = false;
// lifetime: forever
- protected Component component;
- private AWTGraphicsConfiguration config; // control access due to delegation
- private SurfaceUpdatedHelper surfaceUpdatedHelper = new SurfaceUpdatedHelper();
- private RecursiveLock surfaceLock = LockFactory.createRecursiveLock();
+ protected final Component component;
+ private final AWTGraphicsConfiguration config; // control access due to delegation
+ private final SurfaceUpdatedHelper surfaceUpdatedHelper = new SurfaceUpdatedHelper();
+ private final RecursiveLock surfaceLock = LockFactory.createRecursiveLock();
+ private final JAWTComponentListener jawtComponentListener;
// lifetime: valid after lock but may change with each 1st lock, purges after invalidate
private boolean isApplet;
@@ -106,39 +110,110 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
if(! ( config instanceof AWTGraphicsConfiguration ) ) {
throw new NativeWindowException("Error: AbstractGraphicsConfiguration is not an AWTGraphicsConfiguration: "+config);
}
+ this.component = (Component)comp;
this.config = (AWTGraphicsConfiguration) config;
- init((Component)comp);
- }
-
- private void init(Component windowObject) throws NativeWindowException {
+ this.jawtComponentListener = new JAWTComponentListener();
+ this.component.addComponentListener(jawtComponentListener);
+ this.component.addHierarchyListener(jawtComponentListener);
invalidate();
- this.component = windowObject;
this.isApplet = false;
this.offscreenSurfaceLayer = 0;
- this.component.addComponentListener(new ComponentListener() {
- private boolean visible = component.isVisible();
+ }
+ private class JAWTComponentListener implements ComponentListener, HierarchyListener {
+ private boolean localVisibility = component.isVisible();
+ private boolean globalVisibility = localVisibility;
+ private boolean visibilityPropagation = false;
+
+ private String s(ComponentEvent e) {
+ return "visible[local "+localVisibility+", global "+globalVisibility+", propag. "+visibilityPropagation+"],"+Platform.getNewline()+
+ " ** COMP "+e.getComponent()+Platform.getNewline()+
+ " ** SOURCE "+e.getSource()+Platform.getNewline()+
+ " ** THIS "+component;
+ }
+ private String s(HierarchyEvent e) {
+ return "visible[local "+localVisibility+", global "+globalVisibility+", propag. "+visibilityPropagation+"], changeBits 0x"+Long.toHexString(e.getChangeFlags())+Platform.getNewline()+
+ " ** COMP "+e.getComponent()+Platform.getNewline()+
+ " ** SOURCE "+e.getSource()+Platform.getNewline()+
+ " ** CHANGED "+e.getChanged()+Platform.getNewline()+
+ " ** CHANGEDPARENT "+e.getChangedParent()+Platform.getNewline()+
+ " ** THIS "+component;
+ }
+
@Override
public void componentResized(ComponentEvent e) {
- layoutSurfaceLayerIfEnabled(visible);
+ if(DEBUG) {
+ System.err.println("JAWTWindow.componentResized: "+s(e));
+ }
+ layoutSurfaceLayerIfEnabled(globalVisibility && localVisibility);
}
@Override
public void componentMoved(ComponentEvent e) {
- layoutSurfaceLayerIfEnabled(visible);
+ if(DEBUG) {
+ System.err.println("JAWTWindow.componentMoved: "+s(e));
+ }
+ layoutSurfaceLayerIfEnabled(globalVisibility && localVisibility);
}
@Override
public void componentShown(ComponentEvent e) {
- visible = true;
- layoutSurfaceLayerIfEnabled(visible);
+ if(DEBUG) {
+ System.err.println("JAWTWindow.componentShown: "+s(e));
+ }
+ layoutSurfaceLayerIfEnabled(globalVisibility && localVisibility);
}
@Override
public void componentHidden(ComponentEvent e) {
- visible = false;
- layoutSurfaceLayerIfEnabled(visible);
- }
- });
+ if(DEBUG) {
+ System.err.println("JAWTWindow.componentHidden: "+s(e));
+ }
+ layoutSurfaceLayerIfEnabled(globalVisibility && localVisibility);
+ }
+
+ @Override
+ public void hierarchyChanged(HierarchyEvent e) {
+ final long bits = e.getChangeFlags();
+ final java.awt.Component changed = e.getChanged();
+ if( 0 != ( java.awt.event.HierarchyEvent.DISPLAYABILITY_CHANGED & bits ) ) {
+ final boolean displayable = changed.isDisplayable();
+ final boolean resetLocalVisibility = changed == component && !displayable && localVisibility != component.isVisible();
+ if( resetLocalVisibility ) {
+ // Reset components local state if detached from parent, i.e. 'removeNotify()'
+ visibilityPropagation = true;
+ if(DEBUG) {
+ System.err.println("JAWTWindow.hierarchyChanged DISPLAYABILITY_CHANGED (1): displayable "+displayable+", "+s(e));
+ }
+ component.setVisible(localVisibility);
+ } else if(DEBUG) {
+ System.err.println("JAWTWindow.hierarchyChanged DISPLAYABILITY_CHANGED (x): displayable "+displayable+", "+s(e));
+ }
+ } else if( 0 != ( java.awt.event.HierarchyEvent.SHOWING_CHANGED & bits ) ) {
+ final boolean showing = changed.isShowing();
+ final boolean propagateVisibility = changed != component && ( showing && localVisibility ) != component.isVisible();
+ if( propagateVisibility ) {
+ // Propagate parent's visibility
+ final boolean _visible = showing && localVisibility;
+ visibilityPropagation = true;
+ globalVisibility = showing;
+ if(DEBUG) {
+ System.err.println("JAWTWindow.hierarchyChanged SHOWING_CHANGED (1): showing "+showing+" -> visible "+_visible+", "+s(e));
+ }
+ component.setVisible(_visible);
+ } else if( changed == component ) {
+ // Update component's local visibility state
+ if(!visibilityPropagation) {
+ localVisibility = showing;
+ }
+ visibilityPropagation = false;
+ if(DEBUG) {
+ System.err.println("JAWTWindow.hierarchyChanged SHOWING_CHANGED (0): showing "+showing+" -> visible "+(showing && localVisibility)+", "+s(e));
+ }
+ } else if(DEBUG) {
+ System.err.println("JAWTWindow.hierarchyChanged SHOWING_CHANGED (x): showing "+showing+" -> visible "+(showing && localVisibility)+", "+s(e));
+ }
+ }
+ }
}
protected synchronized void invalidate() {
@@ -488,7 +563,6 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
surfaceLock.lock();
try {
invalidate();
- component = null; // don't dispose the AWT component, since we are merely an immutable uplink
} finally {
surfaceLock.unlock();
}
@@ -638,12 +712,8 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
", surfaceHandle "+toHexString(getSurfaceHandle())+
", bounds "+bounds+", insets "+insets
);
- if(null!=component) {
- sb.append(", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+
- ", visible "+component.isVisible());
- } else {
- sb.append(", component NULL");
- }
+ sb.append(", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+
+ ", visible "+component.isVisible());
sb.append(", lockedExt "+isSurfaceLockedByOtherThread()+
",\n\tconfig "+getPrivateGraphicsConfiguration()+
",\n\tawtComponent "+getAWTComponent()+
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03aAWT.java
index 92d24e417..3451b75cc 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03AWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03aAWT.java
@@ -54,13 +54,23 @@ import com.jogamp.opengl.test.junit.util.UITestCase;
import com.jogamp.opengl.util.Animator;
/**
- * Bug 816: OSX CALayer Positioning Bug - AWT Frame BorderLayout w/ Checkbox North, GLCanvas Center
+ * AWT Frame BorderLayout w/ Checkbox North, GLCanvas Center.
+ * <p>
+ * Checkbox toggles GLCanvas visibility state.
+ * </p>
+ * <p>
+ * Validates bugs:
+ * <ul>
+ * <li>Bug 816: OSX CALayer Positioning Bug</li>
+ * <li>Bug 729: OSX CALayer shall honor the Component's visibility state</li>
+ * </ul>
+ * </p>
* <p>
* Diff. OSX CALayer positioning w/ java6, [7uxx..7u40[, and >= 7u40
* </p>
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class TestBug816OSXCALayerPos03AWT extends UITestCase {
+public class TestBug816OSXCALayerPos03aAWT extends UITestCase {
static long duration = 1600; // ms
static int width=640, height=480;
@@ -68,7 +78,7 @@ public class TestBug816OSXCALayerPos03AWT extends UITestCase {
public void test() throws InterruptedException, InvocationTargetException {
final GLCapabilities caps = new GLCapabilities(getGLP());
- final Frame frame = new Frame("TestBug816OSXCALayerPos03AWT");
+ final Frame frame = new Frame("TestBug816OSXCALayerPos03aAWT");
Assert.assertNotNull(frame);
final GLCanvas glCanvas1 = new GLCanvas(caps);
@@ -150,6 +160,6 @@ public class TestBug816OSXCALayerPos03AWT extends UITestCase {
}
}
- org.junit.runner.JUnitCore.main(TestBug816OSXCALayerPos03AWT.class.getName());
+ org.junit.runner.JUnitCore.main(TestBug816OSXCALayerPos03aAWT.class.getName());
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03bAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03bAWT.java
new file mode 100644
index 000000000..6f57f1e77
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03bAWT.java
@@ -0,0 +1,171 @@
+/**
+ * Copyright 2013 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.opengl.test.junit.jogl.awt;
+
+import java.awt.BorderLayout;
+import java.awt.Checkbox;
+import java.awt.Frame;
+import java.awt.GridLayout;
+import java.awt.Panel;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
+
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+import com.jogamp.newt.event.TraceWindowAdapter;
+import com.jogamp.newt.event.awt.AWTWindowAdapter;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.QuitAdapter;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.util.Animator;
+
+/**
+ * AWT Frame BorderLayout w/ Checkbox North, Panel.GLCanvas Center.
+ * <p>
+ * Checkbox toggles GLCanvas's parent panel's visibility state.
+ * </p>
+ * <p>
+ * Validates bugs:
+ * <ul>
+ * <li>Bug 816: OSX CALayer Positioning Bug</li>
+ * <li>Bug 729: OSX CALayer shall honor the Component's visibility state</li>
+ * <li>Bug 849: AWT GLAutoDrawables (JAWTWindow) shall honor it's parent visibility state</li>
+ * </ul>
+ * </p>
+ * <p>
+ * Diff. OSX CALayer positioning w/ java6, [7uxx..7u40[, and >= 7u40
+ * </p>
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestBug816OSXCALayerPos03bAWT extends UITestCase {
+ static long duration = 1600; // ms
+ static int width=640, height=480;
+
+ @Test
+ public void test() throws InterruptedException, InvocationTargetException {
+ final GLCapabilities caps = new GLCapabilities(getGLP());
+
+ final Frame frame = new Frame("TestBug816OSXCALayerPos03bAWT");
+ Assert.assertNotNull(frame);
+
+ final GLCanvas glCanvas1 = new GLCanvas(caps);
+ Assert.assertNotNull(glCanvas1);
+ glCanvas1.addGLEventListener(new GearsES2(1));
+ // Put it in a panel
+ final Panel panel = new Panel(new GridLayout(1, 1));
+ panel.add(glCanvas1);
+
+ final Animator animator = new Animator();
+ animator.add(glCanvas1);
+ QuitAdapter quitAdapter = new QuitAdapter();
+
+ new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame);
+
+ // Create a check box that hides / shows canvas
+ final Checkbox checkbox = new Checkbox("Visible canvas", true);
+ checkbox.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent ev) {
+ panel.setVisible(checkbox.getState());
+ System.out.println("Visible: [panel "+panel.isVisible()+", canvas "+glCanvas1.isVisible()+"]; Displayable: [panel "+panel.isDisplayable()+", canvas "+glCanvas1.isDisplayable()+"]");
+ if( panel.isVisible() ) {
+ frame.validate(); // take care of resized frame while hidden
+ }
+ }
+ });
+
+ // Build a GUI that displays canvas and check box
+ frame.setLayout(new BorderLayout());
+ frame.add(panel, BorderLayout.CENTER);
+ frame.add(checkbox, BorderLayout.NORTH);
+
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setSize(width, height);
+ frame.setVisible(true);
+ }});
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas1, true));
+
+ animator.start();
+ Assert.assertTrue(animator.isStarted());
+ Assert.assertTrue(animator.isAnimating());
+ animator.setUpdateFPSFrames(60, System.err);
+
+ final long t0 = System.currentTimeMillis();
+ long t1 = t0;
+ while(!quitAdapter.shouldQuit() && t1 - t0 < duration) {
+ Thread.sleep(100);
+ t1 = System.currentTimeMillis();
+ }
+
+ Assert.assertNotNull(frame);
+ Assert.assertNotNull(glCanvas1);
+
+ Assert.assertNotNull(animator);
+ animator.stop();
+ Assert.assertFalse(animator.isAnimating());
+ Assert.assertFalse(animator.isStarted());
+
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setVisible(false);
+ }});
+ Assert.assertEquals(false, frame.isVisible());
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.remove(panel);
+ frame.dispose();
+ }});
+ }
+
+ static GLProfile getGLP() {
+ return GLProfile.getMaxProgrammableCore(true);
+ }
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ duration = MiscUtils.atol(args[i], duration);
+ }
+ }
+
+ org.junit.runner.JUnitCore.main(TestBug816OSXCALayerPos03bAWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03cAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03cAWT.java
new file mode 100644
index 000000000..b06e9d970
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03cAWT.java
@@ -0,0 +1,173 @@
+/**
+ * Copyright 2013 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.opengl.test.junit.jogl.awt;
+
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.GridLayout;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
+import javax.swing.JCheckBox;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+import com.jogamp.newt.event.TraceWindowAdapter;
+import com.jogamp.newt.event.awt.AWTWindowAdapter;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.QuitAdapter;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.util.Animator;
+
+/**
+ * AWT JFrame BorderLayout w/ Checkbox North, JPanel.GLCanvas Center.
+ * <p>
+ * Checkbox toggles GLCanvas's parent jpanel's visibility state.
+ * </p>
+ * <p>
+ * Validates bugs:
+ * <ul>
+ * <li>Bug 816: OSX CALayer Positioning Bug</li>
+ * <li>Bug 729: OSX CALayer shall honor the Component's visibility state</li>
+ * <li>Bug 849: AWT GLAutoDrawables (JAWTWindow) shall honor it's parent visibility state</li>
+ * </ul>
+ * </p>
+ * <p>
+ * Diff. OSX CALayer positioning w/ java6, [7uxx..7u40[, and >= 7u40
+ * </p>
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestBug816OSXCALayerPos03cAWT extends UITestCase {
+ static long duration = 1600; // ms
+ static int width=640, height=480;
+
+ @Test
+ public void test() throws InterruptedException, InvocationTargetException {
+ final GLCapabilities caps = new GLCapabilities(getGLP());
+
+ final JFrame frame = new JFrame("TestBug816OSXCALayerPos03cAWT");
+ Assert.assertNotNull(frame);
+ final Container framePane = frame.getContentPane();
+
+ final GLCanvas glCanvas1 = new GLCanvas(caps);
+ Assert.assertNotNull(glCanvas1);
+ glCanvas1.addGLEventListener(new GearsES2(1));
+ // Put it in a panel
+ final JPanel panel = new JPanel(new GridLayout(1, 1));
+ panel.add(glCanvas1);
+
+ final Animator animator = new Animator();
+ animator.add(glCanvas1);
+ QuitAdapter quitAdapter = new QuitAdapter();
+
+ new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame);
+
+ // Create a check box that hides / shows canvas
+ final JCheckBox checkbox = new JCheckBox("Visible canvas", true);
+ checkbox.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent ev) {
+ panel.setVisible(checkbox.getSelectedObjects()!=null);
+ System.out.println("Visible: [panel "+panel.isVisible()+", canvas "+glCanvas1.isVisible()+"]; Displayable: [panel "+panel.isDisplayable()+", canvas "+glCanvas1.isDisplayable()+"]");
+ if( panel.isVisible() ) {
+ frame.validate(); // take care of resized frame while hidden
+ }
+ }
+ });
+
+ // Build a GUI that displays canvas and check box
+ framePane.setLayout(new BorderLayout());
+ framePane.add(panel, BorderLayout.CENTER);
+ framePane.add(checkbox, BorderLayout.NORTH);
+
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setSize(width, height);
+ frame.setVisible(true);
+ }});
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas1, true));
+
+ animator.start();
+ Assert.assertTrue(animator.isStarted());
+ Assert.assertTrue(animator.isAnimating());
+ animator.setUpdateFPSFrames(60, System.err);
+
+ final long t0 = System.currentTimeMillis();
+ long t1 = t0;
+ while(!quitAdapter.shouldQuit() && t1 - t0 < duration) {
+ Thread.sleep(100);
+ t1 = System.currentTimeMillis();
+ }
+
+ Assert.assertNotNull(frame);
+ Assert.assertNotNull(glCanvas1);
+
+ Assert.assertNotNull(animator);
+ animator.stop();
+ Assert.assertFalse(animator.isAnimating());
+ Assert.assertFalse(animator.isStarted());
+
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setVisible(false);
+ }});
+ Assert.assertEquals(false, frame.isVisible());
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ framePane.remove(panel);
+ frame.dispose();
+ }});
+ }
+
+ static GLProfile getGLP() {
+ return GLProfile.getMaxProgrammableCore(true);
+ }
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ duration = MiscUtils.atol(args[i], duration);
+ }
+ }
+
+ org.junit.runner.JUnitCore.main(TestBug816OSXCALayerPos03cAWT.class.getName());
+ }
+}