JOGL: src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816JTabbedPanelVisibilityB849B878AWT.java Source File

JOGL v2.6.0-rc-20250721 JOGL, High-Performance Graphics Binding for Java™ (public API).

TestBug816JTabbedPanelVisibilityB849B878AWT.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 */
28package com.jogamp.opengl.test.junit.jogl.awt;
29
30import java.awt.BorderLayout;
31import java.lang.reflect.InvocationTargetException;
32
33import com.jogamp.opengl.GLCapabilities;
34import com.jogamp.opengl.GLProfile;
35import com.jogamp.opengl.awt.GLCanvas;
36import javax.swing.JFrame;
37import javax.swing.JLabel;
38import javax.swing.JPanel;
39import javax.swing.JTabbedPane;
40import javax.swing.SwingUtilities;
41
42import org.junit.Assert;
43import org.junit.FixMethodOrder;
44import org.junit.Test;
45import org.junit.runners.MethodSorters;
46
47import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
48import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
49import com.jogamp.opengl.test.junit.util.MiscUtils;
50import com.jogamp.opengl.test.junit.util.UITestCase;
51
52/**
53 * AWT JFrame w/ JTabbedPanel, Moving GLCanvas between it's tabs while selecting.
54 * <p>
55 * Validates bugs:
56 * <ul>
57 * <li>Bug 816: OSX CALayer Positioning Bug</li>
58 * <li>Bug 729: OSX CALayer shall honor the Component's visibility state</li>
59 * <li>Bug 849: AWT GLAutoDrawables (JAWTWindow) shall honor it's parent visibility state</li>
60 * <li>Bug 878: JAWTWindow's HierarchyListener doesn't set component visible (again) on 'addNotify(..)' - GLCanvas in JtabbedPane disappear</li>
61 * </ul>
62 * </p>
63 */
64@FixMethodOrder(MethodSorters.NAME_ASCENDING)
65public class TestBug816JTabbedPanelVisibilityB849B878AWT extends UITestCase {
66
67 static long durationPerTest = 500*6; // ms
68 static boolean manual = false;
69
70 @Test
71 public void test() throws InterruptedException, InvocationTargetException {
72 final JFrame frame = new JFrame("TestBug816OSXCALayerPos03dBug878AWT");
73
74 final JPanel panel1 = new javax.swing.JPanel();
75 final JPanel panel2 = new javax.swing.JPanel();
76 final JPanel panel3 = new javax.swing.JPanel();
77
78 panel1.setLayout(new BorderLayout());
79 panel2.setLayout(new BorderLayout());
80
81 final GLProfile profile = GLProfile.get(GLProfile.GL2ES2);
82 final GLCapabilities glCapabilities = new GLCapabilities(profile);
83 final GLCanvas glCanvas = new GLCanvas(glCapabilities);
84 glCanvas.setSize(new java.awt.Dimension(640, 480));
85 glCanvas.addGLEventListener(new GearsES2(1));
86 panel1.add(glCanvas, BorderLayout.CENTER);
87 panel3.add(new JLabel("A label to cover the canvas"), BorderLayout.CENTER);
88
89 final JTabbedPane tabbedPanel = new JTabbedPane();
90 tabbedPanel.addTab("tab1", panel1); // glcanvas
91 tabbedPanel.addTab("tab2", panel2); // glcanvas
92 tabbedPanel.addTab("tab3", panel3); // text
93
94 tabbedPanel.addChangeListener(new javax.swing.event.ChangeListener() {
95 @Override
96 public void stateChanged(final javax.swing.event.ChangeEvent evt) {
97 if (tabbedPanel.getSelectedIndex() == 0) {
98 System.err.println("XXXX Add GLCanvas Panel2("+id(panel2)+" -> Panel1("+id(panel1)+") START");
99 dumpGLCanvasStats(glCanvas);
100 panel1.add(glCanvas, BorderLayout.CENTER);
101 dumpGLCanvasStats(glCanvas);
102 } else if (tabbedPanel.getSelectedIndex() == 1) {
103 System.err.println("XXXX Add GLCanvas Panel1("+id(panel1)+" -> Panel2("+id(panel2)+") START");
104 dumpGLCanvasStats(glCanvas);
105 panel2.add(glCanvas, BorderLayout.CENTER);
106 dumpGLCanvasStats(glCanvas);
107 } else {
108 System.err.println("XXXX NOP");
109 dumpGLCanvasStats(glCanvas);
110 }
111 }
112 });
113
114 frame.setContentPane(tabbedPanel);
115 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
116 public void run() {
117 frame.pack();
118 System.err.println("XXX SetVisible ON XXX GLCanvas on Panel1("+id(panel1)+")");
119 frame.setVisible(true);
120 }});
121 Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true, null));
122 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, true, null));
123 dumpGLCanvasStats(glCanvas);
124
125 if(manual) {
126 for(long w=durationPerTest; w>0; w-=100) {
127 Thread.sleep(100);
128 }
129 } else {
130 Thread.sleep(durationPerTest/6);
131 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
132 public void run() {
133 System.err.println("XXXX Panel1("+id(panel1)+" -> Panel2("+id(panel2)+") START");
134 tabbedPanel.setSelectedIndex(1);
135 }});
136
137 Thread.sleep(durationPerTest/6);
138 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
139 public void run() {
140 System.err.println("XXXX Panel2("+id(panel2)+") -> Panel3("+id(panel3)+" START");
141 tabbedPanel.setSelectedIndex(2);
142 }});
143
144 Thread.sleep(durationPerTest/6);
145 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
146 public void run() {
147 System.err.println("XXXX Panel3("+id(panel3)+") -> Panel1("+id(panel1)+" START");
148 tabbedPanel.setSelectedIndex(0);
149 }});
150
151 // one loop done
152
153 Thread.sleep(durationPerTest/6);
154 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
155 public void run() {
156 System.err.println("XXXX Panel1("+id(panel1)+" -> Panel2("+id(panel2)+") START");
157 tabbedPanel.setSelectedIndex(1);
158 }});
159
160 Thread.sleep(durationPerTest/6);
161 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
162 public void run() {
163 System.err.println("XXXX Panel2("+id(panel2)+") -> Panel1("+id(panel1)+" START");
164 tabbedPanel.setSelectedIndex(0);
165 }});
166
167 Thread.sleep(durationPerTest/6);
168 }
169
170 SwingUtilities.invokeLater(new Runnable() {
171 public void run() {
172 System.err.println("XXX SetVisible OFF XXX");
173 frame.dispose();
174 } });
175 }
176
177 private static String id(final Object obj) { return "0x"+Integer.toHexString(obj.hashCode()); }
178
179 static void dumpGLCanvasStats(final GLCanvas glCanvas) {
180 System.err.println("XXXX GLCanvas: comp "+glCanvas+", visible "+glCanvas.isVisible()+", showing "+glCanvas.isShowing()+
181 ", displayable "+glCanvas.isDisplayable()+", "+glCanvas.getSurfaceWidth()+"x"+glCanvas.getSurfaceHeight());
182 }
183
184 public static void main(final String args[]) {
185 for(int i=0; i<args.length; i++) {
186 if(args[i].equals("-time")) {
187 durationPerTest = MiscUtils.atoi(args[++i], (int)durationPerTest);
188 } else if(args[i].equals("-manual")) {
189 manual = true;
190 }
191 }
192 org.junit.runner.JUnitCore.main(TestBug816JTabbedPanelVisibilityB849B878AWT.class.getName());
193 }
194}
com.jogamp.opengl.GLCapabilities
Specifies a set of OpenGL capabilities.
Definition: GLCapabilities.java:58
com.jogamp.opengl.GLProfile
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
com.jogamp.opengl.GLProfile.GL2ES2
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
Definition: GLProfile.java:594
com.jogamp.opengl.GLProfile.get
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
Definition: GLProfile.java:1000
com.jogamp.opengl.awt.GLCanvas
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
com.jogamp.opengl.awt.GLCanvas.addGLEventListener
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
com.jogamp.opengl.test.junit.jogl.awt.TestBug816JTabbedPanelVisibilityB849B878AWT
AWT JFrame w/ JTabbedPanel, Moving GLCanvas between it's tabs while selecting.
Definition: TestBug816JTabbedPanelVisibilityB849B878AWT.java:65
com.jogamp.opengl.test.junit.jogl.awt.TestBug816JTabbedPanelVisibilityB849B878AWT.test
void test()
Definition: TestBug816JTabbedPanelVisibilityB849B878AWT.java:71
com.jogamp.opengl.test.junit.jogl.awt.TestBug816JTabbedPanelVisibilityB849B878AWT.main
static void main(final String args[])
Definition: TestBug816JTabbedPanelVisibilityB849B878AWT.java:184
com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2
GearsES2.java
Definition: GearsES2.java:65
com.jogamp.opengl.test.junit.util.MiscUtils
Definition: MiscUtils.java:47
com.jogamp.opengl.test.junit.util.MiscUtils.atoi
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
com.jogamp.opengl.test.junit.util.UITestCase
Definition: UITestCase.java:62
com.jogamp.opengl.awt.AWTGLAutoDrawable.setSize
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.