28package com.jogamp.opengl.test.junit.jogl.awt;
30import java.awt.BorderLayout;
31import java.lang.reflect.InvocationTargetException;
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;
42import org.junit.Assert;
43import org.junit.FixMethodOrder;
45import org.junit.runners.MethodSorters;
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;
64@FixMethodOrder(MethodSorters.NAME_ASCENDING)
67 static long durationPerTest = 500*6;
68 static boolean manual =
false;
71 public void test() throws InterruptedException, InvocationTargetException {
72 final JFrame frame =
new JFrame(
"TestBug816OSXCALayerPos03dBug878AWT");
74 final JPanel panel1 =
new javax.swing.JPanel();
75 final JPanel panel2 =
new javax.swing.JPanel();
76 final JPanel panel3 =
new javax.swing.JPanel();
78 panel1.setLayout(
new BorderLayout());
79 panel2.setLayout(
new BorderLayout());
84 glCanvas.
setSize(
new java.awt.Dimension(640, 480));
86 panel1.add(glCanvas, BorderLayout.CENTER);
87 panel3.add(
new JLabel(
"A label to cover the canvas"), BorderLayout.CENTER);
89 final JTabbedPane tabbedPanel =
new JTabbedPane();
90 tabbedPanel.addTab(
"tab1", panel1);
91 tabbedPanel.addTab(
"tab2", panel2);
92 tabbedPanel.addTab(
"tab3", panel3);
94 tabbedPanel.addChangeListener(
new javax.swing.event.ChangeListener() {
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);
108 System.err.println(
"XXXX NOP");
109 dumpGLCanvasStats(glCanvas);
114 frame.setContentPane(tabbedPanel);
115 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
118 System.err.println(
"XXX SetVisible ON XXX GLCanvas on Panel1("+
id(panel1)+
")");
119 frame.setVisible(
true);
121 Assert.assertEquals(
true, AWTRobotUtil.waitForVisible(frame,
true,
null));
122 Assert.assertEquals(
true, AWTRobotUtil.waitForRealized(glCanvas,
true,
null));
123 dumpGLCanvasStats(glCanvas);
126 for(
long w=durationPerTest; w>0; w-=100) {
130 Thread.sleep(durationPerTest/6);
131 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
133 System.err.println(
"XXXX Panel1("+
id(panel1)+
" -> Panel2("+
id(panel2)+
") START");
134 tabbedPanel.setSelectedIndex(1);
137 Thread.sleep(durationPerTest/6);
138 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
140 System.err.println(
"XXXX Panel2("+
id(panel2)+
") -> Panel3("+
id(panel3)+
" START");
141 tabbedPanel.setSelectedIndex(2);
144 Thread.sleep(durationPerTest/6);
145 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
147 System.err.println(
"XXXX Panel3("+
id(panel3)+
") -> Panel1("+
id(panel1)+
" START");
148 tabbedPanel.setSelectedIndex(0);
153 Thread.sleep(durationPerTest/6);
154 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
156 System.err.println(
"XXXX Panel1("+
id(panel1)+
" -> Panel2("+
id(panel2)+
") START");
157 tabbedPanel.setSelectedIndex(1);
160 Thread.sleep(durationPerTest/6);
161 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
163 System.err.println(
"XXXX Panel2("+
id(panel2)+
") -> Panel1("+
id(panel1)+
" START");
164 tabbedPanel.setSelectedIndex(0);
167 Thread.sleep(durationPerTest/6);
170 SwingUtilities.invokeLater(
new Runnable() {
172 System.err.println(
"XXX SetVisible OFF XXX");
177 private static String id(
final Object obj) {
return "0x"+Integer.toHexString(obj.hashCode()); }
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());
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")) {
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
A heavyweight AWT component which provides OpenGL rendering support.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
AWT JFrame w/ JTabbedPanel, Moving GLCanvas between it's tabs while selecting.
static void main(final String args[])
static int atoi(final String str, final int def)
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.