/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* <p>This class contains utilities useful for regression testing.
* <p>When using jtreg you would include this class into the build
* list via something like:
* <pre>
@library ../../../regtesthelpers
@build Util
@run main YourTest
</pre>
* Note that if you are about to create a test based on
* Applet-template, then put those lines into html-file, not in java-file.
* <p> And put an
* import test.java.awt.regtesthelpers.Util;
* into the java source of test.
*/
public final class Util {
/*
* @throws RuntimeException when creation failed
*/
try {
return new Robot();
} catch (AWTException e) {
throw new RuntimeException("Error: unable to create robot", e);
}
}
{
hwnd_field.setAccessible(true);
}
}
/**
* Makes the window visible and waits until it's shown.
*/
win.setVisible(true);
}
/**
* Moves mouse pointer in the center of given {@code comp} component
* using {@code robot} parameter.
*/
}
/**
* Moves mouse pointer in the center of a given {@code comp} component
* and performs a left mouse button click using the {@code robot} parameter
* with the {@code delay} delay between press and release.
*/
}
/**
* Moves mouse pointer in the center of a given {@code comp} component
* and performs a left mouse button click using the {@code robot} parameter
* with the default delay between press and release.
*/
}
}
/*
* WARNING: it may fail on some platforms when the window is not wide enough.
*/
}
}
// we do not use robot for now, use SunToolkit.realSync() instead
}
try {
field.setAccessible(true);
return field;
} catch (SecurityException se) {
} catch (NoSuchFieldException nsfe) {
}
}
});
}
/*
* Waits for a notification and for a boolean condition to become true.
* The method returns when the above conditions are fullfilled or when the timeout
* occurs.
*
* @param condition the object to be notified and the booelan condition to wait for
* @param timeout the maximum time to wait in milliseconds
* @param catchExceptions if {@code true} the method catches InterruptedException
* @return the final boolean value of the {@code condition}
* @throws InterruptedException if the awaiting proccess has been interrupted
*/
throws InterruptedException
{
synchronized (condition) {
break;
}
}
}
}
/*
* The same as {@code waitForConditionEx(AtomicBoolean, long)} except that it
* doesn't throw InterruptedException.
*/
try {
} catch (InterruptedException e) {
throw new RuntimeException("Error: unexpected exception caught!", e);
}
}
/*
* The same as {@code waitForConditionEx(AtomicBoolean, long)} but without a timeout.
*/
throws InterruptedException
{
synchronized (condition) {
}
}
}
/*
* The same as {@code waitForConditionEx(AtomicBoolean)} except that it
* doesn't throw InterruptedException.
*/
try {
} catch (InterruptedException e) {
throw new RuntimeException("Error: unexpected exception caught!", e);
}
}
while (true) {
try {
break;
} catch (IllegalComponentStateException e) {}
}
}
try {
} catch (InterruptedException e) {
throw new RuntimeException("Error: unexpected exception caught!", e);
}
}
/**
* Drags from one point to another with the specified mouse button pressed.
*
* @param robot a robot to use for moving the mouse, etc.
* @param startPoint a start point of the drag
* @param endPoint an end point of the drag
* @param button one of {@code InputEvent.BUTTON1_MASK},
* {@code InputEvent.BUTTON2_MASK}, {@code InputEvent.BUTTON3_MASK}
*
* @throws IllegalArgumentException if {@code button} is not one of
* {@code InputEvent.BUTTON1_MASK}, {@code InputEvent.BUTTON2_MASK},
* {@code InputEvent.BUTTON3_MASK}
*/
{
throw new IllegalArgumentException("invalid mouse button");
}
try {
} finally {
}
}
/**
* Moves the mouse pointer from one point to another.
* Uses Bresenham's algorithm.
*
* @param robot a robot to use for moving the mouse
* @param startPoint a start point of the drag
* @param endPoint an end point of the drag
*/
int x = startPoint.x;
int y = startPoint.y;
int d = 0;
while (true){
if (x == endPoint.x){
return;
}
if (d >= 0){
y = y + sy;
d = d - ax;
}
x = x + sx;
d = d + ay;
}
} else {
while (true){
if (y == endPoint.y){
return;
}
if (d >= 0){
x = x + sx;
d = d - ay;
}
y = y + sy;
d = d + ax;
}
}
}
private static int signWOZero(int i){
return (i > 0)? 1: -1;
}
private static int sign(int n) {
return n < 0 ? -1 : n == 0 ? 0 : 1;
}
/** Returns {@code WindowListener} instance that diposes {@code Window} on
* "window closing" event.
*
* @return the {@code WindowListener} instance that could be set
* on a {@code Window}. After that
* the {@code Window} is disposed when "window closed"
* event is sent to the {@code Window}
*/
return new WindowAdapter () {
public void windowClosing(WindowEvent e) {
}
};
}
/*
* The values directly map to the ones of
* sun.awt.X11.XWM & sun.awt.motif.MToolkit classes.
*/
public final static int
/*
* Returns -1 in case of not X Window or any problems.
*/
public static int getWMID() {
try {
}
} catch (ClassNotFoundException cnfe) {
}
return -1;
}
try {
try {
method.setAccessible(true);
}
return method;
} catch (NoSuchMethodException e) {
assert false;
} catch (SecurityException e) {
assert false;
}
return null;
}
});
} catch (IllegalAccessException iae) {
} catch (InvocationTargetException ite) {
}
return -1;
}
////////////////////////////
// Some stuff to test focus.
////////////////////////////
private abstract static class EventListener {
boolean printEvent;
this.printEvent = printEvent;
}
return notifier;
}
if (printEvent) {
}
synchronized (notifier) {
}
}
}
private static class WindowGainedFocusListener extends EventListener implements WindowFocusListener {
}
printAndNotify(e);
}
}
comp.addFocusListener(this);
}
comp.removeFocusListener(this);
printAndNotify(e);
}
}
}
printAndNotify(e);
}
}
private static boolean trackEvent(int eventID, Component comp, Runnable action, int time, boolean printEvent) {
switch (eventID) {
break;
case FocusEvent.FOCUS_GAINED:
break;
case ActionEvent.ACTION_PERFORMED:
break;
}
}
/*
* Tracks WINDOW_GAINED_FOCUS event for a window caused by an action.
* @param window the window to track the event for
* @param action the action to perform
* @param time the max time to wait for the event
* @param printEvent should the event received be printed or doesn't
* @return true if the event has been received, otherwise false
*/
public static boolean trackWindowGainedFocus(Window window, Runnable action, int time, boolean printEvent) {
}
/*
* Tracks FOCUS_GAINED event for a component caused by an action.
* @see #trackWindowGainedFocus
*/
public static boolean trackFocusGained(Component comp, Runnable action, int time, boolean printEvent) {
}
/*
* Tracks ACTION_PERFORMED event for a button caused by an action.
* @see #trackWindowGainedFocus
*/
public static boolean trackActionPerformed(Button button, Runnable action, int time, boolean printEvent) {
}
/*
* Requests focus on the component provided and waits for the result.
* @return true if the component has been focused, false otherwise.
*/
}
return trackFocusGained(comp,
new Runnable() {
public void run() {
comp.requestFocus();
}
},
time, printEvent);
}
/**
* Invokes the <code>task</code> on the EDT thread.
*
* @return result of the <code>task</code>
*/
public void run() {
try {
} catch (Exception e) {
exception[0] = e;
}
}
});
throw exception[0];
}
}
}