JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug816OSXCALayerPos03bB849AWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2013 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.jogl.awt;
30
31import java.awt.BorderLayout;
32import java.awt.Checkbox;
33import java.awt.Frame;
34import java.awt.GridLayout;
35import java.awt.Panel;
36import java.awt.event.ItemEvent;
37import java.awt.event.ItemListener;
38import java.lang.reflect.InvocationTargetException;
39
40import com.jogamp.opengl.GLCapabilities;
41import com.jogamp.opengl.GLProfile;
42import com.jogamp.opengl.awt.GLCanvas;
43
44import org.junit.Assert;
45import org.junit.FixMethodOrder;
46import org.junit.Test;
47import org.junit.runners.MethodSorters;
48
49import com.jogamp.newt.event.TraceWindowAdapter;
50import com.jogamp.newt.event.awt.AWTWindowAdapter;
51import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
52import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
53import com.jogamp.opengl.test.junit.util.MiscUtils;
54import com.jogamp.opengl.test.junit.util.QuitAdapter;
55import com.jogamp.opengl.test.junit.util.UITestCase;
56import com.jogamp.opengl.util.Animator;
57
58/**
59 * AWT Frame BorderLayout w/ Checkbox North, Panel.GLCanvas Center.
60 * <p>
61 * Checkbox toggles GLCanvas's parent panel's visibility state.
62 * </p>
63 * <p>
64 * Validates bugs:
65 * <ul>
66 * <li>Bug 816: OSX CALayer Positioning Bug</li>
67 * <li>Bug 729: OSX CALayer shall honor the Component's visibility state</li>
68 * <li>Bug 849: AWT GLAutoDrawables (JAWTWindow) shall honor it's parent visibility state</li>
69 * </ul>
70 * </p>
71 * <p>
72 * Diff. OSX CALayer positioning w/ java6, [7uxx..7u40[, and >= 7u40
73 * </p>
74 */
75@FixMethodOrder(MethodSorters.NAME_ASCENDING)
77 static long duration = 1600; // ms
78 static int width=640, height=480;
79
80 @Test
81 public void test() throws InterruptedException, InvocationTargetException {
82 final GLCapabilities caps = new GLCapabilities(getGLP());
83
84 final Frame frame = new Frame("TestBug816OSXCALayerPos03bAWT");
85 Assert.assertNotNull(frame);
86
87 final GLCanvas glCanvas1 = new GLCanvas(caps);
88 Assert.assertNotNull(glCanvas1);
89 glCanvas1.addGLEventListener(new GearsES2(1));
90 // Put it in a panel
91 final Panel panel = new Panel(new GridLayout(1, 1));
92 panel.add(glCanvas1);
93
94 final Animator animator = new Animator();
95 animator.add(glCanvas1);
96
97 final QuitAdapter quitAdapter = new QuitAdapter();
98 new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas1).addTo(frame);
99
100 // Create a check box that hides / shows canvas
101 final Checkbox checkbox = new Checkbox("Visible canvas", true);
102 checkbox.addItemListener(new ItemListener() {
103 public void itemStateChanged(final ItemEvent ev) {
104 final boolean visible = checkbox.getState();
105 System.err.println("XXXX Panel setVisible "+visible);
106 panel.setVisible(visible);
107 System.err.println("XXXX Visible: [panel "+panel.isVisible()+", canvas "+glCanvas1.isVisible()+"]; Displayable: [panel "+panel.isDisplayable()+", canvas "+glCanvas1.isDisplayable()+"]");
108 if( panel.isVisible() ) {
109 frame.validate(); // take care of resized frame while hidden
110 }
111 }
112 });
113
114 // Build a GUI that displays canvas and check box
115 frame.setLayout(new BorderLayout());
116 frame.add(panel, BorderLayout.CENTER);
117 frame.add(checkbox, BorderLayout.NORTH);
118
119 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
120 public void run() {
121 frame.setSize(width, height);
122 frame.setVisible(true);
123 }});
124 Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true, null));
125 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas1, true, null));
126
127 animator.start();
128 Assert.assertTrue(animator.isStarted());
129 Assert.assertTrue(animator.isAnimating());
130
131 final long t0 = System.currentTimeMillis();
132 long t1 = t0;
133 while(!quitAdapter.shouldQuit() && t1 - t0 < duration) {
134 Thread.sleep(100);
135 t1 = System.currentTimeMillis();
136 }
137
138 Assert.assertNotNull(frame);
139 Assert.assertNotNull(glCanvas1);
140
141 Assert.assertNotNull(animator);
142 animator.stop();
143 Assert.assertFalse(animator.isAnimating());
144 Assert.assertFalse(animator.isStarted());
145
146 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
147 public void run() {
148 frame.setVisible(false);
149 }});
150 Assert.assertEquals(false, frame.isVisible());
151 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
152 public void run() {
153 frame.remove(panel);
154 frame.dispose();
155 }});
156 }
157
158 static GLProfile getGLP() {
160 }
161
162 public static void main(final String args[]) {
163 for(int i=0; i<args.length; i++) {
164 if(args[i].equals("-time")) {
165 i++;
166 duration = MiscUtils.atol(args[i], duration);
167 }
168 }
169
170 org.junit.runner.JUnitCore.main(TestBug816OSXCALayerPos03bB849AWT.class.getName());
171 }
172}
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getMaxProgrammableCore(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the programmable shader core pipeline only.
Definition: GLProfile.java:854
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
AWT Frame BorderLayout w/ Checkbox North, Panel.GLCanvas Center.
static boolean waitForRealized(final java.awt.Component comp, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final java.awt.Component comp, final boolean visible, final Runnable waitAction)
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
synchronized boolean isStarted()
Indicates whether this animator has been started.
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368