JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestNewtEventModifiersNewtCanvasAWT.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 java.awt.BorderLayout ;
32
35
36import javax.swing.JFrame ;
37import javax.swing.SwingUtilities ;
38import javax.swing.WindowConstants ;
39
40import org.junit.AfterClass ;
41import org.junit.Assert;
42import org.junit.BeforeClass ;
43import org.junit.FixMethodOrder;
44import org.junit.runners.MethodSorters;
45
48import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
49import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
50import com.jogamp.opengl.test.junit.util.NewtTestUtil;
51
52/**
53 * Test whether or not event modifiers are preserved by NEWT when
54 * the canvas is a NewtCanvasAWT.
55 */
56@FixMethodOrder(MethodSorters.NAME_ASCENDING)
58
59 private static JFrame _testFrame ;
60 private static GLWindow _glWindow ;
61
62 ////////////////////////////////////////////////////////////////////////////
63
64 @BeforeClass
65 public static void beforeClass() throws Exception {
67
68 SwingUtilities.invokeAndWait( new Runnable() {
69 @Override
70 public void run() {
71
72 _testFrame = new JFrame( "Event Modifier Test NewtCanvasAWT" ) ;
73 _testFrame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE ) ;
74
75 {
76 final GLCapabilities caps = new GLCapabilities( GLProfile.getGL2ES2() ) ;
77 _glWindow = GLWindow.create( caps ) ;
78
79 final NewtCanvasAWT canvas = new NewtCanvasAWT( _glWindow ) ;
80 _testFrame.getContentPane().add( canvas, BorderLayout.CENTER ) ;
81
82 _glWindow.addGLEventListener( new RedSquareES2() ) ;
83 }
84
85 _testFrame.setBounds( TEST_FRAME_X, TEST_FRAME_Y, TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT ) ;
86 _testFrame.setVisible( true ) ;
87 }
88 } ) ;
89 Assert.assertEquals(true, AWTRobotUtil.waitForVisible(_testFrame, true, null));
90 Assert.assertTrue(NewtTestUtil.waitForVisible(_glWindow, true, null));
91 final GLWindow obj = _glWindow;
92 Assert.assertTrue(NewtTestUtil.waitForRealized(obj, true, null));
93
94 AWTRobotUtil.assertRequestFocusAndWait(null, _glWindow, _glWindow, null, null); // programmatic
95 Assert.assertNotNull(_robot);
96 AWTRobotUtil.requestFocus(_robot, _glWindow, false); // within unit framework, prev. tests (TestFocus02SwingAWTRobot) 'confuses' Windows keyboard input
97
98 _glWindow.addMouseListener( _testMouseListener ) ;
99 }
100
101 ////////////////////////////////////////////////////////////////////////////
102
103 @AfterClass
104 public static void afterClass() throws Exception {
105 SwingUtilities.invokeAndWait( new Runnable() {
106 @Override
107 public void run() {
108 if( null != _testFrame ) {
109 _testFrame.dispose() ;
110 }
111 }
112 } ) ;
113
114 _glWindow.destroy() ;
115 }
116
117 ////////////////////////////////////////////////////////////////////////////
118
119 public static void main(final String args[]) throws Exception {
120 final String testName = TestNewtEventModifiersNewtCanvasAWT.class.getName() ;
121 org.junit.runner.JUnitCore.main( testName ) ;
122 }
123
124 ////////////////////////////////////////////////////////////////////////////
125}
AWT Canvas containing a NEWT Window using native parenting.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
Definition: GLWindow.java:927
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
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
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
Test whether or not event modifiers are preserved by NEWT.
static void baseBeforeClass()
Must be called from subclass @BeforeClass code, allowing it to perform its specific initialization fi...
Test whether or not event modifiers are preserved by NEWT when the canvas is a NewtCanvasAWT.
static void requestFocus(final Robot robot, final Object obj)
FIXME: AWTRobotUtil Cleanup: Use specific type for argument object.
static boolean waitForVisible(final java.awt.Component comp, final boolean visible, final Runnable waitAction)
static void assertRequestFocusAndWait(final Robot robot, final Object requestFocus, final Object waitForFocus, final FocusEventCountAdapter gain, final FocusEventCountAdapter lost)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final Window win, final boolean visible, final Runnable waitAction)
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.