JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestWindowAndPointerIconNEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 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 java.io.IOException;
32import java.util.Properties;
33
34import com.jogamp.nativewindow.NativeWindowFactory;
35import com.jogamp.opengl.GLCapabilities;
36
37import org.junit.AfterClass;
38import org.junit.Assert;
39import org.junit.FixMethodOrder;
40import org.junit.Test;
41import org.junit.runners.MethodSorters;
42
43import com.jogamp.common.util.IOUtil;
44import com.jogamp.junit.util.SingletonJunitCase;
45import com.jogamp.newt.Display;
46import com.jogamp.newt.Display.PointerIcon;
47import com.jogamp.newt.opengl.GLWindow;
48import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
49import com.jogamp.opengl.test.junit.util.MiscUtils;
50import com.jogamp.opengl.test.junit.util.NewtTestUtil;
51import com.jogamp.opengl.test.junit.util.QuitAdapter;
52import com.jogamp.opengl.util.Animator;
53import com.jogamp.opengl.util.AnimatorBase;
54
55@FixMethodOrder(MethodSorters.NAME_ASCENDING)
56public class TestWindowAndPointerIconNEWT extends SingletonJunitCase {
57
58 static long duration = 1000; // ms
59
60 // As early as possible
61 static {
62 setPointerIcons();
63 }
64
65 static void setPointerIcons() {
66 final Properties sysp = System.getProperties();
67 sysp.put("jnlp.newt.window.icons", "red-16x16.png red-32x32.png");
68 }
69
70 @AfterClass
71 public static void unsetPointerIcons() {
72 final Properties sysp = System.getProperties();
73 sysp.remove("jnlp.newt.window.icons");
74 }
75
76 @Test
77 public void test() throws InterruptedException {
78 final GLWindow glWindow = GLWindow.create(new GLCapabilities(null));
79 Assert.assertNotNull(glWindow);
80
81 glWindow.setSize(800, 600);
82
83 final GearsES2 demo = new GearsES2(1);
84 glWindow.addGLEventListener(demo);
85
86 final QuitAdapter quitAdapter = new QuitAdapter();
87 glWindow.addKeyListener(quitAdapter);
88 glWindow.addWindowListener(quitAdapter);
89
90 final PointerIcon pointerIcon;
91 {
92 final Display disp = glWindow.getScreen().getDisplay();
93 disp.createNative();
94 final int idx = 0;
95 {
96 PointerIcon _pointerIcon = null;
97 final IOUtil.ClassResources res = new IOUtil.ClassResources(new String[] { "arrow-red-alpha-64x64.png" }, glWindow.getClass().getClassLoader(), null);
98 try {
99 _pointerIcon = disp.createPointerIcon(res, 0, 0);
100 System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString());
101 } catch (final Exception e) {
102 e.printStackTrace();
103 }
104 pointerIcon = _pointerIcon;
105 }
106 }
107 glWindow.setPointerIcon(pointerIcon);
108 System.err.println("Set PointerIcon: "+glWindow.getPointerIcon());
109
110 final Animator animator = new Animator(0 /* w/o AWT */);
111 animator.add(glWindow);
112 animator.start();
113
114 glWindow.setVisible(true);
115 glWindow.warpPointer(3*glWindow.getSurfaceWidth()/4, 3*glWindow.getSurfaceHeight()/4);
116
117 final long t0 = System.currentTimeMillis();
118 long t1 = t0;
119 while(!quitAdapter.shouldQuit() && t1-t0<duration) {
120 Thread.sleep(100);
121 t1 = System.currentTimeMillis();
122 }
123
124 animator.stop();
125
126 glWindow.destroy();
127 if( NativeWindowFactory.isAWTAvailable() ) {
128 Assert.assertEquals(true, NewtTestUtil.waitForRealized(glWindow, false, null));
129 }
130 }
131
132 public static void main(final String args[]) throws IOException {
133 for(int i=0; i<args.length; i++) {
134 if(args[i].equals("-time")) {
135 i++;
136 duration = MiscUtils.atol(args[i], duration);
137 }
138 }
139 org.junit.runner.JUnitCore.main(TestWindowAndPointerIconNEWT.class.getName());
140 }
141}
Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the NativeW...
abstract void createNative()
Manual trigger the native creation, if it is not done yet.
abstract PointerIcon createPointerIcon(final IOUtil.ClassResources pngResource, final int hotX, final int hotY)
Returns the newly created PointerIcon or null if not implemented on platform.
abstract Display getDisplay()
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void warpPointer(final int x, final int y)
Moves the pointer to x/y relative to this window's origin in pixel units.
Definition: GLWindow.java:342
final void setPointerIcon(final PointerIcon pi)
Definition: GLWindow.java:322
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Definition: GLWindow.java:466
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
Definition: GLWindow.java:902
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
Definition: GLWindow.java:461
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final PointerIcon getPointerIcon()
Returns the current PointerIcon, which maybe null for the default.
Definition: GLWindow.java:317
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 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.
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
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
Native PointerIcon handle.
Definition: Display.java:92
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.