JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
SWTTestUtil.java
Go to the documentation of this file.
1/**
2 * Copyright 2020 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
29
30package com.jogamp.opengl.test.junit.util;
31
32import org.eclipse.swt.widgets.Display;
33
34import com.jogamp.newt.util.EDTUtil;
35
36public class SWTTestUtil {
37 public static class WaitAction implements Runnable {
38 final Display display;
39 final boolean blocking;
40 final long sleepMS;
41 volatile Exception exo = null;
42
43 public WaitAction(final Display display, final boolean blocking, final long sleepMS) {
44 this.display = display;
45 this.blocking = blocking;
46 this.sleepMS = sleepMS;
47 }
48
49 final Runnable waitAction0 = new Runnable() {
50 @Override
51 public void run() {
52 if( !display.readAndDispatch() ) {
53 try {
54 Thread.sleep(sleepMS);
55 } catch (final InterruptedException e) { }
56 }
57 } };
58
59 @Override
60 public void run() {
61 try {
62 if( blocking ) {
63 display.syncExec( waitAction0 );
64 } else {
65 display.asyncExec( waitAction0 );
66 }
67 } catch (final Exception ex) {
68 ex.printStackTrace();
69 exo = ex;
70 }
71 };
72 public Exception getException(final boolean clear) {
73 final Exception r = exo;
74 if( clear ) {
75 exo = null;
76 }
77 return r;
78 }
79 }
80
81 public static class WaitAction2 implements Runnable {
82 final EDTUtil edt;
83 final Display display;
84 final boolean blocking;
85 final long sleepMS;
86
87 public WaitAction2(final EDTUtil edt, final Display display, final boolean blocking, final long sleepMS) {
88 this.edt = edt;
89 this.display = display;
90 this.blocking = blocking;
91 this.sleepMS = sleepMS;
92 }
93
94 final Runnable waitAction0 = new Runnable() {
95 @Override
96 public void run() {
97 if( !display.readAndDispatch() ) {
98 try {
99 Thread.sleep(sleepMS);
100 } catch (final InterruptedException e) { }
101 }
102 } };
103
104 @Override
105 public void run() {
106 edt.invoke(blocking, waitAction0);
107 };
108 }
109}
110
111
112
WaitAction2(final EDTUtil edt, final Display display, final boolean blocking, final long sleepMS)
WaitAction(final Display display, final boolean blocking, final long sleepMS)
EDT stands for Event Dispatch Thread.
Definition: EDTUtil.java:53
boolean invoke(boolean wait, Runnable task)
Appends task to the EDT task queue if current thread is not EDT, otherwise execute task immediately.