28package com.jogamp.opengl.test.junit.jogl.awt;
30import java.awt.BorderLayout;
31import java.awt.Dimension;
32import java.awt.GridLayout;
33import java.lang.reflect.InvocationTargetException;
35import javax.swing.JFrame;
36import javax.swing.JPanel;
37import javax.swing.JTabbedPane;
38import javax.swing.SwingUtilities;
39import javax.swing.UIManager;
41import org.junit.Assert;
42import org.junit.BeforeClass;
43import org.junit.FixMethodOrder;
45import org.junit.runners.MethodSorters;
47import com.jogamp.opengl.GLEventListener;
48import com.jogamp.opengl.GLProfile;
49import com.jogamp.opengl.awt.GLCanvas;
50import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
51import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
52import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
53import com.jogamp.opengl.test.junit.util.GLEventListenerCounter;
54import com.jogamp.opengl.test.junit.util.MiscUtils;
55import com.jogamp.opengl.test.junit.util.UITestCase;
56import com.jogamp.opengl.util.Animator;
64@FixMethodOrder(MethodSorters.NAME_ASCENDING)
67 static long durationPerTest = 500*4;
68 static boolean manual =
false;
70 @SuppressWarnings(
"serial")
71 static class View3D
extends JPanel {
76 public View3D(
final int num) {
78 this.setLayout(
new BorderLayout());
80 canvas.
setSize(
new Dimension(100, 100));
81 canvas.setMinimumSize(
new Dimension(100, 100));
82 add(canvas, BorderLayout.CENTER);
89 public void addNotify() {
90 System.err.println(
"View3D["+num+
"].addNotify()");
92 if(
null != animator ) {
97 public void removeNotify() {
98 System.err.println(
"View3D["+num+
"].removeNotify()");
99 if(
null != animator ) {
102 super.removeNotify();
105 public String getGLCanvasStats() {
106 return "GLCanvas: comp "+canvas.getBounds()+
", visible "+canvas.isVisible()+
", showing "+canvas.isShowing()+
114 private JTabbedPane createAndShowGUI(
final JFrame frame,
final View3D[] views) {
115 final JPanel panel =
new JPanel(
new GridLayout(1, 1));
116 final JTabbedPane tabbedPanel =
new JTabbedPane();
117 for(
int i=0; i<views.length; i++) {
128 views[i] =
new View3D(i);
129 views[i].canvas.addGLEventListener(glelCounter);
130 views[i].canvas.addGLEventListener(demo);
131 tabbedPanel.addTab(
"Tab "+i,
null, views[i],
"Does nothing");
133 tabbedPanel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
134 tabbedPanel.addChangeListener(
new javax.swing.event.ChangeListener() {
136 public void stateChanged(final javax.swing.event.ChangeEvent evt) {
137 final int idx = tabbedPanel.getSelectedIndex();
138 if( 0 <= idx && idx < views.length ) {
139 System.err.println(
"Pane["+idx+
"]: State Changed: "+evt);
140 System.err.println(
"Pane["+idx+
"]: "+views[idx].getGLCanvasStats());
145 panel.add(tabbedPanel);
146 frame.add(panel, BorderLayout.CENTER);
147 frame.setSize(640,480);
152 private static String id(
final Object obj) {
return "0x"+Integer.toHexString(obj.hashCode()); }
160 public void test01() throws InterruptedException, InvocationTargetException {
161 final JFrame frame =
new JFrame(
"Java3DApplication");
162 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
164 final View3D[] views =
new View3D[4];
165 final JTabbedPane[] tabbedPane = {
null };
166 SwingUtilities.invokeLater(
new Runnable() {
170 UIManager.put(
"swing.boldMetal", Boolean.FALSE);
171 tabbedPane[0] = createAndShowGUI(frame, views);
172 System.err.println(
"XXX SetVisible ON XXX");
173 frame.setVisible(
true);
176 for(
int i=0; i<views.length; i++) {
177 System.err.printf(
"View "+i+
": "+views[i]+
",%n "+views[i].getGLCanvasStats()+
"%n%n");
180 System.err.println(
"XXX POST.VISIBLE: "+glelCounter);
182 Thread.sleep(durationPerTest);
183 System.err.println(
"XXX POST.ACTION: "+glelCounter);
185 final JTabbedPane tabbedPanel = tabbedPane[0];
187 for(
int i=0; i<views.length; i++) {
188 Thread.sleep(durationPerTest/views.length);
189 switchTab(tabbedPanel, views, i, (i+1)%views.length);
191 Thread.sleep(durationPerTest/views.length);
192 switchTab(tabbedPanel, views, 0, 1);
194 Thread.sleep(durationPerTest/views.length);
195 switchTab(tabbedPanel, views, 1, 0);
197 System.err.println(
"XXX POST.ACTION: "+glelCounter);
198 Assert.assertTrue(glelCounter.initCount >= views.length);
201 SwingUtilities.invokeLater(
new Runnable() {
203 System.err.println(
"XXX SetVisible OFF XXX");
207 System.err.println(
"XXX POST.DISPOSE: "+glelCounter);
210 void switchTab(
final JTabbedPane tabbedPanel,
final View3D[] views,
final int thisId,
final int nextId)
throws InvocationTargetException, InterruptedException {
211 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
213 System.err.println(
"XXXX Panel("+
id(views[thisId])+
" -> Panel("+
id(views[nextId])+
") START");
214 tabbedPanel.setSelectedIndex(nextId);
218 public static void main(
final String args[]) {
219 for(
int i=0; i<args.length; i++) {
220 if(args[i].equals(
"-time")) {
221 durationPerTest =
MiscUtils.
atoi(args[++i], (
int)durationPerTest);
222 }
else if(args[i].equals(
"-manual")) {
Specifies the the OpenGL profile.
static void initSingleton()
Static initialization of JOGL.
A heavyweight AWT component which provides OpenGL rendering support.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
long getHandle()
Returns the GL drawable handle, guaranteed to be valid after realization and while it's surface is be...
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
static void main(final String args[])
GearsES2 setVerbose(final boolean v)
RedSquareES2 setVerbose(final boolean v)
static boolean waitForVisible(final java.awt.Component comp, final boolean visible, final Runnable waitAction)
static int atoi(final String str, final int def)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.