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 29 package com.jogamp.opengl.test.junit.newt.event ; 30 31 import java.awt.BorderLayout ; 32 33 import com.jogamp.opengl.GLCapabilities ; 34 import com.jogamp.opengl.GLProfile ; 35 36 import javax.swing.JFrame ; 37 import javax.swing.SwingUtilities ; 38 import javax.swing.WindowConstants ; 39 40 import org.junit.AfterClass ; 41 import org.junit.Assert; 42 import org.junit.BeforeClass ; 43 import org.junit.FixMethodOrder; 44 import org.junit.runners.MethodSorters; 45 46 import com.jogamp.newt.awt.NewtCanvasAWT ; 47 import com.jogamp.newt.opengl.GLWindow ; 48 import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2; 49 import com.jogamp.opengl.test.junit.util.AWTRobotUtil; 50 51 /** 52 * Test whether or not event modifiers are preserved by NEWT when 53 * the canvas is a NewtCanvasAWT. 54 */ 55 @FixMethodOrder(MethodSorters.NAME_ASCENDING) 56 public class TestNewtEventModifiersNewtCanvasAWT extends BaseNewtEventModifiers { 57 58 private static JFrame _testFrame ; 59 private static GLWindow _glWindow ; 60 61 //////////////////////////////////////////////////////////////////////////// 62 63 @BeforeClass beforeClass()64 public static void beforeClass() throws Exception { 65 66 SwingUtilities.invokeAndWait( new Runnable() { 67 public void run() { 68 69 _testFrame = new JFrame( "Event Modifier Test NewtCanvasAWT" ) ; 70 _testFrame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE ) ; 71 72 { 73 final GLCapabilities caps = new GLCapabilities( GLProfile.getGL2ES2() ) ; 74 _glWindow = GLWindow.create( caps ) ; 75 76 final NewtCanvasAWT canvas = new NewtCanvasAWT( _glWindow ) ; 77 _testFrame.getContentPane().add( canvas, BorderLayout.CENTER ) ; 78 79 _glWindow.addGLEventListener( new RedSquareES2() ) ; 80 } 81 82 _testFrame.setBounds( TEST_FRAME_X, TEST_FRAME_Y, TEST_FRAME_WIDTH, TEST_FRAME_HEIGHT ) ; 83 _testFrame.setVisible( true ) ; 84 } 85 } ) ; 86 Assert.assertEquals(true, AWTRobotUtil.waitForVisible(_testFrame, true)); 87 Assert.assertTrue(AWTRobotUtil.waitForVisible(_glWindow, true)); 88 Assert.assertTrue(AWTRobotUtil.waitForRealized(_glWindow, true)); 89 90 AWTRobotUtil.assertRequestFocusAndWait(null, _glWindow, _glWindow, null, null); // programmatic 91 Assert.assertNotNull(_robot); 92 AWTRobotUtil.requestFocus(_robot, _glWindow, false); // within unit framework, prev. tests (TestFocus02SwingAWTRobot) 'confuses' Windows keyboard input 93 94 _glWindow.addMouseListener( _testMouseListener ) ; 95 } 96 97 //////////////////////////////////////////////////////////////////////////// 98 99 @AfterClass afterClass()100 public static void afterClass() throws Exception { 101 SwingUtilities.invokeAndWait( new Runnable() { 102 public void run() { 103 if( null != _testFrame ) { 104 _testFrame.dispose() ; 105 } 106 } 107 } ) ; 108 109 _glWindow.destroy() ; 110 } 111 112 //////////////////////////////////////////////////////////////////////////// 113 main(final String args[])114 public static void main(final String args[]) throws Exception { 115 final String testName = TestNewtEventModifiersNewtCanvasAWT.class.getName() ; 116 org.junit.runner.JUnitCore.main( testName ) ; 117 } 118 119 //////////////////////////////////////////////////////////////////////////// 120 } 121