JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug816OSXCALayerPos03cB849AWT.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.Container;
33import java.awt.GridLayout;
34import java.awt.event.ItemEvent;
35import java.awt.event.ItemListener;
36import java.lang.reflect.InvocationTargetException;
37
38import com.jogamp.opengl.GLCapabilities;
39import com.jogamp.opengl.GLProfile;
40import com.jogamp.opengl.awt.GLCanvas;
41import javax.swing.JCheckBox;
42import javax.swing.JFrame;
43import javax.swing.JPanel;
44
45import org.junit.Assert;
46import org.junit.FixMethodOrder;
47import org.junit.Test;
48import org.junit.runners.MethodSorters;
49
50import com.jogamp.newt.event.TraceWindowAdapter;
51import com.jogamp.newt.event.awt.AWTWindowAdapter;
52import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
53import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
54import com.jogamp.opengl.test.junit.util.MiscUtils;
55import com.jogamp.opengl.test.junit.util.QuitAdapter;
56import com.jogamp.opengl.test.junit.util.UITestCase;
57import com.jogamp.opengl.util.Animator;
58
59/**
60 * AWT JFrame BorderLayout w/ Checkbox North, JPanel.GLCanvas Center.
61 * <p>
62 * Checkbox toggles GLCanvas's parent jpanel's visibility state.
63 * </p>
64 * <p>
65 * Validates bugs:
66 * <ul>
67 * <li>Bug 816: OSX CALayer Positioning Bug</li>
68 * <li>Bug 729: OSX CALayer shall honor the Component's visibility state</li>
69 * <li>Bug 849: AWT GLAutoDrawables (JAWTWindow) shall honor it's parent visibility state</li>
70 * </ul>
71 * </p>
72 * <p>
73 * Diff. OSX CALayer positioning w/ java6, [7uxx..7u40[, and >= 7u40
74 * </p>
75 */
76@FixMethodOrder(MethodSorters.NAME_ASCENDING)
78 static long duration = 1600; // ms
79 static int width=640, height=480;
80
81 @Test
82 public void test() throws InterruptedException, InvocationTargetException {
83 final GLCapabilities caps = new GLCapabilities(getGLP());
84
85 final JFrame frame = new JFrame("TestBug816OSXCALayerPos03cAWT");
86 Assert.assertNotNull(frame);
87 final Container framePane = frame.getContentPane();
88
89 final GLCanvas glCanvas1 = new GLCanvas(caps);
90 Assert.assertNotNull(glCanvas1);
91 glCanvas1.addGLEventListener(new GearsES2(1));
92 // Put it in a panel
93 final JPanel panel = new JPanel(new GridLayout(1, 1));
94 panel.add(glCanvas1);
95
96 final Animator animator = new Animator();
97 animator.add(glCanvas1);
98
99 final QuitAdapter quitAdapter = new QuitAdapter();
100 new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas1).addTo(frame);
101
102 // Create a check box that hides / shows canvas
103 final JCheckBox checkbox = new JCheckBox("Visible canvas", true);
104 checkbox.addItemListener(new ItemListener() {
105 public void itemStateChanged(final ItemEvent ev) {
106 final boolean visible = checkbox.getSelectedObjects()!=null;
107 System.err.println("XXXX Panel setVisible "+visible);
108 panel.setVisible(visible);
109 System.err.println("XXXX Visible: [panel "+panel.isVisible()+", canvas "+glCanvas1.isVisible()+"]; Displayable: [panel "+panel.isDisplayable()+", canvas "+glCanvas1.isDisplayable()+"]");
110 if( panel.isVisible() ) {
111 frame.validate(); // take care of resized frame while hidden
112 }
113 }
114 });
115
116 // Build a GUI that displays canvas and check box
117 framePane.setLayout(new BorderLayout());
118 framePane.add(panel, BorderLayout.CENTER);
119 framePane.add(checkbox, BorderLayout.NORTH);
120
121 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
122 public void run() {
123 frame.setSize(width, height);
124 frame.setVisible(true);
125 }});
126 Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true, null));
127 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas1, true, null));
128
129 animator.start();
130 Assert.assertTrue(animator.isStarted());
131 Assert.assertTrue(animator.isAnimating());
132
133 final long t0 = System.currentTimeMillis();
134 long t1 = t0;
135 while(!quitAdapter.shouldQuit() && t1 - t0 < duration) {
136 Thread.sleep(100);
137 t1 = System.currentTimeMillis();
138 }
139
140 Assert.assertNotNull(frame);
141 Assert.assertNotNull(glCanvas1);
142
143 Assert.assertNotNull(animator);
144 animator.stop();
145 Assert.assertFalse(animator.isAnimating());
146 Assert.assertFalse(animator.isStarted());
147
148 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
149 public void run() {
150 frame.setVisible(false);
151 }});
152 Assert.assertEquals(false, frame.isVisible());
153 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
154 public void run() {
155 framePane.remove(panel);
156 frame.dispose();
157 }});
158 }
159
160 static GLProfile getGLP() {
162 }
163
164 public static void main(final String args[]) {
165 for(int i=0; i<args.length; i++) {
166 if(args[i].equals("-time")) {
167 i++;
168 duration = MiscUtils.atol(args[i], duration);
169 }
170 }
171
172 org.junit.runner.JUnitCore.main(TestBug816OSXCALayerPos03cB849AWT.class.getName());
173 }
174}
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 JFrame BorderLayout w/ Checkbox North, JPanel.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