1package com.jogamp.opengl.test.junit.jogl.acore.anim;
3import java.awt.BorderLayout;
4import java.awt.CardLayout;
5import java.awt.Component;
6import java.awt.Dimension;
7import java.awt.event.ItemEvent;
8import java.awt.event.ItemListener;
9import java.awt.event.WindowAdapter;
10import java.awt.event.WindowEvent;
11import java.lang.reflect.InvocationTargetException;
13import com.jogamp.opengl.GLAnimatorControl;
14import com.jogamp.opengl.GLCapabilities;
15import com.jogamp.opengl.GLProfile;
16import com.jogamp.opengl.awt.GLCanvas;
17import javax.swing.JComboBox;
18import javax.swing.JFrame;
19import javax.swing.JLabel;
20import javax.swing.JPanel;
21import javax.swing.WindowConstants;
24import org.junit.FixMethodOrder;
25import org.junit.runners.MethodSorters;
27import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
28import com.jogamp.opengl.test.junit.util.MiscUtils;
29import com.jogamp.opengl.test.junit.util.UITestCase;
30import com.jogamp.opengl.util.Animator;
31import com.jogamp.opengl.util.FPSAnimator;
33@FixMethodOrder(MethodSorters.NAME_ASCENDING)
34@SuppressWarnings({
"unchecked",
"rawtypes" })
36 static final String LABEL =
"Label";
37 static final String CANVAS =
"GLCanvas";
43 static long durationPerTest = 200*4;
44 static boolean manual =
false;
45 static volatile boolean shouldStop =
false;
47 private String selected = LABEL;
79 private static String id(
final Object obj) {
return "0x" + (
null!=obj ? Integer.toHexString(obj.hashCode()) :
"nil" ); }
80 private static String str(
final Component c) {
81 return id(c)+
": "+c.getClass().getSimpleName()+
"[visible "+c.isVisible()+
", showing "+c.isShowing()+
", valid "+c.isValid()+
82 ", displayable "+c.isDisplayable()+
", "+c.getX()+
"/"+c.getY()+
" "+c.getWidth()+
"x"+c.getHeight()+
"]";
84 void testImpl(
final AnimatorControlBehavior animCtrl,
final boolean useFPSAnimator)
throws InterruptedException, InvocationTargetException {
87 final GLCanvas canvas =
new GLCanvas(caps);
88 canvas.setPreferredSize(
new Dimension(640, 480));
90 final GLAnimatorControl animatorCtrl = useFPSAnimator ?
new FPSAnimator(canvas, 60) : new Animator(canvas);
103 canvas.addGLEventListener(
new GearsES2(1));
121 final JFrame frame =
new JFrame();
122 frame.setTitle(getSimpleTestName(
" - "));
123 frame.addWindowListener(
new WindowAdapter() {
125 public void windowClosing(
final WindowEvent e) {
130 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
132 final JLabel label =
new JLabel(
"A label to cover the canvas");
134 final JPanel cards =
new JPanel(
new CardLayout());
135 final JPanel comboBoxPanel =
new JPanel();
136 final JComboBox comboBox =
new JComboBox(
new String[] { LABEL, CANVAS });
137 comboBox.setEditable(
false);
138 comboBox.addItemListener(
new ItemListener() {
140 public void itemStateChanged(
final ItemEvent evt) {
141 final CardLayout cl = (CardLayout)(cards.getLayout());
142 final String newSelection = (String)evt.getItem();
143 if(!newSelection.equals(selected)) {
144 final String oldSelected = selected;
145 if(newSelection.equals(CANVAS)) {
146 System.err.println(
"XXX Card.SHOW Canvas PRE: ");
147 System.err.println(
" CANVAS "+str(canvas));
148 System.err.println(
" LABEL "+str(label));
149 cl.show(cards, CANVAS);
150 System.err.println(
"XXX Card.SHOW Canvas POST: ");
151 System.err.println(
" CANVAS "+str(canvas));
152 System.err.println(
" LABEL "+str(label));
155 animatorCtrl.
start();
163 }
else if(newSelection.equals(LABEL)) {
169 animatorCtrl.
pause();
173 System.err.println(
"XXX Card.SHOW Label PRE: ");
174 System.err.println(
" CANVAS "+str(canvas));
175 System.err.println(
" LABEL "+str(label));
176 cl.show(cards, LABEL);
177 System.err.println(
"XXX Card.SHOW Label POST: ");
178 System.err.println(
" CANVAS "+str(canvas));
179 System.err.println(
" LABEL "+str(label));
182 throw new RuntimeException(
"oops .. unexpected item: "+evt);
184 System.err.println(
"Item Change: "+oldSelected+
" -> "+selected+
", "+animatorCtrl);
186 System.err.println(
"Item Stays: "+selected+
", "+animatorCtrl);
190 comboBoxPanel.add(comboBox);
192 cards.add(label, LABEL);
193 cards.add(canvas, CANVAS);
195 frame.add(comboBoxPanel, BorderLayout.PAGE_START);
196 frame.add(cards, BorderLayout.CENTER);
198 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
202 frame.setVisible(
true);
206 for(
long w=durationPerTest; !shouldStop && w>0; w-=100) {
210 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
213 comboBox.setSelectedItem(LABEL);
215 Thread.sleep(durationPerTest/4);
217 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
220 comboBox.setSelectedItem(CANVAS);
222 Thread.sleep(durationPerTest/4);
224 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
227 comboBox.setSelectedItem(LABEL);
229 Thread.sleep(durationPerTest/4);
231 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
234 comboBox.setSelectedItem(CANVAS);
236 Thread.sleep(durationPerTest/4);
239 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
242 frame.setVisible(
false);
248 public static void main(
final String args[]) {
249 for(
int i=0; i<args.length; i++) {
250 if(args[i].equals(
"-time")) {
251 durationPerTest =
MiscUtils.
atoi(args[++i], (
int)durationPerTest);
252 }
else if(args[i].equals(
"-manual")) {
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
void testFPSAnimatorStartStop()
void testAnimatorStartStop()
void testFPSAnimatorContinue()
static void main(final String args[])
void testAnimatorContinue()
void testFPSAnimatorResumePause()
void testAnimatorResumePause()
static int atoi(final String str, final int def)
void setUpdateFPSFrames(int frames, PrintStream out)
An animator control interface, which implementation may drive a com.jogamp.opengl....
boolean start()
Starts this animator, if not running.
boolean resume()
Resumes animation if paused.
boolean stop()
Stops this animator.
boolean pause()
Pauses this animator.