JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLJPanelResize01AWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2013-2023 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.Dimension;
31import java.lang.reflect.InvocationTargetException;
32
33import com.jogamp.opengl.GLCapabilities;
34import com.jogamp.opengl.GLCapabilitiesImmutable;
35import com.jogamp.opengl.GLProfile;
36import com.jogamp.opengl.awt.GLJPanel;
37import javax.swing.JFrame;
38import javax.swing.JPanel;
39import javax.swing.SwingUtilities;
40
41import org.junit.Assume;
42import org.junit.BeforeClass;
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.MiscUtils;
49import com.jogamp.opengl.test.junit.util.UITestCase;
50
51/**
52 * Multiple GLJPanels in a JFrame
53 */
54@FixMethodOrder(MethodSorters.NAME_ASCENDING)
55public class TestGLJPanelResize01AWT extends UITestCase {
56
57 @BeforeClass
58 public static void initClass() {
60 }
61
62 static Dimension[] esize00 = {
63 new Dimension(281, 151),
64 new Dimension(282, 151),
65 new Dimension(283, 151),
66 new Dimension(284, 151),
67
68 new Dimension(284, 152),
69 new Dimension(283, 152),
70 new Dimension(282, 152),
71 new Dimension(281, 152),
72
73 new Dimension(291, 153),
74 new Dimension(292, 153),
75 new Dimension(293, 153),
76 new Dimension(294, 153),
77
78 new Dimension(281, 154),
79 new Dimension(282, 154),
80 new Dimension(283, 154),
81 new Dimension(284, 154)
82 };
83 static Dimension[] esize01 = {
84 new Dimension(283, 154), // #3: new sub-aligned image in pixelBuffer-1
85 new Dimension(291, 154), // #2: new pixelBuffer-1
86 new Dimension(282, 154), // #1: new pixelBuffer-0
87 };
88 static Dimension[] esize02 = {
89 new Dimension(291, 154), // #2: new pixelBuffer-1
90 new Dimension(282, 154), // #1: new pixelBuffer-0
91 };
92
93 public void test(final GLCapabilitiesImmutable caps, final Dimension[] dims, final boolean useSwingDoubleBuffer) {
94 final int cols = 4;
95 final int rows = dims.length / cols + ( dims.length % cols > 0 ? 1 : 0 );
96 final JFrame[] frame = new JFrame[] { null };
97
98 System.err.println("Frame size: cols x rows "+cols+"x"+rows);
99 try {
100 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
101 @Override
102 public void run() {
103 frame[0] = new JFrame();
104 frame[0].setLocation(64, 64);
105 final JPanel panel = new JPanel();
106 panel.setLayout(null); // new BorderLayout());
107 panel.setDoubleBuffered(useSwingDoubleBuffer);
108 frame[0].getContentPane().add(panel);
109
110 final int x0 = 4;
111 int x = x0, y = 4;
112 int maxRowWidth = 0;
113 for(int i=0; i<rows; i++) {
114 int maxColHeight = 0;
115 for(int j=0; j<cols; j++) {
116 final int idx = i*cols+j;
117 if( idx >= dims.length ) { break; }
118 final Dimension d = dims[idx];
119 if( d.height > maxColHeight ) {
120 maxColHeight = d.height;
121 }
122 final GLJPanel glad = createGLJPanel(useSwingDoubleBuffer, caps, d, "[r "+i+", c "+j+"]");
123 panel.add(glad);
124 glad.setLocation(x, y);
125 x+=d.width+4;
126 }
127 if( x > maxRowWidth ) {
128 maxRowWidth = x;
129 }
130 x = x0;
131 y += maxColHeight+4;
132 }
133 frame[0].setSize(maxRowWidth+4+64, y+4+64);
134 // frame[0].pack();
135 frame[0].setVisible(true);
136 } } );
137 } catch( final Throwable throwable ) {
138 throwable.printStackTrace();
139 Assume.assumeNoException( throwable );
140 }
141 try {
142 Thread.sleep(duration);
143 } catch (final InterruptedException e1) {
144 e1.printStackTrace();
145 }
146 try {
147 SwingUtilities.invokeAndWait(new Runnable() {
148 @Override
149 public void run() {
150 frame[0].dispose();
151 } } );
152 } catch (final Exception e1) {
153 e1.printStackTrace();
154 }
155 }
156
157 private GLJPanel createGLJPanel(final boolean useSwingDoubleBuffer, final GLCapabilitiesImmutable caps, final Dimension size, final String name) {
158 final GLJPanel canvas = new GLJPanel(caps);
159 canvas.setName(name);
160 canvas.setSize(size);
161 canvas.setPreferredSize(size);
162 canvas.setMinimumSize(size);
163 canvas.setDoubleBuffered(useSwingDoubleBuffer);
164 final GearsES2 g = new GearsES2(0);
165 // g.setVerbose(false);
166 canvas.addGLEventListener(g);
167 return canvas;
168 }
169
170 static GLCapabilitiesImmutable caps = null;
171
172 // @Test
173 public void test00() throws InterruptedException, InvocationTargetException {
174 test(new GLCapabilities(null), esize00, false /*useSwingDoubleBuffer*/);
175 }
176
177 @Test
178 public void test01() throws InterruptedException, InvocationTargetException {
179 test(new GLCapabilities(null), esize01, false /*useSwingDoubleBuffer*/);
180 }
181
182 @Test
183 public void test02() throws InterruptedException, InvocationTargetException {
184 test(new GLCapabilities(null), esize02, false /*useSwingDoubleBuffer*/);
185 }
186
187 static long duration = 600; // ms
188
189 public static void main(final String[] args) {
190 boolean useSwingDoubleBuffer=false, manual=false;
191
192 for(int i=0; i<args.length; i++) {
193 if(args[i].equals("-time")) {
194 i++;
195 duration = MiscUtils.atol(args[i], duration);
196 } else if(args[i].equals("-swingDoubleBuffer")) {
197 useSwingDoubleBuffer = true;
198 } else if(args[i].equals("-manual")) {
199 manual = true;
200 }
201 }
202 if( manual ) {
205 demo.test(new GLCapabilities(null), esize01, useSwingDoubleBuffer);
206 } else {
207 org.junit.runner.JUnitCore.main(TestGLJPanelResize01AWT.class.getName());
208 }
209 }
210
211}
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static void initSingleton()
Static initialization of JOGL.
Definition: GLProfile.java:204
A lightweight Swing component which provides OpenGL rendering support.
Definition: GLJPanel.java:189
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLJPanel.java:989
void test(final GLCapabilitiesImmutable caps, final Dimension[] dims, final boolean useSwingDoubleBuffer)
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
Specifies an immutable set of OpenGL capabilities.
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.