JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug816OSXCALayerPos02AWT.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 com.jogamp.opengl.*;
32
33import com.jogamp.opengl.util.Animator;
34
35import com.jogamp.opengl.awt.GLCanvas;
36import javax.swing.JFrame;
37import javax.swing.JRootPane;
38import javax.swing.JScrollPane;
39import javax.swing.JSplitPane;
40
41import com.jogamp.newt.event.awt.AWTWindowAdapter;
42import com.jogamp.newt.event.TraceWindowAdapter;
43import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
44import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
45import com.jogamp.opengl.test.junit.util.MiscUtils;
46import com.jogamp.opengl.test.junit.util.UITestCase;
47import com.jogamp.opengl.test.junit.util.QuitAdapter;
48
49import java.lang.reflect.InvocationTargetException;
50
51import org.junit.Assert;
52import org.junit.Test;
53import org.junit.FixMethodOrder;
54import org.junit.runners.MethodSorters;
55
56/**
57 * Bug 816: OSX CALayer Positioning Bug - Swing JFrame w/ 2 JRootPanes and 2 JSplitPanes
58 * <p>
59 * Diff. OSX CALayer positioning w/ java6, [7uxx..7u40[, and >= 7u40
60 * </p>
61 * <p>
62 * See also {@link com.jogamp.opengl.test.junit.jogl.demos.es2.awt.Bug816AppletOSXCALayerPos03b}
63 * </p>
64 */
65@FixMethodOrder(MethodSorters.NAME_ASCENDING)
67 static long duration = 1600; // ms
68 static int width=640, height=480;
69
70 @Test
71 public void test() throws InterruptedException, InvocationTargetException {
72 final GLCapabilities caps = new GLCapabilities(getGLP());
73
74 final JFrame frame = new JFrame("TestBug816OSXCALayerPos02AWT");
75 Assert.assertNotNull(frame);
76
77 final GLCanvas glCanvas1 = new GLCanvas(caps);
78 Assert.assertNotNull(glCanvas1);
79 glCanvas1.addGLEventListener(new GearsES2(1));
80
81 final Animator animator = new Animator();
82 animator.add(glCanvas1);
83
84 final QuitAdapter quitAdapter = new QuitAdapter();
85 new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas1).addTo(frame);
86
87 // Build a GUI where the canvas 3D is located at top right of the frame
88 // and can be resized with split panes dividers
89 final JSplitPane verticalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
90 true, new JScrollPane(), glCanvas1);
91 verticalSplitPane.setResizeWeight(0.5);
92 final JSplitPane horizontalSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
93 true, new JScrollPane(), verticalSplitPane);
94 horizontalSplitPane.setResizeWeight(0.5);
95 final JRootPane intermediateRootPane = new JRootPane();
96 intermediateRootPane.setContentPane(horizontalSplitPane);
97 frame.add(intermediateRootPane);
98
99 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
100 public void run() {
101 frame.setSize(width, height);
102 frame.setVisible(true);
103 }});
104 Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true, null));
105 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas1, true, null));
106
107 animator.start();
108 Assert.assertTrue(animator.isStarted());
109 Assert.assertTrue(animator.isAnimating());
110
111 final long t0 = System.currentTimeMillis();
112 long t1 = t0;
113 while(!quitAdapter.shouldQuit() && t1 - t0 < duration) {
114 Thread.sleep(100);
115 t1 = System.currentTimeMillis();
116 }
117
118 Assert.assertNotNull(frame);
119 Assert.assertNotNull(glCanvas1);
120
121 Assert.assertNotNull(animator);
122 animator.stop();
123 Assert.assertFalse(animator.isAnimating());
124 Assert.assertFalse(animator.isStarted());
125
126 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
127 public void run() {
128 frame.setVisible(false);
129 }});
130 Assert.assertEquals(false, frame.isVisible());
131 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
132 public void run() {
133 frame.remove(glCanvas1);
134 frame.dispose();
135 }});
136 }
137
138 static GLProfile getGLP() {
140 }
141
142 public static void main(final String args[]) {
143 for(int i=0; i<args.length; i++) {
144 if(args[i].equals("-time")) {
145 i++;
146 duration = MiscUtils.atol(args[i], duration);
147 }
148 }
149
150 org.junit.runner.JUnitCore.main(TestBug816OSXCALayerPos02AWT.class.getName());
151 }
152}
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
Bug 816: OSX CALayer Positioning Bug - Swing JFrame w/ 2 JRootPanes and 2 JSplitPanes.
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