JOGL: src/test/com/jogamp/opengl/test/junit/newt/event/TestNewtEventModifiersNewtCanvasSWTAWT.java Source File

JOGL v2.6.0 JOGL, High-Performance Graphics Binding for Java™ (public API).

TestNewtEventModifiersNewtCanvasSWTAWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 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.newt.event;
30
31import org.eclipse.swt.SWT ;
32import org.eclipse.swt.layout.FillLayout ;
33import org.eclipse.swt.widgets.Composite;
34import org.eclipse.swt.widgets.Display ;
35import org.eclipse.swt.widgets.Shell ;
36
37import com.jogamp.opengl.GLCapabilities ;
38import com.jogamp.opengl.GLProfile ;
39
40import org.junit.AfterClass ;
41import org.junit.Assert;
42import org.junit.Assume;
43import org.junit.BeforeClass ;
44import org.junit.FixMethodOrder;
45import org.junit.runners.MethodSorters;
46
47import com.jogamp.nativewindow.swt.SWTAccessor;
48import com.jogamp.newt.opengl.GLWindow ;
49import com.jogamp.newt.swt.NewtCanvasSWT ;
50import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
51import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
52
53/**
54 * Test whether or not event modifiers preserved by NEWT when
55 * the canvas is a NewtCanvasSWT.
56 */
57@FixMethodOrder(MethodSorters.NAME_ASCENDING)
58public class TestNewtEventModifiersNewtCanvasSWTAWT extends BaseNewtEventModifiers {
59
60 private static Display _display = null;
61 private static Shell _shell = null;
62 private static Composite _composite = null;
63 private static GLWindow _glWindow ;
64
65 ////////////////////////////////////////////////////////////////////////////
66
67 protected static void eventDispatchImpl() {
68 final int maxEvents = 10;
69 final boolean[] res = { false };
70 int i=0;
71 do {
72 SWTAccessor.invokeOnSWTThread(_display, true, new Runnable() {
73 @Override
74 public void run() {
75 if( !_display.isDisposed() ) {
76 if( !_display.readAndDispatch() ) {
77 res[0] = false;
78 try {
79 Thread.sleep(100);
80 } catch (final InterruptedException e) { }
81 } else {
82 res[0] = true;
83 }
84 } else {
85 res[0] = false;
86 }
87 }});
88 i++;
89 } while( i<maxEvents && res[0] );
90 }
91
92 @Override
93 protected void eventDispatch() {
94 eventDispatchImpl();
95 }
96
97 ////////////////////////////////////////////////////////////////////////////
98
99 @BeforeClass
100 public static void beforeClass() throws Exception {
101
102 SWTAccessor.initSingleton();
103 BaseNewtEventModifiers.baseBeforeClass();
104
105 // FIXME: Hangs .. w/ Java7 .. every now and then!
106 // FIXME: Implementation must still be overhauled
107 setTestSupported(false);
108
109 SWTAccessor.invokeOnOSTKThread(true, new Runnable() {
110 @Override
111 public void run() {
112 _display = new Display();
113 }});
114 Assert.assertNotNull( _display );
115
116 SWTAccessor.invokeOnSWTThread(_display, true, new Runnable() {
117 @Override
118 public void run() {
119 _shell = new Shell( _display );
120 Assert.assertNotNull( _shell );
121 _shell.setText( "Event Modifier Test NewtCanvasSWT" ) ;
122 _shell.setLayout( new FillLayout() );
123 _composite = new Composite( _shell, SWT.NONE );
124 _composite.setLayout( new FillLayout() );
125 Assert.assertNotNull( _composite );
126 }});
127
128 {
129 final GLCapabilities caps = new GLCapabilities( GLProfile.get( GLProfile.GL2ES2 ) ) ;
130 _glWindow = GLWindow.create( caps ) ;
131 _glWindow.addGLEventListener( new RedSquareES2() ) ;
132
133 NewtCanvasSWT.create( _composite, SWT.NO_BACKGROUND, _glWindow ) ;
134 }
135
136 SWTAccessor.invokeOnSWTThread(_display, true, new Runnable() {
137 @Override
138 public void run() {
139 _shell.setBounds( TEST_FRAME_X, TEST_FRAME_Y, TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT ) ;
140 _shell.open();
141 }
142 });
143
144 // no AWT idling, may deadlock on OSX!
145 Assert.assertNotNull(_robot);
146 _robot.setAutoWaitForIdle( false ) ;
147
148 // no waiting for results ..
149 AWTRobotUtil.requestFocus(null, _glWindow, false); // programmatic
150 eventDispatchImpl();
151 AWTRobotUtil.requestFocus(_robot, _glWindow, INITIAL_MOUSE_X, INITIAL_MOUSE_Y);
152 eventDispatchImpl();
153
154 _glWindow.addMouseListener( _testMouseListener ) ;
155 }
156
157 ////////////////////////////////////////////////////////////////////////////
158
159 @AfterClass
160 public static void afterClass() throws Exception {
161 _glWindow.destroy() ;
162
163 try {
164 SWTAccessor.invokeOnSWTThread(_display, true, new Runnable() {
165 @Override
166 public void run() {
167 if( null != _composite ) {
168 _composite.dispose();
169 }
170 if( null != _shell ) {
171 _shell.dispose();
172 }
173 }});
174 SWTAccessor.invokeOnOSTKThread(true, new Runnable() {
175 @Override
176 public void run() {
177 if( null != _display && !_display.isDisposed()) {
178 _display.dispose();
179 }
180 }});
181 }
182 catch( final Throwable throwable ) {
183 throwable.printStackTrace();
184 Assume.assumeNoException( throwable );
185 }
186 }
187
188 ////////////////////////////////////////////////////////////////////////////
189
190 public static void main(final String args[]) throws Exception {
191 final String testName = TestNewtEventModifiersNewtCanvasSWTAWT.class.getName() ;
192 org.junit.runner.JUnitCore.main( testName ) ;
193 }
194
195 ////////////////////////////////////////////////////////////////////////////
196}
com.jogamp.nativewindow.swt.SWTAccessor
Definition: SWTAccessor.java:62
com.jogamp.nativewindow.swt.SWTAccessor.invokeOnOSTKThread
static void invokeOnOSTKThread(final boolean blocking, final Runnable runnable)
Runs the specified action in an SWT compatible OS toolkit thread, which is:
Definition: SWTAccessor.java:807
com.jogamp.nativewindow.swt.SWTAccessor.initSingleton
static void initSingleton()
Call this method, if this class shall be initialized before any other of its methods are called withi...
Definition: SWTAccessor.java:326
com.jogamp.nativewindow.swt.SWTAccessor.invokeOnSWTThread
static void invokeOnSWTThread(final org.eclipse.swt.widgets.Display display, final boolean blocking, final Runnable runnable)
Runs the specified action on the SWT UI thread.
Definition: SWTAccessor.java:826
com.jogamp.newt.opengl.GLWindow
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
com.jogamp.newt.opengl.GLWindow.addMouseListener
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
Definition: GLWindow.java:927
com.jogamp.newt.opengl.GLWindow.destroy
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
com.jogamp.newt.opengl.GLWindow.create
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
com.jogamp.newt.swt.NewtCanvasSWT
SWT Canvas containing a NEWT Window using native parenting.
Definition: NewtCanvasSWT.java:74
com.jogamp.newt.swt.NewtCanvasSWT.create
static NewtCanvasSWT create(final Composite parent, final int style, final Window child)
Creates an instance using NewtCanvasSWT(Composite, int, Window) on the SWT thread.
Definition: NewtCanvasSWT.java:106
com.jogamp.opengl.GLCapabilities
Specifies a set of OpenGL capabilities.
Definition: GLCapabilities.java:58
com.jogamp.opengl.GLProfile
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
com.jogamp.opengl.GLProfile.GL2ES2
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
Definition: GLProfile.java:594
com.jogamp.opengl.GLProfile.get
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
Definition: GLProfile.java:1000
com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2
Definition: RedSquareES2.java:45
com.jogamp.opengl.test.junit.newt.event.BaseNewtEventModifiers
Test whether or not event modifiers are preserved by NEWT.
Definition: BaseNewtEventModifiers.java:55
com.jogamp.opengl.test.junit.newt.event.BaseNewtEventModifiers.baseBeforeClass
static void baseBeforeClass()
Must be called from subclass @BeforeClass code, allowing it to perform its specific initialization fi...
Definition: BaseNewtEventModifiers.java:290
com.jogamp.opengl.test.junit.newt.event.TestNewtEventModifiersNewtCanvasSWTAWT
Test whether or not event modifiers preserved by NEWT when the canvas is a NewtCanvasSWT.
Definition: TestNewtEventModifiersNewtCanvasSWTAWT.java:58
com.jogamp.opengl.test.junit.newt.event.TestNewtEventModifiersNewtCanvasSWTAWT.main
static void main(final String args[])
Definition: TestNewtEventModifiersNewtCanvasSWTAWT.java:190
com.jogamp.opengl.test.junit.newt.event.TestNewtEventModifiersNewtCanvasSWTAWT.afterClass
static void afterClass()
Definition: TestNewtEventModifiersNewtCanvasSWTAWT.java:160
com.jogamp.opengl.test.junit.newt.event.TestNewtEventModifiersNewtCanvasSWTAWT.eventDispatch
void eventDispatch()
Definition: TestNewtEventModifiersNewtCanvasSWTAWT.java:93
com.jogamp.opengl.test.junit.newt.event.TestNewtEventModifiersNewtCanvasSWTAWT.beforeClass
static void beforeClass()
Definition: TestNewtEventModifiersNewtCanvasSWTAWT.java:100
com.jogamp.opengl.test.junit.newt.event.TestNewtEventModifiersNewtCanvasSWTAWT.eventDispatchImpl
static void eventDispatchImpl()
Definition: TestNewtEventModifiersNewtCanvasSWTAWT.java:67
com.jogamp.opengl.test.junit.util.AWTRobotUtil
Definition: AWTRobotUtil.java:51
com.jogamp.opengl.test.junit.util.AWTRobotUtil.requestFocus
static void requestFocus(final Robot robot, final Object obj)
FIXME: AWTRobotUtil Cleanup: Use specific type for argument object.
Definition: AWTRobotUtil.java:300
com.jogamp.opengl.GLAutoDrawable.addGLEventListener
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.