JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug1146GLContextDialogToolTipAWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2015 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 */
28
29package com.jogamp.opengl.test.junit.jogl.acore;
30
31import java.awt.AWTException;
32import java.awt.BorderLayout;
33import java.awt.Component;
34import java.awt.Container;
35import java.awt.Dimension;
36import java.awt.Point;
37import java.awt.Robot;
38import java.awt.Window;
39import java.lang.reflect.InvocationTargetException;
40import java.util.Locale;
41
42import javax.swing.AbstractButton;
43import javax.swing.JDialog;
44import javax.swing.JFileChooser;
45import javax.swing.JPanel;
46import javax.swing.SwingUtilities;
47import javax.swing.UIManager;
48
49import org.junit.Assert;
50import org.junit.FixMethodOrder;
51import org.junit.Test;
52import org.junit.runners.MethodSorters;
53
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;
65
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; // 5s
73
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);
79 // System.err.println("["+depth+"]["+i+"]: "+e.getClass().getSimpleName()+": "+e);
80 if( e instanceof AbstractButton ) {
81 final AbstractButton b = (AbstractButton) e;
82 final String bT = b.getText();
83 if( buttonText.equals(bT) ) {
84 res = b;
85 }
86 } else if( e instanceof Container ) {
87 res = findButton(depth+1, (Container)e, buttonText);
88 }
89 }
90 return res;
91 }
92
93 private void oneTest(final GLCapabilitiesImmutable caps) {
94 // base dialog
95 final JDialog dialog = new JDialog((Window) null);
96 dialog.setMinimumSize(new Dimension(500, 300));
97 dialog.setPreferredSize(new Dimension(500, 300));
98
99 dialog.setModal(false);
100
101 // build accessory
103 final GLCanvas canvas1 = new GLCanvas(caps);
104 canvas1.addGLEventListener(new DumpGLInfo(Platform.getNewline()+Platform.getNewline()+"Pre-ToolTip", false, false, false));
105 canvas1.addGLEventListener(new GLClearColor(1f, 0f, 0f, 1f));
106 canvas1.addGLEventListener(glelc1);
107 final JPanel panel1 = new JPanel(new BorderLayout());
108 panel1.add(canvas1, BorderLayout.CENTER);
109 panel1.setPreferredSize(new Dimension(300, 300));
110
112 final GLCanvas canvas2 = new GLCanvas(caps);
113 canvas2.addGLEventListener(new DumpGLInfo(Platform.getNewline()+Platform.getNewline()+"Post-ToolTip", false, false, false));
114 canvas2.addGLEventListener(new GLClearColor(0f, 0f, 1f, 1f));
115 canvas2.addGLEventListener(glelc2);
116 final JPanel panel2 = new JPanel(new BorderLayout());
117 panel2.add(canvas2, BorderLayout.CENTER);
118 panel2.setPreferredSize(new Dimension(300, 300));
119
120 // create file chooser with accessory
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);
126
127 final Locale l = fileChooser.getLocale();
128 final String cancelButtonText = UIManager.getString("FileChooser.cancelButtonText",l);
129
130 // launch robot action ..
131 new InterruptSource.Thread()
132 {
133 public void run()
134 {
135 try {
136 Assert.assertEquals(true, AWTRobotUtil.waitForVisible(fileChooser, true, null));
137 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(canvas1, true, null));
138
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);
146 } else {
147 System.err.println("OK Button: NULL");
148 approveButtonPos = null;
149 }
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);
157 } else {
158 cancelButtonPos = null;
159 System.err.println("CANCEL Button: NULL");
160 }
161 final Robot robot = new Robot();
162 // hover to 'approve' -> tool tip
163 if( null != approveButtonPos ) {
164 AWTRobotUtil.mouseMove(robot, approveButtonPos, MOVE_ITER, MOVE_DELAY);
165 java.lang.Thread.sleep(TOOLTIP_WAIT);
166 try {
167 SwingUtilities.invokeAndWait(new Runnable() {
168 public void run() {
169 fileChooser.setAccessory(panel2);
170 fileChooser.validate();
171 } } ) ;
172 } catch (final InterruptedException e) {
173 e.printStackTrace();
174 } catch (final InvocationTargetException e) {
175 e.printStackTrace();
176 }
177 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(canvas2, true, null));
178 }
179 if( null != cancelButtonPos ) {
180 AWTRobotUtil.mouseClick(robot, cancelButtonPos, MOVE_ITER, MOVE_DELAY, ACTION_DELAY);
181 } else {
182 // oops ..
183 fileChooser.cancelSelection();
184 }
185 } catch (final AWTException e1) {
186 e1.printStackTrace();
187 } catch (final InterruptedException e2) {
188 e2.printStackTrace();
189 }
190 }
191 }.start();
192
193 // show file chooser dialog
194 try {
195 SwingUtilities.invokeAndWait(new Runnable() {
196 public void run() {
197 dialog.setVisible(true);
198 fileChooser.showOpenDialog(dialog);
199 } } ) ;
200 } catch (final InterruptedException e) {
201 e.printStackTrace();
202 } catch (final InvocationTargetException e) {
203 e.printStackTrace();
204 }
205
206 // dispose of resources
207 try {
208 SwingUtilities.invokeAndWait(new Runnable() {
209 public void run() {
210 canvas1.destroy();
211 canvas2.destroy();
212 dialog.setVisible(false);
213 dialog.dispose();
214 } } ) ;
215 } catch (final InterruptedException e) {
216 e.printStackTrace();
217 } catch (final InvocationTargetException e) {
218 e.printStackTrace();
219 }
220
221 Assert.assertEquals(1, glelc1.initCount);
222 Assert.assertEquals(1, glelc2.initCount);
223 }
224
225
226 @Test(timeout=180000) // TO 3 min
227 public void test01() {
229 for (int i = 0; i < NB_TEST; i++) {
230 System.out.println("Iteration " + i + " / " + NB_TEST);
231 oneTest(caps);
232 }
233 }
234
235 public static void main(final String[] pArgs)
236 {
237 org.junit.runner.JUnitCore.main(TestBug1146GLContextDialogToolTipAWT.class.getName());
238 }
239}
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext....
Definition: GLCanvas.java:521
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
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:
Definition: Window.java:115
Specifies an immutable set of OpenGL capabilities.