JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestListenerCom01AWT.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;
30
31import org.junit.Assert;
32import org.junit.BeforeClass;
33import org.junit.Test;
34import org.junit.FixMethodOrder;
35import org.junit.runners.MethodSorters;
36
37import java.awt.Frame;
38
39import com.jogamp.opengl.*;
40
41import com.jogamp.opengl.util.Animator;
42import com.jogamp.newt.*;
43import com.jogamp.newt.opengl.*;
44import com.jogamp.newt.awt.NewtCanvasAWT;
45
46import java.io.IOException;
47import java.lang.reflect.InvocationTargetException;
48
49import com.jogamp.opengl.test.junit.util.*;
50import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
51
52@FixMethodOrder(MethodSorters.NAME_ASCENDING)
53public class TestListenerCom01AWT extends UITestCase {
54 static int width, height;
55 static long durationPerTest = 500;
56 static boolean verbose = false;
57
58 @BeforeClass
59 public static void initClass() {
60 width = 640;
61 height = 480;
62 }
63
64 @Test
65 public void testListenerStringPassingAndOrder() throws InterruptedException, InvocationTargetException {
66 // setup NEWT GLWindow ..
67 final GLWindow glWindow = GLWindow.create(new GLCapabilities(null));
68 Assert.assertNotNull(glWindow);
69 glWindow.setTitle("NEWT - CHILD");
70
71 System.out.println("durationPerTest "+durationPerTest);
72
73 final GLEventListener demo = new GearsES2();
74 setDemoFields(demo, glWindow, false);
75 glWindow.addGLEventListener(demo);
76
77 final WindowEventCom1 wl1 = new WindowEventCom1();
78 final WindowEventCom2 wl2 = new WindowEventCom2();
79 final WindowEventCom3 wl3 = new WindowEventCom3();
80
81 // TraceWindowAdapter wlT = new TraceWindowAdapter();
82 // glWindow.addWindowListener(0, wlT);
83 // Assert.assertEquals(wlT, glWindow.getWindowListener(0));
84
85 glWindow.addWindowListener(0, wl3);
86 glWindow.addWindowListener(0, wl2);
87 glWindow.addWindowListener(0, wl1);
88
89 Assert.assertEquals(wl1, glWindow.getWindowListener(0));
90 Assert.assertEquals(wl2, glWindow.getWindowListener(1));
91 Assert.assertEquals(wl3, glWindow.getWindowListener(2));
92
93 // attach NEWT GLWindow to AWT Canvas
94 final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow);
95 final Frame frame = new Frame("AWT Parent Frame");
96 frame.add(newtCanvasAWT);
97 frame.setSize(width, height);
98 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
99 public void run() {
100 frame.setVisible(true);
101 }});
102
103 final Animator animator1 = new Animator(glWindow);
104 animator1.setUpdateFPSFrames(1, null);
105 animator1.start();
106 while(animator1.isAnimating() && animator1.getTotalFPSDuration()<durationPerTest) {
107 Thread.sleep(100);
108 width+=10; height+=10;
109 frame.setSize(width, height);
110 }
111 animator1.stop();
112 Assert.assertEquals(false, animator1.isAnimating());
113
114 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
115 public void run() {
116 frame.dispose();
117 }});
118 glWindow.destroy();
119 }
120
121 public static void setDemoFields(final GLEventListener demo, final GLWindow glWindow, final boolean debug) {
122 Assert.assertNotNull(demo);
123 Assert.assertNotNull(glWindow);
124 final Window window = glWindow.getDelegatedWindow();
125 if(debug) {
126 MiscUtils.setFieldIfExists(demo, "glDebug", true);
127 MiscUtils.setFieldIfExists(demo, "glTrace", true);
128 }
129 if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
130 MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
131 }
132 }
133
134 static int atoi(final String a) {
135 int i=0;
136 try {
137 i = Integer.parseInt(a);
138 } catch (final Exception ex) { ex.printStackTrace(); }
139 return i;
140 }
141
142 public static void main(final String args[]) throws IOException {
143 verbose = true;
144 for(int i=0; i<args.length; i++) {
145 if(args[i].equals("-time")) {
146 durationPerTest = atoi(args[++i]);
147 }
148 }
149 final String tstname = TestListenerCom01AWT.class.getName();
150 org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
151 tstname,
152 "filtertrace=true",
153 "haltOnError=false",
154 "haltOnFailure=false",
155 "showoutput=true",
156 "outputtoformatters=true",
157 "logfailedtests=true",
158 "logtestlistenerevents=true",
159 "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
160 "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
161 }
162
163}
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 setTitle(final String title)
Definition: GLWindow.java:297
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
Definition: GLWindow.java:882
final WindowListener getWindowListener(final int index)
Definition: GLWindow.java:867
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
Definition: GLWindow.java:277
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.
static void setDemoFields(final GLEventListener demo, final GLWindow glWindow, final boolean debug)
static boolean setFieldIfExists(final Object instance, final String fieldName, final Object value)
Definition: MiscUtils.java:193
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368
Specifying NEWT's Window functionality:
Definition: Window.java:115
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.