29package com.jogamp.opengl.test.junit.jogl.newt;
31import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
32import com.jogamp.opengl.test.junit.util.*;
34import java.lang.reflect.InvocationTargetException;
36import com.jogamp.nativewindow.NativeWindowFactory;
37import com.jogamp.nativewindow.util.RectangleImmutable;
38import com.jogamp.opengl.GLAutoDrawable;
39import com.jogamp.opengl.GLProfile;
40import com.jogamp.opengl.GLCapabilities;
41import com.jogamp.opengl.awt.GLCanvas;
43import com.jogamp.opengl.util.Animator;
44import com.jogamp.newt.Screen;
45import com.jogamp.newt.opengl.GLWindow;
46import com.jogamp.newt.awt.NewtCanvasAWT;
48import java.awt.BorderLayout;
49import java.awt.Canvas;
51import java.awt.Dimension;
52import java.awt.AWTException;
55import java.awt.event.InputEvent;
56import java.awt.event.MouseAdapter;
57import java.awt.event.MouseEvent;
58import java.awt.event.WindowAdapter;
59import java.awt.event.WindowEvent;
61import com.jogamp.opengl.GLEventListener;
62import javax.swing.JButton;
63import javax.swing.JFrame;
64import javax.swing.JPanel;
65import javax.swing.BorderFactory;
66import javax.swing.border.Border;
68import org.junit.Assert;
69import org.junit.BeforeClass;
70import org.junit.AfterClass;
72import org.junit.FixMethodOrder;
73import org.junit.runners.MethodSorters;
75@FixMethodOrder(MethodSorters.NAME_ASCENDING)
77 static long durationPerTest = 150;
81 static JButton button;
83 static JPanel colorPanel;
84 static boolean windowClosing;
86 boolean modLightBrighter =
true;
88 Color modLight(
final Color c) {
90 if(modLightBrighter) {
96 modLightBrighter = !modLightBrighter;
109 colorPanel.setBackground(modLight(colorPanel.getBackground()));
110 colorPanel.repaint();
113 public void reshape(
final GLAutoDrawable glad,
final int x,
final int y,
final int width,
final int height) {
118 public static void setup() throws InterruptedException, InvocationTargetException, AWTException {
119 System.err.println(
"TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): Start Pre-JOGL-Swing");
123 border = BorderFactory.createLineBorder (Color.yellow, 2);
125 panel =
new JPanel();
126 panel.setLayout(
new BorderLayout());
128 button =
new JButton(
"Click me");
130 public void mouseClicked(
final MouseEvent e) {
131 System.err.println(
"Test: "+e);
134 panel.add(button, BorderLayout.NORTH);
136 colorPanel =
new JPanel();
137 final Dimension size =
new Dimension(400,100);
138 colorPanel.setPreferredSize(size);
139 colorPanel.setBorder(border);
140 panel.add(colorPanel, BorderLayout.SOUTH);
142 frame =
new JFrame(
"PRE JOGL");
143 frame.addWindowListener(
new WindowAdapter() {
148 frame.setContentPane(panel);
153 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
155 frame.setSize(512, 512);
156 frame.setLocation(0, 0);
158 frame.setVisible(
true);
159 colorPanel.setBackground(Color.white);
160 colorPanel.repaint();
164 robot.setAutoWaitForIdle(
true);
167 for (
int wait=0; wait<TestUtil.POLL_DIVIDER && !frame.isVisible(); wait++) {
170 Assert.assertEquals(
true, frame.isVisible());
172 System.err.println(
"TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): Before NativeWindow init");
180 System.err.println(
"TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): Before JOGL init");
185 System.err.println(
"TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): End Pre-JOGL-Swing");
189 public static void release() throws InterruptedException, InvocationTargetException {
190 System.err.println(
"TestSwingAWTRobotUsageBeforeJOGLInitBug411.release(): Start");
192 Assert.assertNotNull(frame);
193 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
199 System.err.println(
"TestSwingAWTRobotUsageBeforeJOGLInitBug411.release(): End");
203 throws AWTException, InterruptedException, InvocationTargetException {
205 final Dimension size =
new Dimension(400,400);
206 canvas.setPreferredSize(size);
208 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
210 panel.add(canvas, BorderLayout.CENTER);
219 drawable.addGLEventListener(
new GearsES2());
221 for(
int i=0; i<100; i++) {
222 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
224 colorPanel.setBackground(modLight(colorPanel.getBackground()));
225 colorPanel.repaint();
232 colorPanel.setBackground(Color.blue);
233 drawable.addGLEventListener(
new SwingGLAction());
235 final Point p0 = canvas.getLocationOnScreen();
237 robot.mouseMove( (
int) ( p0.getX() + .5 ) ,
238 (
int) ( p0.getY() + .5 ) );
240 for(
int i=0; !windowClosing && i<durationPerTest/10; i++) {
242 robot.mouseMove( (
int) ( p0.getX() + .5 ) ,
243 (
int) ( p0.getY() + .5 ) );
248 for(
int i=0; !windowClosing && i<durationPerTest/100; i++) {
252 Assert.assertNotNull(canvas);
253 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
255 panel.remove(canvas);
263 System.err.println(
"TestSwingAWTRobotUsageBeforeJOGLInitBug411.test01NewtCanvasAWT(): Start");
283 runTestGL(newtCanvasAWT, win1);
288 Assert.assertEquals(
true, anim.isAnimating());
293 Assert.assertEquals(
true, anim.isAnimating());
295 Assert.assertEquals(
true, anim.
stop());
296 Assert.assertEquals(
false, anim.isAnimating());
298 System.err.println(
"TestSwingAWTRobotUsageBeforeJOGLInitBug411.test01NewtCanvasAWT(): End");
302 public void test02GLCanvas() throws AWTException, InterruptedException, InvocationTargetException {
303 System.err.println(
"TestSwingAWTRobotUsageBeforeJOGLInitBug411.test02GLCanvas(): Start");
325 runTestGL(glCanvas, glCanvas);
328 Assert.assertEquals(
false, anim.isAnimating());
334 Assert.assertEquals(
true, anim.
stop());
335 System.err.println(
"TestSwingAWTRobotUsageBeforeJOGLInitBug411.test02GLCanvas(): End");
338 static int atoi(
final String a) {
341 i = Integer.parseInt(a);
342 }
catch (
final Exception ex) { ex.printStackTrace(); }
346 public static void main(
final String args[]) {
347 for(
int i=0; i<args.length; i++) {
348 if(args[i].equals(
"-time")) {
349 durationPerTest = atoi(args[++i]);
352 System.out.println(
"durationPerTest: "+durationPerTest);
Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the NativeW...
static synchronized void initSingleton()
Static one time initialization of this factory.
A screen may span multiple MonitorDevices representing their combined virtual size.
abstract RectangleImmutable getViewportInWindowUnits()
See Coordinate System.
AWT Canvas containing a NEWT Window using native parenting.
final void destroy()
Destroys this resource:
Pointer event of type PointerType.
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final boolean isNativeValid()
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
static void initSingleton()
Static initialization of JOGL.
A heavyweight AWT component which provides OpenGL rendering support.
void test01NewtCanvasAWT()
void runTestGL(final Canvas canvas, final GLAutoDrawable drawable)
static void main(final String args[])
static void requestFocus(final Robot robot, final Object obj)
FIXME: AWTRobotUtil Cleanup: Use specific type for argument object.
static boolean toFrontAndRequestFocus(Robot robot, final java.awt.Window window)
toFront, call setVisible(true) and toFront(), after positioning the mouse in the middle of the window...
static void clearAWTFocus(Robot robot)
static boolean waitForRealized(final GLAutoDrawable glad, final boolean realized, final Runnable waitAction)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
static final int TIME_SLICE
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized void remove(final GLAutoDrawable drawable)
Removes a drawable from the animator's list of rendering drawables.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
Immutable Rectangle interface, with its position on the top-left.
int getX()
x-position, left of rectangle.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
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.