30package com.jogamp.opengl.test.junit.util;
32import java.util.concurrent.atomic.AtomicInteger;
34import com.jogamp.nativewindow.util.InsetsImmutable;
35import com.jogamp.newt.Screen;
36import com.jogamp.newt.Window;
37import com.jogamp.newt.event.WindowEvent;
39import jogamp.newt.WindowImplAccess;
45 AtomicInteger closing =
new AtomicInteger(0);
46 AtomicInteger closed =
new AtomicInteger(0);
63 return 0 < closing.get();
67 return 0 < closed.get();
71 closing.incrementAndGet();
72 System.err.println(
"NEWTWindowClosingAdapter.windowDestroyNotify: "+
this);
76 closed.incrementAndGet();
77 System.err.println(
"NEWTWindowClosingAdapter.windowDestroyed: "+
this);
81 return "NEWTWindowClosingAdapter[closing "+closing+
", closed "+closed+
"]";
89 public static boolean waitForFocus(
final Window win,
final Runnable waitAction)
throws InterruptedException {
91 for (wait=0; wait<
POLL_DIVIDER && !win.hasFocus(); wait++) {
92 if(
null != waitAction ) {
119 public static boolean waitForSize(
final Window window,
final int width,
final int height,
final Runnable waitAction)
throws InterruptedException {
121 for (wait=0; wait<
POLL_DIVIDER && ( width != window.getSurfaceWidth() || height != window.getSurfaceHeight() ) ; wait++) {
122 if(
null != waitAction ) {
135 public static boolean waitForVisible(
final Window win,
final boolean visible,
final Runnable waitAction)
throws InterruptedException {
137 for (wait=0; wait<
POLL_DIVIDER && visible != win.isVisible(); wait++) {
138 if(
null != waitAction ) {
154 public static boolean waitForRealized(
final Screen screen,
final boolean realized,
final Runnable waitAction)
throws InterruptedException {
155 final long t0 = System.currentTimeMillis();
157 while( (t1-t0) <
TIME_OUT && realized != screen.isNativeValid() ) {
158 if(
null != waitAction ) {
163 t1 = System.currentTimeMillis();
174 public static boolean waitForRealized(
final Window win,
final boolean realized,
final Runnable waitAction)
throws InterruptedException {
175 final long t0 = System.currentTimeMillis();
177 while( (t1-t0) <
TIME_OUT && realized != win.isNativeValid() ) {
178 if(
null != waitAction ) {
183 t1 = System.currentTimeMillis();
208 closingListener.reset();
209 WindowImplAccess.windowDestroyNotify(win);
220 final int maxDX, maxDY;
226 return hasPosition(win, shouldX, shouldY, maxDX, maxDY);
232 public static boolean hasPosition(
final Window win,
final int expX,
final int expY,
final int maxDX,
final int maxDY) {
233 final int dx = Math.abs(expX - win.
getX());
234 final int dy = Math.abs(expY - win.
getY());
235 final boolean ok = dx <= maxDX && dy <= maxDY ;
237 System.err.println(
"Position OFF: abs( exp "+expX+
"/"+expY+
" - has "+win.
getX()+
"/"+win.
getY()+
" ) = "+dx+
"/"+dy+
" > "+maxDX+
"/"+maxDY);
239 System.err.println(
"Position OK : abs( exp "+expX+
"/"+expY+
" - has "+win.
getX()+
"/"+win.
getY()+
" ) = "+dx+
"/"+dy+
" <= "+maxDX+
"/"+maxDY);
A screen may span multiple MonitorDevices representing their combined virtual size.
NEWT Window events are provided for notification purposes ONLY.
void windowDestroyNotify(final WindowEvent e)
Window destruction has been requested.
boolean isWindowClosing()
int getWindowClosedCount()
void windowDestroyed(final WindowEvent e)
Window has been destroyed.
int getWindowClosingCount()
static TestUtil.WindowClosingListener addClosingListener(final Window win)
static boolean hasPosition(final Window win, final int expX, final int expY, final int maxDX, final int maxDY)
Validates whether the window position is within the expected position including given tolerance.
static boolean hasPositionMax2xInsetsOr64Pix(final Window win, final int shouldX, final int shouldY)
Validates whether the window position is on the given position within tolerances.
static boolean waitForFocus(final Window win, final Runnable waitAction)
static boolean closeWindow(final Window win, final boolean willClose, final TestUtil.WindowClosingListener closingListener, final Runnable waitAction)
Programmatically issue windowClosing on AWT or NEWT.
static boolean waitForSize(final Window window, final int width, final int height, final Runnable waitAction)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
static boolean waitForFocus(final Window win, final FocusEventCountAdapter gain, final FocusEventCountAdapter lost, final Runnable waitAction)
static boolean waitForRealized(final Window win, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final Window win, final boolean visible, final Runnable waitAction)
static final int TIME_SLICE
static final int POLL_DIVIDER
static boolean waitForFocus(final FocusEventCountAdapter gain, final FocusEventCountAdapter lost, final Runnable waitAction)
static boolean waitUntilClosed(final boolean willClose, final TestUtil.WindowClosingListener closingListener, final Runnable waitAction)
Wait until the window is closing within TIME_OUT.
static final int TIME_OUT
int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
int getX()
Returns the current x position of this window, relative to it's parent.
Immutable insets representing rectangular window decoration insets on all four edges in window units.
Specifying NEWT's Window functionality:
void addWindowListener(WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.