29package com.jogamp.opengl.test.junit.jogl.acore;
31import java.awt.AWTException;
32import java.awt.BorderLayout;
33import java.awt.Component;
34import java.awt.Container;
35import java.awt.Dimension;
38import java.awt.Window;
39import java.lang.reflect.InvocationTargetException;
40import java.util.Locale;
42import javax.swing.AbstractButton;
43import javax.swing.JDialog;
44import javax.swing.JFileChooser;
45import javax.swing.JPanel;
46import javax.swing.SwingUtilities;
47import javax.swing.UIManager;
49import org.junit.Assert;
50import org.junit.FixMethodOrder;
52import org.junit.runners.MethodSorters;
54import com.jogamp.common.os.Platform;
55import com.jogamp.common.util.InterruptSource;
56import com.jogamp.opengl.GLCapabilities;
57import com.jogamp.opengl.GLCapabilitiesImmutable;
58import com.jogamp.opengl.GLProfile;
59import com.jogamp.opengl.awt.GLCanvas;
60import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
61import com.jogamp.opengl.test.junit.util.DumpGLInfo;
62import com.jogamp.opengl.test.junit.util.GLClearColor;
63import com.jogamp.opengl.test.junit.util.GLEventListenerCounter;
64import com.jogamp.opengl.test.junit.util.UITestCase;
66@FixMethodOrder(MethodSorters.NAME_ASCENDING)
68 static final int NB_TEST = 5;
69 static final int ACTION_DELAY = 500;
70 static final int MOVE_DELAY = 2;
71 static final int MOVE_ITER = 100;
72 static final int TOOLTIP_WAIT = 3*1000;
74 static AbstractButton findButton(
final int depth,
final Container c,
final String buttonText) {
75 AbstractButton res =
null;
76 final int cc = c.getComponentCount();
77 for(
int i=0;
null==res && i<cc; i++) {
78 final Component e = c.getComponent(i);
80 if( e instanceof AbstractButton ) {
81 final AbstractButton b = (AbstractButton) e;
82 final String bT = b.getText();
83 if( buttonText.equals(bT) ) {
86 }
else if( e instanceof Container ) {
87 res = findButton(depth+1, (Container)e, buttonText);
95 final JDialog dialog =
new JDialog((
Window)
null);
96 dialog.setMinimumSize(
new Dimension(500, 300));
97 dialog.setPreferredSize(
new Dimension(500, 300));
99 dialog.setModal(
false);
107 final JPanel panel1 =
new JPanel(
new BorderLayout());
108 panel1.add(canvas1, BorderLayout.CENTER);
109 panel1.setPreferredSize(
new Dimension(300, 300));
116 final JPanel panel2 =
new JPanel(
new BorderLayout());
117 panel2.add(canvas2, BorderLayout.CENTER);
118 panel2.setPreferredSize(
new Dimension(300, 300));
121 final JFileChooser fileChooser =
new JFileChooser();
122 final String approveButtonText =
"Approved";
123 fileChooser.setApproveButtonText(approveButtonText);
124 fileChooser.setApproveButtonToolTipText(
"Tool-Tip for Approved");
125 fileChooser.setAccessory(panel1);
127 final Locale l = fileChooser.getLocale();
128 final String cancelButtonText = UIManager.getString(
"FileChooser.cancelButtonText",l);
131 new InterruptSource.Thread()
139 final Point approveButtonPos;
140 final AbstractButton approveButton = findButton(0, fileChooser, approveButtonText);
141 if(
null != approveButton ) {
142 approveButtonPos = approveButton.getLocationOnScreen();
143 final Dimension approveButtonSize = approveButton.getSize();
144 approveButtonPos.translate(approveButtonSize.width/2, approveButtonSize.height/2);
145 System.err.println(
"OK Button: "+approveButton.getClass().getSimpleName()+
"; "+approveButton+
", "+approveButtonPos);
147 System.err.println(
"OK Button: NULL");
148 approveButtonPos =
null;
150 final Point cancelButtonPos;
151 final AbstractButton cancelButton = findButton(0, fileChooser, cancelButtonText);
152 if(
null != approveButton ) {
153 cancelButtonPos = cancelButton.getLocationOnScreen();
154 final Dimension cancelButtonSize = cancelButton.getSize();
155 cancelButtonPos.translate(cancelButtonSize.width/2, cancelButtonSize.height/2);
156 System.err.println(
"CANCEL Button: "+cancelButton.getClass().getSimpleName()+
"; "+cancelButton+
", "+cancelButtonPos);
158 cancelButtonPos =
null;
159 System.err.println(
"CANCEL Button: NULL");
161 final Robot robot =
new Robot();
163 if(
null != approveButtonPos ) {
165 java.lang.Thread.sleep(TOOLTIP_WAIT);
167 SwingUtilities.invokeAndWait(
new Runnable() {
169 fileChooser.setAccessory(panel2);
170 fileChooser.validate();
172 }
catch (
final InterruptedException e) {
174 }
catch (
final InvocationTargetException e) {
179 if(
null != cancelButtonPos ) {
183 fileChooser.cancelSelection();
185 }
catch (
final AWTException e1) {
186 e1.printStackTrace();
187 }
catch (
final InterruptedException e2) {
188 e2.printStackTrace();
195 SwingUtilities.invokeAndWait(
new Runnable() {
197 dialog.setVisible(
true);
198 fileChooser.showOpenDialog(dialog);
200 }
catch (
final InterruptedException e) {
202 }
catch (
final InvocationTargetException e) {
208 SwingUtilities.invokeAndWait(
new Runnable() {
212 dialog.setVisible(
false);
215 }
catch (
final InterruptedException e) {
217 }
catch (
final InvocationTargetException e) {
221 Assert.assertEquals(1, glelc1.
initCount);
222 Assert.assertEquals(1, glelc2.
initCount);
226 @Test(timeout=180000)
227 public
void test01() {
229 for (
int i = 0; i < NB_TEST; i++) {
230 System.out.println(
"Iteration " + i +
" / " + NB_TEST);
235 public static void main(
final String[] pArgs)
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
A heavyweight AWT component which provides OpenGL rendering support.
void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext....
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
static void main(final String[] pArgs)
static void mouseMove(final Robot robot, final Point destination, final int iter, final int delay)
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 void mouseClick(final Robot robot, final Point pos, final int moveIter, final int moveDelay, final int actionDelay)
Specifying NEWT's Window functionality:
Specifies an immutable set of OpenGL capabilities.