JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestNewtEventModifiersAWTCanvas.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
32
33import javax.swing.JFrame ;
34import javax.swing.SwingUtilities ;
35import javax.swing.WindowConstants ;
36
37import org.junit.AfterClass ;
38import org.junit.Assert;
39import org.junit.BeforeClass ;
40import org.junit.FixMethodOrder;
41import org.junit.runners.MethodSorters;
42
43import com.jogamp.nativewindow.swt.SWTAccessor;
45import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
46import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
47
48/**
49 * Test whether or not event modifiers are preserved by NEWT when
50 * the source is an AWT canvas.
51 */
52
53@FixMethodOrder(MethodSorters.NAME_ASCENDING)
55
56 private static JFrame _testFrame ;
57
58 ////////////////////////////////////////////////////////////////////////////
59
60 @BeforeClass
61 public static void beforeClass() throws Exception {
63
64 final GLCanvas canvas = new GLCanvas() ;
65 canvas.addGLEventListener( new RedSquareES2() ) ;
66 new AWTMouseAdapter( _testMouseListener, canvas ).addTo( canvas ) ;
67
68 _testFrame = new JFrame( "Event Modifier Test AWTCanvas" ) ;
69 _testFrame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE ) ;
70
71 SwingUtilities.invokeAndWait(new Runnable() {
72 @Override
73 public void run() {
74 _testFrame.getContentPane().add( canvas ) ;
75 _testFrame.setBounds( TEST_FRAME_X, TEST_FRAME_Y, TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT ) ;
76 _testFrame.setVisible( true ) ;
77 }
78 }) ;
79 Assert.assertEquals(true, AWTRobotUtil.waitForVisible(_testFrame, true, null));
80 Assert.assertTrue(AWTRobotUtil.waitForVisible(canvas, true, null));
81 Assert.assertTrue(AWTRobotUtil.waitForRealized(canvas, true, null));
82
83 AWTRobotUtil.assertRequestFocusAndWait(null, canvas, canvas, null, null); // programmatic
84 Assert.assertNotNull(_robot);
85 AWTRobotUtil.requestFocus(_robot, canvas, false); // within unit framework, prev. tests (TestFocus02SwingAWTRobot) 'confuses' Windows keyboard input
86 }
87
88 ////////////////////////////////////////////////////////////////////////////
89
90 @AfterClass
91 public static void afterClass() throws Exception {
92 SwingUtilities.invokeAndWait(new Runnable() {
93 @Override
94 public void run() {
95 if( null != _testFrame ) {
96 _testFrame.dispose() ;
97 }
98 }
99 }) ;
100 }
101
102 ////////////////////////////////////////////////////////////////////////////
103
104 public static void main(final String args[]) throws Exception {
105 final String testName = TestNewtEventModifiersAWTCanvas.class.getName() ;
106 org.junit.runner.JUnitCore.main( testName ) ;
107 }
108
109 ////////////////////////////////////////////////////////////////////////////
110}
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
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 source is an AWT canvas.
static void requestFocus(final Robot robot, final Object obj)
FIXME: AWTRobotUtil Cleanup: Use specific type for argument object.
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 assertRequestFocusAndWait(final Robot robot, final Object requestFocus, final Object waitForFocus, final FocusEventCountAdapter gain, final FocusEventCountAdapter lost)