|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| TestHelper.java | 71.8% | 74.9% | 63.2% | 72.8% |
|
||||||||||||||
| 1 |
package junit.extensions.jfcunit;
|
|
| 2 |
|
|
| 3 |
import java.util.ArrayList;
|
|
| 4 |
import java.util.Collections;
|
|
| 5 |
import java.util.HashMap;
|
|
| 6 |
import java.util.Iterator;
|
|
| 7 |
import java.util.List;
|
|
| 8 |
import java.util.Set;
|
|
| 9 |
|
|
| 10 |
import java.awt.Component;
|
|
| 11 |
import java.awt.Container;
|
|
| 12 |
import java.awt.Frame;
|
|
| 13 |
import java.awt.Point;
|
|
| 14 |
import java.awt.Window;
|
|
| 15 |
import java.awt.event.InputEvent;
|
|
| 16 |
import java.awt.event.KeyEvent;
|
|
| 17 |
import java.awt.event.WindowEvent;
|
|
| 18 |
import javax.swing.JDialog;
|
|
| 19 |
import javax.swing.JFileChooser;
|
|
| 20 |
import javax.swing.JLabel;
|
|
| 21 |
|
|
| 22 |
import org.apache.regexp.RE;
|
|
| 23 |
import org.apache.regexp.RESyntaxException;
|
|
| 24 |
import junit.extensions.jfcunit.eventdata.AbstractKeyEventData;
|
|
| 25 |
import junit.extensions.jfcunit.eventdata.AbstractMouseEventData;
|
|
| 26 |
import junit.extensions.jfcunit.eventdata.DragEventData;
|
|
| 27 |
import junit.extensions.jfcunit.eventdata.KeyEventData;
|
|
| 28 |
import junit.extensions.jfcunit.eventdata.MouseWheelEventData;
|
|
| 29 |
import junit.extensions.jfcunit.finder.AbstractWindowFinder;
|
|
| 30 |
import junit.extensions.jfcunit.finder.ComponentFinder;
|
|
| 31 |
import junit.extensions.jfcunit.finder.DialogFinder;
|
|
| 32 |
import junit.extensions.jfcunit.finder.Finder;
|
|
| 33 |
import junit.extensions.jfcunit.finder.FrameFinder;
|
|
| 34 |
import junit.extensions.jfcunit.finder.NamedComponentFinder;
|
|
| 35 |
import junit.extensions.jfcunit.keyboard.DefaultKeyMapping;
|
|
| 36 |
import junit.extensions.jfcunit.keyboard.JFCKeyStroke;
|
|
| 37 |
import junit.extensions.jfcunit.keyboard.KeyMapping;
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
/**
|
|
| 41 |
* A helper class that provides facilities for locating and posting events to components
|
|
| 42 |
* within a GUI. To use, create a new instance of TestHelper in your setUp.
|
|
| 43 |
* Caveat: Windows can only be located once they have been shown once to the user.
|
|
| 44 |
*
|
|
| 45 |
* @author Matt Caswell
|
|
| 46 |
* @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
|
|
| 47 |
*/
|
|
| 48 |
public abstract class TestHelper { |
|
| 49 |
/**
|
|
| 50 |
* The length of time that the test class will sleep for between each
|
|
| 51 |
* event being posted.
|
|
| 52 |
*/
|
|
| 53 |
public static final long DEFAULTSLEEP = 300L; |
|
| 54 |
|
|
| 55 |
/**
|
|
| 56 |
* Current test.
|
|
| 57 |
*/
|
|
| 58 |
private static JFCTestCase s_test; |
|
| 59 |
|
|
| 60 |
/**
|
|
| 61 |
* KeyMapping to be used with the helper.
|
|
| 62 |
*/
|
|
| 63 |
private static KeyMapping s_keyMapping = null; |
|
| 64 |
|
|
| 65 |
/**
|
|
| 66 |
* System Windows List. These windows should not be closed
|
|
| 67 |
* when the cleanUp is called. The vector should contain
|
|
| 68 |
* the Regular expression strings for matching the name to the
|
|
| 69 |
* title.
|
|
| 70 |
*/
|
|
| 71 |
private static HashMap s_systemWindows = new HashMap(); |
|
| 72 |
|
|
| 73 |
/**
|
|
| 74 |
* Lock for setting the key mapping.
|
|
| 75 |
*/
|
|
| 76 |
private static final Object LOCK = new Object(); |
|
| 77 |
|
|
| 78 |
/**
|
|
| 79 |
* Step size for mouse movement events.
|
|
| 80 |
*/
|
|
| 81 |
private int m_step = 10; |
|
| 82 |
|
|
| 83 |
/**
|
|
| 84 |
* Constructor.
|
|
| 85 |
*/
|
|
| 86 | 1380 |
protected TestHelper() {
|
| 87 |
} |
|
| 88 |
|
|
| 89 |
/**
|
|
| 90 |
* Get all of the windows we know about including heavy weight
|
|
| 91 |
* popups.
|
|
| 92 |
*
|
|
| 93 |
* @return Window[] All of the windows we know about.
|
|
| 94 |
* @deprecated 2.02 use WindowMonitor.getWindows();
|
|
| 95 |
*/
|
|
| 96 | 0 |
public static Window[] getAllWindows() { |
| 97 | 0 |
return WindowMonitor.getWindows();
|
| 98 |
} |
|
| 99 |
|
|
| 100 |
/**
|
|
| 101 |
* Set the current test case.
|
|
| 102 |
* @param tc TestCase to set as the current test.
|
|
| 103 |
*/
|
|
| 104 | 1338 |
public static void setCurrentTestCase(final JFCTestCase tc) { |
| 105 | 1338 |
s_test = tc; |
| 106 |
} |
|
| 107 |
|
|
| 108 |
/**
|
|
| 109 |
* Get the current test case.
|
|
| 110 |
* @return JFCTestCase which is the current test.
|
|
| 111 |
*/
|
|
| 112 | 0 |
public static JFCTestCase getCurrentTestCase() { |
| 113 | 0 |
return s_test;
|
| 114 |
} |
|
| 115 |
|
|
| 116 |
/**
|
|
| 117 |
* Returns a unmodifiable list of
|
|
| 118 |
* the system window regular expressions.
|
|
| 119 |
*
|
|
| 120 |
* @return unmodifiable Set containing the regular
|
|
| 121 |
* expressions for matching windows.
|
|
| 122 |
*/
|
|
| 123 | 0 |
public static final Set getSystemWindows() { |
| 124 | 0 |
return Collections.unmodifiableSet(s_systemWindows.keySet());
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/**
|
|
| 128 |
* Add a regular expression to match the window titles
|
|
| 129 |
* which should not be closed during cleanup.
|
|
| 130 |
*
|
|
| 131 |
* @param matchTitleRE Regular expression defining the windows
|
|
| 132 |
* which should not be closed.
|
|
| 133 |
* @throws RESyntaxException if the syntax is not a valid Regular expression.
|
|
| 134 |
*/
|
|
| 135 | 1 |
public static final void addSystemWindow(final String matchTitleRE) |
| 136 |
throws RESyntaxException {
|
|
| 137 | 1 |
if (matchTitleRE == null) { |
| 138 | 0 |
return;
|
| 139 |
} |
|
| 140 |
|
|
| 141 | 1 |
RE patternMatcher = new RE(matchTitleRE);
|
| 142 | 1 |
s_systemWindows.put(matchTitleRE, patternMatcher); |
| 143 |
} |
|
| 144 |
|
|
| 145 |
/**
|
|
| 146 |
* Set the key mapping to be used.
|
|
| 147 |
*
|
|
| 148 |
* @param km KeyMapping to be used.
|
|
| 149 |
*/
|
|
| 150 | 7 |
public static void setKeyMapping(final KeyMapping km) { |
| 151 | 7 |
synchronized (LOCK) {
|
| 152 | 7 |
s_keyMapping = km; |
| 153 | 7 |
LOCK.notifyAll(); |
| 154 |
} |
|
| 155 |
} |
|
| 156 |
|
|
| 157 |
/**
|
|
| 158 |
* Get the key mapping to be used.
|
|
| 159 |
*
|
|
| 160 |
* @return the key mapping.
|
|
| 161 |
*/
|
|
| 162 | 2071 |
public static KeyMapping getKeyMapping() { |
| 163 | 2071 |
synchronized (LOCK) {
|
| 164 | 2071 |
if (s_keyMapping == null) { |
| 165 | 7 |
setKeyMapping(new DefaultKeyMapping());
|
| 166 |
} |
|
| 167 |
|
|
| 168 | 2071 |
LOCK.notifyAll(); |
| 169 |
} |
|
| 170 |
|
|
| 171 | 2071 |
return s_keyMapping;
|
| 172 |
} |
|
| 173 |
|
|
| 174 |
/**
|
|
| 175 |
* Returns a set of all the Dialogs that are currently visible for all
|
|
| 176 |
* opened, visible windows - including the special case of the shared, hidden
|
|
| 177 |
* frame which is the owner of JDialogs whose owner is not specified.
|
|
| 178 |
*
|
|
| 179 |
* @return The full list of dialogs.
|
|
| 180 |
* @deprecated 2.05 Use DialogFinder(null).findAll()
|
|
| 181 |
*/
|
|
| 182 | 0 |
public static List getShowingDialogs() { |
| 183 | 0 |
return getShowingDialogs((String) null); |
| 184 |
} |
|
| 185 |
|
|
| 186 |
/**
|
|
| 187 |
* Helper method to obtain a list of the dialogs owned by a given window.
|
|
| 188 |
*
|
|
| 189 |
* @param win The window to find dialogs for.
|
|
| 190 |
* @return The list of dialogs owned by the given window (including the window if it is a Dialog itself).
|
|
| 191 |
* @deprecated 2.05 Use new DialogFinder(null).findAll(win);
|
|
| 192 |
*/
|
|
| 193 | 221 |
public static List getShowingDialogs(final Window win) { |
| 194 | 221 |
return getShowingDialogs(win, null); |
| 195 |
} |
|
| 196 |
|
|
| 197 |
/**
|
|
| 198 |
* Returns a set of all the Dialogs that are currently visible and the title
|
|
| 199 |
* contains the given titlematch string - including the special case of the
|
|
| 200 |
* shared, hidden frame which is the owner of JDialogs whose owner is not specified.
|
|
| 201 |
*
|
|
| 202 |
* @param titlematch The string pattern to search for in the dialog's title.
|
|
| 203 |
* @return The list of dialogs owned by the given window (including the window if it is a Dialog itself).
|
|
| 204 |
* @deprecated 2.05 use new DialogFinder(titlematch).findAll();
|
|
| 205 |
*/
|
|
| 206 | 0 |
public static List getShowingDialogs(final String titlematch) { |
| 207 | 0 |
List openWindows = getWindows(); |
| 208 |
|
|
| 209 |
// We also have to add the shared, hidden frame used by JDialogs which did not
|
|
| 210 |
// have an owner at the beginning
|
|
| 211 | 0 |
openWindows.add((new JDialog()).getOwner());
|
| 212 |
|
|
| 213 | 0 |
Window[] owners = new Window[openWindows.size() + 1];
|
| 214 | 0 |
owners = (Window[]) openWindows.toArray(owners); |
| 215 |
|
|
| 216 | 0 |
return getShowingDialogs(owners, titlematch);
|
| 217 |
} |
|
| 218 |
|
|
| 219 |
/**
|
|
| 220 |
* Returns a set of all the Dialogs that are currently visible and the title
|
|
| 221 |
* contains the given titlematch string.
|
|
| 222 |
*
|
|
| 223 |
* @param win The window to find dialogs for.
|
|
| 224 |
* @param titlematch The string pattern to search for in the dialog's title.
|
|
| 225 |
* @return The list of dialogs owned by the given window (including the window if it is a Dialog itself).
|
|
| 226 |
* @deprecated 2.05 use new DialogFinder(titleMatch).findAll(win);
|
|
| 227 |
*/
|
|
| 228 | 221 |
public static List getShowingDialogs(final Window win, |
| 229 |
final String titlematch) {
|
|
| 230 | 221 |
return getShowingDialogs(
|
| 231 |
new Window[] {win},
|
|
| 232 |
titlematch); |
|
| 233 |
} |
|
| 234 |
|
|
| 235 |
/**
|
|
| 236 |
* Returns a set of all the Dialogs that are currently visible and the title
|
|
| 237 |
* contains the given titlematch string - including the special case of the
|
|
| 238 |
* shared, hidden frame which is the owner of JDialogs whose owner is not specified.
|
|
| 239 |
*
|
|
| 240 |
* @param owners The array of windows to find dialogs for.
|
|
| 241 |
* @param titlematch The string pattern to search for in the dialog's title.
|
|
| 242 |
* @return The list of dialogs owned by the given window (including the window if it is a Dialog itself).
|
|
| 243 |
* @deprecated 2.05 use new DialogFinder(titlematch).findAll(owners);
|
|
| 244 |
*/
|
|
| 245 | 221 |
public static List getShowingDialogs(final Window[] owners, |
| 246 |
final String titlematch) {
|
|
| 247 | 221 |
return getShowingDialogs(
|
| 248 |
new ArrayList(),
|
|
| 249 |
owners, |
|
| 250 |
titlematch); |
|
| 251 |
} |
|
| 252 |
|
|
| 253 |
/**
|
|
| 254 |
* Returns a set of all the Dialogs that are currently visible and the title
|
|
| 255 |
* contains the given titlematch string - including the special case of the
|
|
| 256 |
* shared, hidden frame which is the owner of JDialogs whose owner is not specified.
|
|
| 257 |
*
|
|
| 258 |
* @param ret The list of already filtered and accepted dialogs.
|
|
| 259 |
* @param owners The array of windows to find dialogs for.
|
|
| 260 |
* @param titlematch The string pattern to search for in the dialog's title.
|
|
| 261 |
* @return The list of dialogs owned by the given window (including the window if it is a Dialog itself).
|
|
| 262 |
* @deprecated 2.05 Use new DialogFinder(titlematch).findAll(owners);
|
|
| 263 |
*/
|
|
| 264 | 221 |
public static List getShowingDialogs(final List ret, final Window[] owners, |
| 265 |
final String titlematch) {
|
|
| 266 | 221 |
return getShowingDialogs(
|
| 267 |
ret, |
|
| 268 |
owners, |
|
| 269 |
new DialogFinder(titlematch));
|
|
| 270 |
} |
|
| 271 |
|
|
| 272 |
/**
|
|
| 273 |
* Returns a set of all the Dialogs that are currently visible and the title
|
|
| 274 |
* contains the given titlematch string - including the special case of the
|
|
| 275 |
* shared, hidden frame which is the owner of JDialogs whose owner is not specified.
|
|
| 276 |
*
|
|
| 277 |
* @param ret The list of already filtered and accepted dialogs.
|
|
| 278 |
* @param owners The array of windows to find dialogs for.
|
|
| 279 |
* @param finder The DialogFinder which is used to filter using a title match
|
|
| 280 |
* @return The list of dialogs owned by the given window (including the window if it is a Dialog itself).
|
|
| 281 |
* @deprecated 2.05 use new DialogFinder(null).findAll(owners);
|
|
| 282 |
*/
|
|
| 283 | 469 |
public static List getShowingDialogs(final List ret, final Window[] owners, |
| 284 |
final Finder finder) {
|
|
| 285 | 469 |
List arr; |
| 286 |
|
|
| 287 | 469 |
if (ret == null) { |
| 288 | 0 |
arr = new ArrayList();
|
| 289 |
} else {
|
|
| 290 | 469 |
arr = ret; |
| 291 |
} |
|
| 292 |
|
|
| 293 | 469 |
if ((owners == null) || (finder == null)) { |
| 294 | 0 |
return arr;
|
| 295 |
} |
|
| 296 |
|
|
| 297 | 469 |
for (int i = 0; i < owners.length; i++) { |
| 298 | 248 |
if (owners[i] == null) { |
| 299 | 0 |
continue;
|
| 300 |
} |
|
| 301 |
|
|
| 302 | 248 |
if (finder.testComponent(owners[i])
|
| 303 |
&& !ret.contains(owners[i])) {
|
|
| 304 | 10 |
arr.add(owners[i]); |
| 305 |
} |
|
| 306 |
|
|
| 307 | 248 |
getShowingDialogs( |
| 308 |
arr, |
|
| 309 |
owners[i].getOwnedWindows(), |
|
| 310 |
finder); |
|
| 311 |
} |
|
| 312 |
|
|
| 313 | 469 |
return arr;
|
| 314 |
} |
|
| 315 |
|
|
| 316 |
/**
|
|
| 317 |
* Returns a set of all the Windows that are currently visible based on the
|
|
| 318 |
* Finder being passed in.
|
|
| 319 |
*
|
|
| 320 |
* @param finder The AbstractWindowFinder which is used to filter
|
|
| 321 |
* @return Set of Window objects.
|
|
| 322 |
* @deprecated 2.05 use finder.findAll();
|
|
| 323 |
*/
|
|
| 324 | 65 |
public static List getWindows(final AbstractWindowFinder finder) { |
| 325 | 65 |
return finder.findAll();
|
| 326 |
} |
|
| 327 |
|
|
| 328 |
/**
|
|
| 329 |
* Returns a set of all the Windows that are currently visible and the title
|
|
| 330 |
* contains the given titlematch string.
|
|
| 331 |
*
|
|
| 332 |
* @param ret The list of already filtered and accepted windows.
|
|
| 333 |
* @param windows The array of windows to filter and add.
|
|
| 334 |
* @param titlematch The string pattern to search for in the window's title.
|
|
| 335 |
* @return Set of Window objects.
|
|
| 336 |
* @deprecated 2.05 use new FrameFinder(titlematch).findAll();
|
|
| 337 |
*/
|
|
| 338 | 0 |
public static List getWindows(final List ret, final Window[] windows, |
| 339 |
final String titlematch) {
|
|
| 340 | 0 |
return getWindows(
|
| 341 |
ret, |
|
| 342 |
windows, |
|
| 343 |
new FrameFinder(titlematch));
|
|
| 344 |
} |
|
| 345 |
|
|
| 346 |
/**
|
|
| 347 |
* Returns a set of all the Windows that are currently visible and the title
|
|
| 348 |
* contains the given titlematch string.
|
|
| 349 |
*
|
|
| 350 |
* @param ret The list of already filtered and accepted windows.
|
|
| 351 |
* @param windows The array of windows to filter and add.
|
|
| 352 |
* @param finder The FrameFinder which is used to filter using a title match
|
|
| 353 |
* @return Set of Window objects.
|
|
| 354 |
* @deprecated 2.05 use finder.findAll(windows);
|
|
| 355 |
*/
|
|
| 356 | 0 |
public static List getWindows(final List ret, final Window[] windows, |
| 357 |
final Finder finder) {
|
|
| 358 | 0 |
return AbstractWindowFinder.getWindows(ret, windows, finder);
|
| 359 |
} |
|
| 360 |
|
|
| 361 |
/**
|
|
| 362 |
* Calculate the next point along the path to the
|
|
| 363 |
* destingation point.
|
|
| 364 |
*
|
|
| 365 |
* @param src Source point.
|
|
| 366 |
* @param dest Dest point.
|
|
| 367 |
* @param step Number of pixels to step.
|
|
| 368 |
* @return src point.
|
|
| 369 |
*/
|
|
| 370 | 31509 |
public static Point calcNextPoint(final Point src, final Point dest, |
| 371 |
final int step) {
|
|
| 372 | 31509 |
Point dir = new Point(
|
| 373 |
getDir(src.x, dest.x), |
|
| 374 |
getDir(src.y, dest.y)); |
|
| 375 |
|
|
| 376 | 31509 |
if (isBounded(src.x + (dir.x * step), dest.x, src.x)) {
|
| 377 | 13515 |
dir.x = (dir.x * step); |
| 378 |
} |
|
| 379 |
|
|
| 380 | 31509 |
if (isBounded(src.y + (dir.y * step), dest.y, src.y)) {
|
| 381 | 6945 |
dir.y = dir.y * step; |
| 382 |
} |
|
| 383 |
|
|
| 384 | 31509 |
dir.translate(src.x, src.y); |
| 385 |
|
|
| 386 | 31509 |
return dir;
|
| 387 |
} |
|
| 388 |
|
|
| 389 |
/**
|
|
| 390 |
* This method is used to clean up any existing open windows, etc
|
|
| 391 |
* if ase lettersa test fails midway. To be called in the tearDown() method.
|
|
| 392 |
*
|
|
| 393 |
* @param testCase The test case that is firing the event.
|
|
| 394 |
* @see #addSystemWindow
|
|
| 395 |
* @see #removeSystemWindow
|
|
| 396 |
* @see #removeAllSystemWindows
|
|
| 397 |
*/
|
|
| 398 | 26 |
public static void cleanUp(final JFCTestCase testCase) { |
| 399 | 26 |
cleanUp(testCase, DEFAULTSLEEP); |
| 400 |
} |
|
| 401 |
|
|
| 402 |
/**
|
|
| 403 |
* This method is used to clean up any existing open windows, etc
|
|
| 404 |
* if a test fails midway. To be called in the tearDown() method.
|
|
| 405 |
*
|
|
| 406 |
* @param testCase The test case that is firing the event.
|
|
| 407 |
* @param awtSleepTime
|
|
| 408 |
* The wait time in ms between each event.
|
|
| 409 |
*/
|
|
| 410 | 26 |
public static void cleanUp(final JFCTestCase testCase, |
| 411 |
final long awtSleepTime) {
|
|
| 412 | 26 |
Iterator iter = getWindows().iterator(); |
| 413 |
|
|
| 414 | 26 |
while (iter.hasNext()) {
|
| 415 | 21 |
boolean ignore = false; |
| 416 | 21 |
Window w = (Window) iter.next(); |
| 417 | 21 |
String title = null;
|
| 418 |
|
|
| 419 | 21 |
if (w instanceof java.awt.Dialog) { |
| 420 | 0 |
title = ((java.awt.Dialog) w).getTitle(); |
| 421 | 21 |
} else if (w instanceof Frame) { |
| 422 | 21 |
title = ((java.awt.Frame) w).getTitle(); |
| 423 |
} |
|
| 424 |
|
|
| 425 | 21 |
if (title != null) { |
| 426 | 21 |
Iterator sw = s_systemWindows.values().iterator(); |
| 427 |
|
|
| 428 | 21 |
while (sw.hasNext() && !ignore) {
|
| 429 | 10 |
RE re = (RE) sw.next(); |
| 430 |
|
|
| 431 | 10 |
if (re.match(title)) {
|
| 432 | 1 |
ignore = true;
|
| 433 |
} |
|
| 434 |
} |
|
| 435 |
} |
|
| 436 |
|
|
| 437 | 21 |
if (!ignore) {
|
| 438 | 20 |
disposeWindow(w, testCase, awtSleepTime); |
| 439 |
} |
|
| 440 |
} |
|
| 441 |
} |
|
| 442 |
|
|
| 443 |
/**
|
|
| 444 |
* This method does the actual work of destroying the window.
|
|
| 445 |
*
|
|
| 446 |
* @param window The window that needs to be destroyed.
|
|
| 447 |
* @param testCase The test case that is firing the event.
|
|
| 448 |
*/
|
|
| 449 | 392 |
public static void disposeWindow(final Window window, |
| 450 |
final JFCTestCase testCase) {
|
|
| 451 | 392 |
disposeWindow(window, testCase, DEFAULTSLEEP); |
| 452 |
} |
|
| 453 |
|
|
| 454 |
/**
|
|
| 455 |
* This method does the actual work of destroying the window and any dialogs that it owns.
|
|
| 456 |
*
|
|
| 457 |
* @param window The window that needs to be destroyed.
|
|
| 458 |
* @param testCase The test case that is firing the event.
|
|
| 459 |
* @param awtSleepTime
|
|
| 460 |
* The wait time in ms between each event.
|
|
| 461 |
*/
|
|
| 462 | 422 |
public static void disposeWindow(final Window window, |
| 463 |
final JFCTestCase testCase, final long awtSleepTime) {
|
|
| 464 | 422 |
if (window != null) { |
| 465 |
// need to leave the AWTThread in the same state that is in at the end
|
|
| 466 | 259 |
boolean awt = testCase.isAWTRunning();
|
| 467 |
|
|
| 468 | 259 |
if (awt) {
|
| 469 | 249 |
testCase.pauseAWT(); |
| 470 |
} |
|
| 471 |
|
|
| 472 | 259 |
try {
|
| 473 | 259 |
if (!(window instanceof JDialog)) { |
| 474 |
// dispose of any showing dialogs first
|
|
| 475 | 221 |
List dialogs = getShowingDialogs(window); |
| 476 |
|
|
| 477 | 221 |
for (int i = 0; i < dialogs.size(); i++) { |
| 478 | 10 |
disposeWindow((JDialog) dialogs.get(i), testCase, |
| 479 |
awtSleepTime); |
|
| 480 |
} |
|
| 481 |
} |
|
| 482 |
|
|
| 483 | 259 |
window.setVisible(false);
|
| 484 |
|
|
| 485 |
// try to clear the event queue
|
|
| 486 | 259 |
testCase.flushAWT(); |
| 487 |
|
|
| 488 | 259 |
if (!awt) {
|
| 489 | 10 |
testCase.pauseAWT(); |
| 490 |
} |
|
| 491 |
|
|
| 492 | 259 |
try {
|
| 493 | 259 |
window.getToolkit().getSystemEventQueue().postEvent( |
| 494 |
new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
|
|
| 495 |
} catch (ExitException exe) {
|
|
| 496 |
; // don't do anything here
|
|
| 497 |
} |
|
| 498 |
} finally {
|
|
| 499 |
// somehow, this sleeptime needs to be set after the first flush
|
|
| 500 | 259 |
testCase.setSleepTime(awtSleepTime); |
| 501 |
|
|
| 502 |
// try to clear the event queue
|
|
| 503 | 259 |
testCase.flushAWT(); |
| 504 |
|
|
| 505 | 258 |
if (!awt) {
|
| 506 | 10 |
testCase.pauseAWT(); |
| 507 |
} |
|
| 508 |
|
|
| 509 | 258 |
testCase.awtSleep(); |
| 510 |
} |
|
| 511 |
} |
|
| 512 |
} |
|
| 513 |
|
|
| 514 |
/**
|
|
| 515 |
* Remove all System Window regular expressions.
|
|
| 516 |
*/
|
|
| 517 | 2 |
public static final void removeAllSystemWindows() { |
| 518 | 2 |
s_systemWindows.clear(); |
| 519 |
} |
|
| 520 |
|
|
| 521 |
/**
|
|
| 522 |
* Remove a regular expression to match the window titles
|
|
| 523 |
* which should not be closed during cleanup.
|
|
| 524 |
*
|
|
| 525 |
* @param matchTitleRE Regular expression defining the windows
|
|
| 526 |
* which should not be closed.
|
|
| 527 |
*/
|
|
| 528 | 1 |
public static final void removeSystemWindow(final String matchTitleRE) { |
| 529 | 1 |
s_systemWindows.remove(matchTitleRE); |
| 530 |
} |
|
| 531 |
|
|
| 532 |
/**
|
|
| 533 |
* A helper method to find the message being displayed in a dialog box.
|
|
| 534 |
*
|
|
| 535 |
* @param dialog The dialog box displaying the message
|
|
| 536 |
* @return The messagebeing displayed
|
|
| 537 |
*/
|
|
| 538 | 1 |
public String getMessageFromJDialog(final JDialog dialog) {
|
| 539 | 1 |
if ((dialog == null) || !dialog.isShowing()) { |
| 540 | 0 |
return null; |
| 541 |
} |
|
| 542 |
|
|
| 543 |
// since there are usually 2 JLabels, use a sufficiently high number ---> 10
|
|
| 544 | 1 |
List list = Finder.findComponentList( |
| 545 |
new ComponentFinder(JLabel.class), |
|
| 546 |
dialog, |
|
| 547 |
new ArrayList(),
|
|
| 548 |
10); |
|
| 549 | 1 |
JLabel label; |
| 550 |
|
|
| 551 | 1 |
for (int i = 0; i < list.size(); i++) { |
| 552 | 1 |
label = (JLabel) list.get(i); |
| 553 |
|
|
| 554 | 1 |
if ((label != null) && (label.getText() != null)) { |
| 555 | 1 |
return label.getText();
|
| 556 |
} |
|
| 557 |
} |
|
| 558 |
|
|
| 559 | 0 |
return null; |
| 560 |
} |
|
| 561 |
|
|
| 562 |
/**
|
|
| 563 |
* Returns a single window that is showing with given string in the title.
|
|
| 564 |
* If there is more than one window that match, then it is undefined which
|
|
| 565 |
* one will be returned.
|
|
| 566 |
*
|
|
| 567 |
* @param title The string that should be present in the title.
|
|
| 568 |
* @return A showing window with the given title pattern.
|
|
| 569 |
* @deprecated 2.02 use new FrameFinder(title).getWindow
|
|
| 570 |
*/
|
|
| 571 | 0 |
public static Window getWindow(final String title) { |
| 572 | 0 |
return getWindow(new FrameFinder(title)); |
| 573 |
} |
|
| 574 |
|
|
| 575 |
/**
|
|
| 576 |
* Returns a single window that is showing that passes the filtration by the Finder passed in.
|
|
| 577 |
* If there is more than one window that match, then it is undefined which
|
|
| 578 |
* one will be returned.
|
|
| 579 |
*
|
|
| 580 |
* @param finder The AbstractWindowFinder which is used to filter
|
|
| 581 |
* @return A showing window with the given title.
|
|
| 582 |
*/
|
|
| 583 | 8 |
public static Window getWindow(final AbstractWindowFinder finder) { |
| 584 | 8 |
Iterator iter = getWindows(finder).iterator(); |
| 585 |
|
|
| 586 | 8 |
if (!iter.hasNext()) {
|
| 587 | 2 |
return null; |
| 588 |
} |
|
| 589 |
|
|
| 590 | 6 |
return (Window) iter.next();
|
| 591 |
} |
|
| 592 |
|
|
| 593 |
/**
|
|
| 594 |
* Returns a set of all the Windows that are currently visible.
|
|
| 595 |
*
|
|
| 596 |
* @return Set of Window objects.
|
|
| 597 |
*/
|
|
| 598 | 52 |
public static List getWindows() { |
| 599 | 52 |
FrameFinder f = new FrameFinder(null); |
| 600 | 52 |
f.setWait(1); |
| 601 |
|
|
| 602 | 52 |
return getWindows(f);
|
| 603 |
} |
|
| 604 |
|
|
| 605 |
/**
|
|
| 606 |
* Returns a set of all the Windows that are currently visible and the title
|
|
| 607 |
* contains the given titlematch string.
|
|
| 608 |
*
|
|
| 609 |
* @param titlematch The string pattern to search for in the window's title.
|
|
| 610 |
* @return Set of Window objects.
|
|
| 611 |
*/
|
|
| 612 | 5 |
public static List getWindows(final String titlematch) { |
| 613 | 5 |
return getWindows(new FrameFinder(titlematch)); |
| 614 |
} |
|
| 615 |
|
|
| 616 |
/**
|
|
| 617 |
* Finds a JFileChooser being shown by a window.
|
|
| 618 |
*
|
|
| 619 |
* @param win The window to owning the chooser.
|
|
| 620 |
* @return The chooser that has been found, or null if there are none.
|
|
| 621 |
* @deprecated 2.05 use JFileChooserFinder(null).find(win, 0);
|
|
| 622 |
*/
|
|
| 623 | 0 |
public JFileChooser getShowingJFileChooser(final Window win) {
|
| 624 | 0 |
List choosers = getShowingJFileChoosers(win); |
| 625 |
|
|
| 626 | 0 |
if (choosers.isEmpty()) {
|
| 627 | 0 |
return null; |
| 628 |
} |
|
| 629 |
|
|
| 630 | 0 |
return (JFileChooser) choosers.get(0);
|
| 631 |
} |
|
| 632 |
|
|
| 633 |
/**
|
|
| 634 |
* Finds a list of all the JFileChoosers being shown by a window.
|
|
| 635 |
*
|
|
| 636 |
* @param win The window to owning the chooser.
|
|
| 637 |
* @return The list of JFileChoosers.
|
|
| 638 |
* @deprecated 2.05 use JFileChooserFinder(null).findAl(win);
|
|
| 639 |
*/
|
|
| 640 | 0 |
public List getShowingJFileChoosers(final Window win) {
|
| 641 | 0 |
List ret = new ArrayList();
|
| 642 | 0 |
List subComps; |
| 643 | 0 |
JFileChooser chooser; |
| 644 |
|
|
| 645 | 0 |
Window[] owned = win.getOwnedWindows(); |
| 646 | 0 |
Finder finder = new ComponentFinder(JFileChooser.class); |
| 647 |
|
|
| 648 | 0 |
for (int i = 0; i < owned.length; i++) { |
| 649 | 0 |
if (!(owned[i] instanceof JDialog)) { |
| 650 | 0 |
continue;
|
| 651 |
} |
|
| 652 |
|
|
| 653 | 0 |
subComps = Finder.findComponentList( |
| 654 |
finder, |
|
| 655 |
owned[i], |
|
| 656 |
new ArrayList(),
|
|
| 657 |
0); |
|
| 658 |
|
|
| 659 | 0 |
Iterator iter = subComps.iterator(); |
| 660 |
|
|
| 661 | 0 |
while (iter.hasNext()) {
|
| 662 | 0 |
chooser = (JFileChooser) iter.next(); |
| 663 |
|
|
| 664 | 0 |
if (finder.testComponent(chooser)) {
|
| 665 | 0 |
ret.add(chooser); |
| 666 |
} |
|
| 667 |
} |
|
| 668 |
} |
|
| 669 |
|
|
| 670 | 0 |
return ret;
|
| 671 |
} |
|
| 672 |
|
|
| 673 |
/**
|
|
| 674 |
* Finds a component which is an instance of the given class by
|
|
| 675 |
* searching from all top level windows.
|
|
| 676 |
*
|
|
| 677 |
* @param compCls Component class
|
|
| 678 |
* @param index The index of the component. The first component matching the
|
|
| 679 |
* criteria will have index 0, the second 1, etc.
|
|
| 680 |
* @return Component Component found. Null if index components
|
|
| 681 |
* do not exist.
|
|
| 682 |
* @deprecated 2.02 Use new ComponentFinder(aClass).find(index);
|
|
| 683 |
*/
|
|
| 684 | 0 |
public static Component findComponent(final Class compCls, final int index) { |
| 685 | 0 |
return new ComponentFinder(compCls).find(index); |
| 686 |
} |
|
| 687 |
|
|
| 688 |
/**
|
|
| 689 |
* Finds a component which is an instance of the given class within a given
|
|
| 690 |
* container.
|
|
| 691 |
*
|
|
| 692 |
* @param compCls The class of the component.
|
|
| 693 |
* @param cont The container that the component will be in.
|
|
| 694 |
* @param index The index of the component. The first component matching the
|
|
| 695 |
* criteria will have index 0, the second 1, etc.
|
|
| 696 |
* @return The component that has been found (or null if none found).
|
|
| 697 |
* @deprecated 2.02 Use new ComponentFinder(compCls).find(cont, index);
|
|
| 698 |
*/
|
|
| 699 | 0 |
public static Component findComponent(final Class compCls, |
| 700 |
final Container cont, final int index) {
|
|
| 701 | 0 |
return new ComponentFinder(compCls).find(cont, index); |
| 702 |
} |
|
| 703 |
|
|
| 704 |
/**
|
|
| 705 |
* Finds a component which is an instance of the given class by
|
|
| 706 |
* searching from all top level windows.
|
|
| 707 |
*
|
|
| 708 |
* @param finder Finder class to be used for locating components.
|
|
| 709 |
* @param index The index of the component. The first component matching the
|
|
| 710 |
* criteria will have index 0, the second 1, etc.
|
|
| 711 |
* @return Component Component found. Null if index components
|
|
| 712 |
* do not exist.
|
|
| 713 |
* @deprecated 2.02 Use finder.find(index);
|
|
| 714 |
*/
|
|
| 715 | 0 |
public static Component findComponent(final Finder finder, final int index) { |
| 716 | 0 |
return (Component) finder.find(index);
|
| 717 |
} |
|
| 718 |
|
|
| 719 |
/**
|
|
| 720 |
* Finds a component matching the given criteria within a given container.
|
|
| 721 |
*
|
|
| 722 |
* @param finder The Finder that is used to test components for a
|
|
| 723 |
* match.
|
|
| 724 |
* @param cont The container that the component will be in.
|
|
| 725 |
* @param index The index of the component. The first component matching the
|
|
| 726 |
* criteria will have index 0, the second 1, etc.
|
|
| 727 |
* @return The component that has been found (or null if none found).
|
|
| 728 |
* @deprecated 2.02 use finder.find(cont, index);
|
|
| 729 |
*/
|
|
| 730 | 0 |
public static Component findComponent(final Finder finder, |
| 731 |
final Container cont, final int index) {
|
|
| 732 | 0 |
return finder.find(cont, index);
|
| 733 |
} |
|
| 734 |
|
|
| 735 |
/**
|
|
| 736 |
* Finds a component which is an instance of the given class by
|
|
| 737 |
* searching from all top level windows.
|
|
| 738 |
*
|
|
| 739 |
* @param compCls Component class
|
|
| 740 |
* @param index The index of the component. The first component matching the
|
|
| 741 |
* criteria will have index 0, the second 1, etc.
|
|
| 742 |
* @return Component Component found. Null if index components
|
|
| 743 |
* do not exist.
|
|
| 744 |
* @deprecated 2.02 Use new ComponentFinder(compCls).find(cont, index);
|
|
| 745 |
*/
|
|
| 746 | 0 |
public static Component findNamedComponent(final Class compCls, |
| 747 |
final int index) {
|
|
| 748 | 0 |
return new NamedComponentFinder(compCls, null).find(index); |
| 749 |
} |
|
| 750 |
|
|
| 751 |
/**
|
|
| 752 |
* Finds a indexed component which has the given name by
|
|
| 753 |
* searching from all top level windows.
|
|
| 754 |
*
|
|
| 755 |
* @param name The pattern for the name of the component to find.
|
|
| 756 |
* @param index The index of the component. The first component matching the
|
|
| 757 |
* criteria will have index 0, the second 1, etc.
|
|
| 758 |
* @return Component Component found. Null if index components
|
|
| 759 |
* do not exist.
|
|
| 760 |
* @deprecated 2.02 Use new NamedComponentFinder(null,name).find(index);
|
|
| 761 |
*/
|
|
| 762 | 0 |
public static Component findNamedComponent(final String name, |
| 763 |
final int index) {
|
|
| 764 | 0 |
return new NamedComponentFinder(null, name).find(index); |
| 765 |
} |
|
| 766 |
|
|
| 767 |
/**
|
|
| 768 |
* Finds a component which is an instance of the given class
|
|
| 769 |
* and has the given name by searching from all top level windows.
|
|
| 770 |
*
|
|
| 771 |
* @param compCls Component class
|
|
| 772 |
* @param name The pattern for the name of the component to find.
|
|
| 773 |
* @param index The index of the component. The first component matching the
|
|
| 774 |
* criteria will have index 0, the second 1, etc.
|
|
| 775 |
* @return Component Component found. Null if index components
|
|
| 776 |
* do not exist.
|
|
| 777 |
* @deprecated 2.02 Use new NamedComponentFinder(compCls, name).find(index);
|
|
| 778 |
*/
|
|
| 779 | 0 |
public static Component findNamedComponent(final Class compCls, |
| 780 |
final String name, final int index) {
|
|
| 781 | 0 |
return new NamedComponentFinder(compCls, name).find(index); |
| 782 |
} |
|
| 783 |
|
|
| 784 |
/**
|
|
| 785 |
* Finds a component matching the given criteria within a given container.
|
|
| 786 |
*
|
|
| 787 |
* @param name The pattern for the name of the component to find.
|
|
| 788 |
* @param cont The container that the component will be in.
|
|
| 789 |
* @param index The index of the component. The first component matching the
|
|
| 790 |
* criteria will have index 0, the second 1, etc.
|
|
| 791 |
* @return The component that has been found (or null if none found).
|
|
| 792 |
* @deprecated 2.02 Use new NamedComponentFinder(null, name).find(cont, index);
|
|
| 793 |
*/
|
|
| 794 | 0 |
public static Component findNamedComponent(final String name, |
| 795 |
final Container cont, final int index) {
|
|
| 796 | 0 |
return findNamedComponent(null, name, cont, index); |
| 797 |
} |
|
| 798 |
|
|
| 799 |
/**
|
|
| 800 |
* Finds a component matching the given criteria within a given container.
|
|
| 801 |
*
|
|
| 802 |
* @param aClass The component's class.
|
|
| 803 |
* @param cont The container that the component will be in.
|
|
| 804 |
* @param index The index of the component. The first component matching the
|
|
| 805 |
* criteria will have index 0, the second 1, etc.
|
|
| 806 |
* @return The component that has been found (or null if none found).
|
|
| 807 |
* @deprecated 2.02 Use new NamedComponentFinder(aClass, null).find(cont, index);
|
|
| 808 |
*/
|
|
| 809 | 0 |
public static Component findNamedComponent(final Class aClass, |
| 810 |
final Container cont, final int index) {
|
|
| 811 | 0 |
return findNamedComponent(aClass, null, cont, index); |
| 812 |
} |
|
| 813 |
|
|
| 814 |
/**
|
|
| 815 |
* Finds a component matching the given criteria within a given container.
|
|
| 816 |
*
|
|
| 817 |
* @param aClass The component's class.
|
|
| 818 |
* @param name The pattern for the name of the component to find.
|
|
| 819 |
* @param cont The container that the component will be in.
|
|
| 820 |
* @param index The index of the component. The first component matching the
|
|
| 821 |
* criteria will have index 0, the second 1, etc.
|
|
| 822 |
* @return The component that has been found (or null if none found).
|
|
| 823 |
* @deprecated 2.02 Use new NamedComponentFinder(aClass, name).find(cont, index);
|
|
| 824 |
*/
|
|
| 825 | 0 |
public static Component findNamedComponent(final Class aClass, |
| 826 |
final String name, final Container cont, final int index) {
|
|
| 827 | 0 |
return new NamedComponentFinder(aClass, name).find(cont, index); |
| 828 |
} |
|
| 829 |
|
|
| 830 |
/**
|
|
| 831 |
* Find the index of the component given.
|
|
| 832 |
* @param finder Finder used for indexing.
|
|
| 833 |
* @param cont Container to look for the component in.
|
|
| 834 |
* @param comp Component to find the index of.
|
|
| 835 |
* @return Index of the component
|
|
| 836 |
*/
|
|
| 837 | 0 |
public static int indexOf(final Finder finder, final Container cont, |
| 838 |
final Component comp) {
|
|
| 839 | 0 |
Container[] containers = null;
|
| 840 |
|
|
| 841 | 0 |
if (cont != null) { |
| 842 | 0 |
if (!cont.isShowing()) {
|
| 843 | 0 |
finder.setIgnoreVisibility(true);
|
| 844 |
} |
|
| 845 |
|
|
| 846 | 0 |
containers = new Container[] {cont};
|
| 847 |
} else {
|
|
| 848 | 0 |
containers = getAllWindows(); |
| 849 |
} |
|
| 850 |
|
|
| 851 | 0 |
int index = 0;
|
| 852 |
|
|
| 853 | 0 |
for (int i = 0; i < containers.length; i++) { |
| 854 | 0 |
List list = Finder.findComponentList( |
| 855 |
finder, |
|
| 856 |
containers[i], |
|
| 857 |
new ArrayList(),
|
|
| 858 |
999); |
|
| 859 |
|
|
| 860 | 0 |
if (list.contains(comp)) {
|
| 861 | 0 |
return index + list.indexOf(comp);
|
| 862 |
} else {
|
|
| 863 | 0 |
index += list.size(); |
| 864 |
} |
|
| 865 |
} |
|
| 866 |
|
|
| 867 | 0 |
return -1;
|
| 868 |
} |
|
| 869 |
|
|
| 870 |
/**
|
|
| 871 |
* Set the step size of mouse move events.
|
|
| 872 |
* @param step size in pixels.
|
|
| 873 |
*/
|
|
| 874 | 1 |
public void setStep(final int step) { |
| 875 | 1 |
this.m_step = step;
|
| 876 |
} |
|
| 877 |
|
|
| 878 |
/**
|
|
| 879 |
* Returns the step size for the move events.
|
|
| 880 |
* @return int size in pixels.
|
|
| 881 |
*/
|
|
| 882 | 31457 |
public int getStep() { |
| 883 | 31457 |
return m_step;
|
| 884 |
} |
|
| 885 |
|
|
| 886 |
/**
|
|
| 887 |
* Helper method to fire appropriate events to click(s) a component with a
|
|
| 888 |
* custom wait method.
|
|
| 889 |
*
|
|
| 890 |
* @param evtData The event data container
|
|
| 891 |
*/
|
|
| 892 | 1468 |
public void enterClickAndLeave(final AbstractMouseEventData evtData) { |
| 893 | 1468 |
if (evtData == null) { |
| 894 | 3 |
return;
|
| 895 |
} |
|
| 896 |
|
|
| 897 | 1465 |
evtData.getTestCase().pauseAWT(); |
| 898 |
|
|
| 899 | 1465 |
if (!evtData.prepareComponent()) {
|
| 900 | 156 |
evtData.getTestCase().resumeAWT(); |
| 901 |
|
|
| 902 | 156 |
return;
|
| 903 |
} |
|
| 904 |
|
|
| 905 | 1309 |
evtData.getTestCase().resumeAWT(); |
| 906 |
|
|
| 907 | 1309 |
int numberOfClicks = evtData.getNumberOfClicks();
|
| 908 | 1309 |
int modifiers = evtData.getModifiers();
|
| 909 | 1309 |
boolean isPopupTrigger = evtData.getPopupTrigger();
|
| 910 |
|
|
| 911 | 1309 |
Component ultimate = evtData.getRoot(); |
| 912 |
|
|
| 913 |
// try to clear the event queue
|
|
| 914 | 1309 |
evtData.getTestCase().flushAWT(); |
| 915 |
|
|
| 916 |
// Translate the screen coordinates returned by the event to frame coordinates.
|
|
| 917 | 1309 |
Point screen = evtData.getLocationOnScreen(); |
| 918 | 1309 |
pressModifiers( |
| 919 |
ultimate, |
|
| 920 |
mouseToKeyModifiers(modifiers)); |
|
| 921 |
|
|
| 922 |
// Insure a move event.
|
|
| 923 | 1309 |
mouseMoved(ultimate, screen.x - 5, screen.y - 5); |
| 924 | 1309 |
mouseMoved(ultimate, screen.x, screen.y); |
| 925 |
|
|
| 926 | 1309 |
for (int click = 1; click <= numberOfClicks; click++) { |
| 927 | 1572 |
mousePressed(ultimate, modifiers, click, isPopupTrigger); |
| 928 | 1572 |
mouseReleased(ultimate, modifiers, click, isPopupTrigger); |
| 929 |
} |
|
| 930 |
|
|
| 931 | 1309 |
releaseModifiers( |
| 932 |
ultimate, |
|
| 933 |
mouseToKeyModifiers(modifiers)); |
|
| 934 |
|
|
| 935 |
// try to clear the event queue
|
|
| 936 | 1309 |
evtData.getTestCase().flushAWT(); |
| 937 |
} |
|
| 938 |
|
|
| 939 |
/**
|
|
| 940 |
* Helper method to fire appropriate events to drag and drop a component with a
|
|
| 941 |
* custom wait method.
|
|
| 942 |
*
|
|
| 943 |
* Note this will not work with java.awt.dnd API implementations.
|
|
| 944 |
* The java.awt.dnd implementation is driven from a level below the
|
|
| 945 |
* AWT EventQueue. Use the RobotTestHelper to work with java.awt.dnd.
|
|
| 946 |
*
|
|
| 947 |
* @param srcEvtData The source event data container
|
|
| 948 |
* @param dstEvtData The destination event data container
|
|
| 949 |
* @param incr Amount to increment the coords while "moving" from
|
|
| 950 |
* source to destination.
|
|
| 951 |
*/
|
|
| 952 | 1 |
public void enterDragAndLeave(final AbstractMouseEventData srcEvtData, |
| 953 |
final AbstractMouseEventData dstEvtData, final int incr) {
|
|
| 954 | 1 |
DragEventData ded = new DragEventData(
|
| 955 |
srcEvtData.getTestCase(), |
|
| 956 |
srcEvtData, |
|
| 957 |
dstEvtData); |
|
| 958 | 1 |
setStep(incr); |
| 959 | 1 |
enterDragAndLeave(ded); |
| 960 |
} |
|
| 961 |
|
|
| 962 |
/**
|
|
| 963 |
* Helper method to fire appropriate events to drag and drop a component with a
|
|
| 964 |
* custom wait method.
|
|
| 965 |
*
|
|
| 966 |
* Note this will not work with java.awt.dnd API implementations.
|
|
| 967 |
* The java.awt.dnd implementation is driven from a level below the
|
|
| 968 |
* AWT EventQueue. Use the RobotTestHelper to work with java.awt.dnd.
|
|
| 969 |
*
|
|
| 970 |
* @param ded The destination event data container
|
|
| 971 |
*/
|
|
| 972 | 84 |
public void enterDragAndLeave(final DragEventData ded) { |
| 973 |
// Is component 2 to be visible from the get go.
|
|
| 974 |
// It may not be if autoScrolling is to take place.
|
|
| 975 |
// If autoScrolling then when do we adjust the screen?
|
|
| 976 |
// How do we calculate the target X/Y?
|
|
| 977 |
// For now we will prepare the second component and
|
|
| 978 |
// attempt to insure visibility
|
|
| 979 | 84 |
ded.getTestCase().pauseAWT(); |
| 980 |
|
|
| 981 | 84 |
if (!ded.prepareComponent()) {
|
| 982 | 0 |
ded.getTestCase().resumeAWT(); |
| 983 |
|
|
| 984 | 0 |
return;
|
| 985 |
} |
|
| 986 |
|
|
| 987 | 84 |
ded.getTestCase().resumeAWT(); |
| 988 |
|
|
| 989 | 84 |
int numberOfClicks = ded.getSource().getNumberOfClicks();
|
| 990 | 84 |
int modifiers = ded.getSource().getModifiers();
|
| 991 | 84 |
int keyModifiers = mouseToKeyModifiers(modifiers);
|
| 992 | 84 |
int mouseButtonMask = modifiers
|
| 993 |
& (InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK |
|
| 994 |
| InputEvent.BUTTON3_MASK); |
|
| 995 | 84 |
boolean isPopupTrigger = ded.getSource().getPopupTrigger();
|
| 996 |
|
|
| 997 | 84 |
Component ultimate = ded.getSource().getComponent(); |
| 998 | 84 |
Point p = ded.getSource().getLocationOnScreen(); |
| 999 |
|
|
| 1000 |
// try to clear the event queue
|
|
| 1001 | 84 |
ded.getTestCase().flushAWT(); |
| 1002 |
|
|
| 1003 | 84 |
mouseMoved(ultimate, p.x - 5, p.y - 5); |
| 1004 | 84 |
mouseMoved(ultimate, p.x, p.y); |
| 1005 | 84 |
pressModifiers(ultimate, keyModifiers); |
| 1006 | 84 |
mousePressed(ultimate, mouseButtonMask, 0, isPopupTrigger); |
| 1007 |
|
|
| 1008 | 84 |
Point[] pts = ded.getPoints(); |
| 1009 |
|
|
| 1010 | 84 |
for (int i = 0; i < pts.length; i++) { |
| 1011 | 168 |
mouseMoved(ultimate, pts[i].x, pts[i].y); |
| 1012 |
} |
|
| 1013 |
|
|
| 1014 | 84 |
mouseReleased(ultimate, mouseButtonMask, numberOfClicks, isPopupTrigger); |
| 1015 | 84 |
releaseModifiers(ultimate, keyModifiers); |
| 1016 |
|
|
| 1017 |
// try to clear the event queue
|
|
| 1018 | 84 |
ded.getTestCase().flushAWT(); |
| 1019 |
} |
|
| 1020 |
|
|
| 1021 |
/**
|
|
| 1022 |
* Enter a mouseWheel event.
|
|
| 1023 |
*
|
|
| 1024 |
* @param evtData MouseWheelEventData to be processed.
|
|
| 1025 |
*/
|
|
| 1026 | 18 |
public void enterMouseWheel(final MouseWheelEventData evtData) { |
| 1027 | 18 |
if (evtData == null) { |
| 1028 | 0 |
return;
|
| 1029 |
} |
|
| 1030 |
|
|
| 1031 | 18 |
evtData.getTestCase().pauseAWT(); |
| 1032 |
|
|
| 1033 | 18 |
if (!evtData.prepareComponent()) {
|
| 1034 | 0 |
evtData.getTestCase().resumeAWT(); |
| 1035 |
|
|
| 1036 | 0 |
return;
|
| 1037 |
} |
|
| 1038 |
|
|
| 1039 | 18 |
evtData.getTestCase().resumeAWT(); |
| 1040 |
|
|
| 1041 | 18 |
int numberOfClicks = evtData.getWheelRotation();
|
| 1042 | 18 |
int modifiers = evtData.getModifiers();
|
| 1043 | 18 |
boolean isPopupTrigger = evtData.getPopupTrigger();
|
| 1044 |
|
|
| 1045 | 18 |
Component ultimate = evtData.getSource(); |
| 1046 |
|
|
| 1047 |
// Translate the screen coordinates returned by the event to frame coordinates.
|
|
| 1048 | 18 |
Point screen = evtData.getLocationOnScreen(); |
| 1049 | 18 |
int mods = mouseToKeyModifiers(modifiers);
|
| 1050 | 18 |
pressModifiers(ultimate, mods); |
| 1051 |
|
|
| 1052 |
// try to clear the event queue
|
|
| 1053 | 18 |
evtData.getTestCase().flushAWT(); |
| 1054 |
|
|
| 1055 |
// Ensure a move event.
|
|
| 1056 | 18 |
mouseMoved(ultimate, screen.x - 5, screen.y - 5); |
| 1057 | 18 |
mouseMoved(ultimate, screen.x, screen.y); |
| 1058 | 18 |
evtData.getTestCase().flushAWT(); |
| 1059 |
|
|
| 1060 | 18 |
int inc = 1;
|
| 1061 |
|
|
| 1062 | 18 |
if (numberOfClicks < 0) {
|
| 1063 | 9 |
inc = -1; |
| 1064 |
} |
|
| 1065 |
|
|
| 1066 | 18 |
int mx = numberOfClicks;
|
| 1067 |
|
|
| 1068 | 18 |
if (numberOfClicks < 0) {
|
| 1069 | 9 |
mx *= -1; |
| 1070 |
} |
|
| 1071 |
|
|
| 1072 | 18 |
for (int i = 0; i < mx; i++) { |
| 1073 | 900 |
mouseWheel( |
| 1074 |
ultimate, |
|
| 1075 |
evtData.getScrollAmount(), |
|
| 1076 |
inc); |
|
| 1077 |
} |
|
| 1078 |
|
|
| 1079 | 18 |
evtData.getTestCase().flushAWT(); |
| 1080 |
|
|
| 1081 | 18 |
releaseModifiers(ultimate, mods); |
| 1082 |
|
|
| 1083 |
// try to clear the event queue
|
|
| 1084 | 18 |
evtData.getTestCase().flushAWT(); |
| 1085 |
} |
|
| 1086 |
|
|
| 1087 |
/**
|
|
| 1088 |
* This method is used to send KeyPressed, KeyTyped
|
|
| 1089 |
* and KeyReleased events (in that order) to the specified
|
|
| 1090 |
* component. This method should be used only to send Action key events.
|
|
| 1091 |
* NOTE: This method will not call 'requestFocus()' on the component - the developer
|
|
| 1092 |
* should include it in the test code if needed.
|
|
| 1093 |
*
|
|
| 1094 |
* @param evtData The event data container.
|
|
| 1095 |
*/
|
|
| 1096 | 52 |
public void sendKeyAction(final KeyEventData evtData) { |
| 1097 | 52 |
sendString(evtData); |
| 1098 |
} |
|
| 1099 |
|
|
| 1100 |
/**
|
|
| 1101 |
* This method is used to send KeyPressed, KeyTyped
|
|
| 1102 |
* and KeyReleased events (in that order) to the specified
|
|
| 1103 |
* component. This method can also differentiate between
|
|
| 1104 |
* upper and lower case characters in the specified string.
|
|
| 1105 |
* NOTE: This method will not call 'requestFocus()' on the component - the developer
|
|
| 1106 |
* should include it in the test code if needed.
|
|
| 1107 |
*
|
|
| 1108 |
* @param evtData The event data container.
|
|
| 1109 |
*/
|
|
| 1110 | 86 |
public void sendString(final AbstractKeyEventData evtData) { |
| 1111 | 86 |
if (evtData == null) { |
| 1112 | 6 |
return;
|
| 1113 |
} |
|
| 1114 |
|
|
| 1115 | 80 |
evtData.getTestCase().pauseAWT(); |
| 1116 |
|
|
| 1117 | 80 |
if (!evtData.prepareComponent()) {
|
| 1118 | 6 |
evtData.getTestCase().resumeAWT(); |
| 1119 |
|
|
| 1120 | 6 |
return;
|
| 1121 |
} |
|
| 1122 |
|
|
| 1123 | 74 |
evtData.getTestCase().resumeAWT(); |
| 1124 |
|
|
| 1125 | 74 |
Component ultimate = evtData.getRoot(); |
| 1126 | 74 |
int modifiers = evtData.getModifiers();
|
| 1127 |
|
|
| 1128 |
// try to clear the event queue
|
|
| 1129 | 74 |
evtData.getTestCase().flushAWT(); |
| 1130 |
|
|
| 1131 | 74 |
pressModifiers(ultimate, modifiers); |
| 1132 |
|
|
| 1133 | 74 |
JFCKeyStroke[] keyStroke = evtData.getKeyStrokes(); |
| 1134 |
|
|
| 1135 | 74 |
for (int k = 0; k < keyStroke.length; k++) { |
| 1136 | 856 |
adjustModifiers( |
| 1137 |
ultimate, |
|
| 1138 |
modifiers, |
|
| 1139 |
keyStroke[k].getModifiers()); |
|
| 1140 | 856 |
modifiers = keyStroke[k].getModifiers(); |
| 1141 | 856 |
keyPressed(ultimate, keyStroke[k]); |
| 1142 | 856 |
keyReleased(ultimate, keyStroke[k]); |
| 1143 |
} |
|
| 1144 |
|
|
| 1145 | 74 |
releaseModifiers(ultimate, modifiers); |
| 1146 |
|
|
| 1147 |
// try to clear the event queue
|
|
| 1148 | 74 |
evtData.getTestCase().flushAWT(); |
| 1149 |
} |
|
| 1150 |
|
|
| 1151 |
/**
|
|
| 1152 |
* Convert the modifiers from mouse modifiers to
|
|
| 1153 |
* keyboard modifiers. ALT modifier overlaps with
|
|
| 1154 |
* BUTTON2 and META overlaps with BUTTON3.
|
|
| 1155 |
*
|
|
| 1156 |
* @param modifiers The mouse modifiers that need to be converted.
|
|
| 1157 |
* @return int The corresponding keyboard modifiers.
|
|
| 1158 |
*/
|
|
| 1159 | 2720 |
protected static int mouseToKeyModifiers(final int modifiers) { |
| 1160 | 2720 |
int keyModifiers = modifiers;
|
| 1161 |
|
|
| 1162 | 2720 |
int mouseButtons = InputEvent.BUTTON1_MASK + InputEvent.BUTTON2_MASK
|
| 1163 |
+ InputEvent.BUTTON3_MASK; |
|
| 1164 | 2720 |
keyModifiers = keyModifiers & (0xFFFFFFFF ^ mouseButtons); |
| 1165 |
|
|
| 1166 | 2720 |
return keyModifiers;
|
| 1167 |
} |
|
| 1168 |
|
|
| 1169 |
/**
|
|
| 1170 |
* Send the modifier key release event for the modifiers.
|
|
| 1171 |
*
|
|
| 1172 |
* @param ultimate Component to receive the events.
|
|
| 1173 |
* @param modifiers The modifiers to be released.
|
|
| 1174 |
* @param newModifiers The new modifiers which should be pressed.
|
|
| 1175 |
*/
|
|
| 1176 | 3826 |
protected final void adjustModifiers(final Component ultimate, |
| 1177 |
final int modifiers, final int newModifiers) { |
|
| 1178 | 3826 |
if (modifiers == newModifiers) {
|
| 1179 | 3610 |
return;
|
| 1180 |
} |
|
| 1181 |
|
|
| 1182 | 216 |
boolean s1 = (modifiers & InputEvent.SHIFT_MASK) > 0;
|
| 1183 | 216 |
boolean s2 = (newModifiers & InputEvent.SHIFT_MASK) > 0;
|
| 1184 | 216 |
boolean c1 = (modifiers & InputEvent.CTRL_MASK) > 0;
|
| 1185 | 216 |
boolean c2 = (newModifiers & InputEvent.CTRL_MASK) > 0;
|
| 1186 | 216 |
boolean m1 = (modifiers & InputEvent.META_MASK) > 0;
|
| 1187 | 216 |
boolean m2 = (newModifiers & InputEvent.META_MASK) > 0;
|
| 1188 | 216 |
boolean a1 = (modifiers & InputEvent.ALT_MASK) > 0;
|
| 1189 | 216 |
boolean a2 = (newModifiers & InputEvent.ALT_MASK) > 0;
|
| 1190 | 216 |
boolean g1 = (modifiers & InputEvent.ALT_GRAPH_MASK) > 0;
|
| 1191 | 216 |
boolean g2 = (newModifiers & InputEvent.ALT_GRAPH_MASK) > 0;
|
| 1192 |
|
|
| 1193 | 216 |
int mods = modifiers;
|
| 1194 |
|
|
| 1195 | 216 |
if (s1 && !s2) {
|
| 1196 |
// Release shift
|
|
| 1197 | 72 |
mods = mods & (-1 ^ InputEvent.SHIFT_MASK); |
| 1198 |
|
|
| 1199 | 72 |
JFCKeyStroke[] strokes = getKeyMapping().getKeyStrokes(KeyEvent.VK_SHIFT); |
| 1200 | 72 |
strokes[0].setModifiers(mods); |
| 1201 | 72 |
keyReleased(ultimate, strokes[0]); |
| 1202 | 144 |
} else if (!s1 && s2) { |
| 1203 |
// Press shift
|
|
| 1204 | 72 |
mods = mods | InputEvent.SHIFT_MASK; |
| 1205 |
|
|
| 1206 | 72 |
JFCKeyStroke[] strokes = getKeyMapping().getKeyStrokes(KeyEvent.VK_SHIFT); |
| 1207 | 72 |
strokes[0].setModifiers(mods); |
| 1208 | 72 |
keyPressed(ultimate, strokes[0]); |
| 1209 |
} |
|
| 1210 |
|
|
| 1211 | 216 |
if (c1 && !c2) {
|
| 1212 |
// Release control
|
|
| 1213 | 6 |
mods = mods & (-1 ^ InputEvent.CTRL_MASK); |
| 1214 |
|
|
| 1215 | 6 |
JFCKeyStroke[] strokes = getKeyMapping().getKeyStrokes(KeyEvent.VK_CONTROL); |
| 1216 | 6 |
strokes[0].setModifiers(mods); |
| 1217 | 6 |
keyReleased(ultimate, strokes[0]); |
| 1218 | 210 |
} else if (!c1 && c2) { |
| 1219 |
// Press control
|
|
| 1220 | 6 |
mods = mods | InputEvent.CTRL_MASK; |
| 1221 |
|
|
| 1222 | 6 |
JFCKeyStroke[] strokes = getKeyMapping().getKeyStrokes(KeyEvent.VK_CONTROL); |
| 1223 | 6 |
strokes[0].setModifiers(mods); |
| 1224 | 6 |
keyPressed(ultimate, strokes[0]); |
| 1225 |
} |
|
| 1226 |
|
|
| 1227 | 216 |
if (a1 && !a2) {
|
| 1228 |
// Release alt
|
|
| 1229 | 33 |
mods = mods & (-1 ^ InputEvent.ALT_MASK); |
| 1230 |
|
|
| 1231 | 33 |
JFCKeyStroke[] strokes = getKeyMapping().getKeyStrokes(KeyEvent.VK_ALT); |
| 1232 | 33 |
strokes[0].setModifiers(mods); |
| 1233 | 33 |
keyReleased(ultimate, strokes[0]); |
| 1234 | 183 |
} else if (!a1 && a2) { |
| 1235 |
// Press alt
|
|
| 1236 | 33 |
mods = mods | InputEvent.ALT_MASK; |
| 1237 |
|
|
| 1238 | 33 |
JFCKeyStroke[] strokes = getKeyMapping().getKeyStrokes(KeyEvent.VK_ALT); |
| 1239 | 33 |
strokes[0].setModifiers(mods); |
| 1240 | 33 |
keyPressed(ultimate, strokes[0]); |
| 1241 |
} |
|
| 1242 |
|
|
| 1243 | 216 |
if (g1 && !g2) {
|
| 1244 |
// Release alt graph
|
|
| 1245 | 0 |
mods = mods & (-1 ^ InputEvent.ALT_GRAPH_MASK); |
| 1246 |
|
|
| 1247 | 0 |
JFCKeyStroke[] strokes = getKeyMapping().getKeyStrokes(KeyEvent.VK_ALT_GRAPH); |
| 1248 | 0 |
strokes[0].setModifiers(mods); |
| 1249 | 0 |
keyReleased(ultimate, strokes[0]); |
| 1250 | 216 |
} else if (!g1 && g2) { |
| 1251 |
// Press alt graph
|
|
| 1252 | 0 |
mods = mods | InputEvent.ALT_GRAPH_MASK; |
| 1253 |
|
|
| 1254 | 0 |
JFCKeyStroke[] strokes = getKeyMapping().getKeyStrokes(KeyEvent.VK_ALT_GRAPH); |
| 1255 | 0 |
strokes[0].setModifiers(mods); |
| 1256 | 0 |
keyPressed(ultimate, strokes[0]); |
| 1257 |
} |
|
| 1258 |
|
|
| 1259 | 216 |
if (m1 && !m2) {
|
| 1260 |
// Release meta
|
|
| 1261 | 0 |
mods = mods & (-1 ^ InputEvent.META_MASK); |
| 1262 |
|
|
| 1263 | 0 |
JFCKeyStroke[] strokes = getKeyMapping().getKeyStrokes(KeyEvent.VK_META); |
| 1264 | 0 |
strokes[0].setModifiers(mods); |
| 1265 | 0 |
keyReleased(ultimate, strokes[0]); |
| 1266 | 216 |
} else if (!m1 && m2) { |
| 1267 |
// Press meta
|
|
| 1268 | 0 |
mods = mods | InputEvent.META_MASK; |
| 1269 |
|
|
| 1270 | 0 |
JFCKeyStroke[] strokes = getKeyMapping().getKeyStrokes(KeyEvent.VK_META); |
| 1271 | 0 |
strokes[0].setModifiers(mods); |
| 1272 | 0 |
keyPressed(ultimate, strokes[0]); |
| 1273 |
} |
|
| 1274 |
} |
|
| 1275 |
|
|
| 1276 |
/**
|
|
| 1277 |
* Send the modifier key press event for the modifiers.
|
|
| 1278 |
*
|
|
| 1279 |
* @param ultimate Component to receive the events.
|
|
| 1280 |
* @param modifiers The modifiers to be pressed.
|
|
| 1281 |
*/
|
|
| 1282 | 1485 |
protected final void pressModifiers(final Component ultimate, |
| 1283 |
final int modifiers) {
|
|
| 1284 | 1485 |
adjustModifiers(ultimate, 0, modifiers); |
| 1285 |
} |
|
| 1286 |
|
|
| 1287 |
/**
|
|
| 1288 |
* Send the modifier key release event for the modifiers.
|
|
| 1289 |
*
|
|
| 1290 |
* @param ultimate Component to receive the events.
|
|
| 1291 |
* @param modifiers The modifiers to be released.
|
|
| 1292 |
*/
|
|
| 1293 | 1485 |
protected final void releaseModifiers(final Component ultimate, |
| 1294 |
final int modifiers) {
|
|
| 1295 | 1485 |
adjustModifiers(ultimate, modifiers, 0); |
| 1296 |
} |
|
| 1297 |
|
|
| 1298 |
/**
|
|
| 1299 |
* Check to see if the value is bounded by the min and max.
|
|
| 1300 |
* @param val Value to be checked.
|
|
| 1301 |
* @param vMin minimum value of range.
|
|
| 1302 |
* @param vMax maximum value of range.
|
|
| 1303 |
* @return true if the value is between vMin and vMax.
|
|
| 1304 |
*/
|
|
| 1305 | 63018 |
protected static boolean isBounded(final int val, final int vMin, |
| 1306 |
final int vMax) {
|
|
| 1307 | 63018 |
int min = Math.min(vMin, vMax);
|
| 1308 | 63018 |
int max = Math.max(vMin, vMax);
|
| 1309 |
|
|
| 1310 | 63018 |
if ((min < val) && (val < max)) {
|
| 1311 | 20460 |
return true; |
| 1312 |
} |
|
| 1313 |
|
|
| 1314 | 42558 |
return false; |
| 1315 |
} |
|
| 1316 |
|
|
| 1317 |
/**
|
|
| 1318 |
* Process a key press event on a component.
|
|
| 1319 |
*
|
|
| 1320 |
* @param ultimate The ultimate parent Component
|
|
| 1321 |
* @param stroke The JFCKeyStroke to be performed.
|
|
| 1322 |
*/
|
|
| 1323 |
protected abstract void keyPressed(final Component ultimate, |
|
| 1324 |
final JFCKeyStroke stroke); |
|
| 1325 |
|
|
| 1326 |
/**
|
|
| 1327 |
* Process a key release event on a component.
|
|
| 1328 |
*
|
|
| 1329 |
* @param ultimate The ultimate parent Component
|
|
| 1330 |
* @param stroke The JFCKeyStroke to be performed.
|
|
| 1331 |
*/
|
|
| 1332 |
protected abstract void keyReleased(final Component ultimate, |
|
| 1333 |
final JFCKeyStroke stroke); |
|
| 1334 |
|
|
| 1335 |
/**
|
|
| 1336 |
* Process a mouse move event on a component.
|
|
| 1337 |
*eve
|
|
| 1338 |
* @param ultimate The ultimate parent Component
|
|
| 1339 |
* @param x The x coordinate of the point where the mouse is being moved to.
|
|
| 1340 |
* @param y The y coordinate of the point where the mouse is being moved to.
|
|
| 1341 |
*/
|
|
| 1342 |
protected abstract void mouseMoved(final Component ultimate, final int x, |
|
| 1343 |
final int y);
|
|
| 1344 |
|
|
| 1345 |
/**
|
|
| 1346 |
* Process a mouse press event on a component.
|
|
| 1347 |
*
|
|
| 1348 |
* @param ultimate The ultimate parent Component
|
|
| 1349 |
* @param modifiers The modifiers associated with this mouse event.
|
|
| 1350 |
* @param click The number of clicks associated with this mouse event.
|
|
| 1351 |
* @param isPopupTrigger Whether this mouse event will generate a popup.
|
|
| 1352 |
*/
|
|
| 1353 |
protected abstract void mousePressed(final Component ultimate, |
|
| 1354 |
final int modifiers, final int click, final boolean isPopupTrigger); |
|
| 1355 |
|
|
| 1356 |
/**
|
|
| 1357 |
* Process a mouse release event on a component.
|
|
| 1358 |
*
|
|
| 1359 |
* @param ultimate The ultimate parent Component
|
|
| 1360 |
* @param modifiers The modifiers associated with this mouse event.
|
|
| 1361 |
* @param click The number of clicks associated with this mouse event.
|
|
| 1362 |
* @param isPopupTrigger Whether this mouse event will generate a popup.
|
|
| 1363 |
*/
|
|
| 1364 |
protected abstract void mouseReleased(final Component ultimate, |
|
| 1365 |
final int modifiers, final int click, final boolean isPopupTrigger); |
|
| 1366 |
|
|
| 1367 |
/**
|
|
| 1368 |
* Simulate rotating the mouseWheel.
|
|
| 1369 |
*
|
|
| 1370 |
* @param ultimate Component to fire the events on.
|
|
| 1371 |
* @param amount Amount to scroll for each rotation.
|
|
| 1372 |
* @param rotation clicks to rotate the mouse wheel.
|
|
| 1373 |
*/
|
|
| 1374 |
protected abstract void mouseWheel(final Component ultimate, |
|
| 1375 |
final int amount, final int rotation); |
|
| 1376 |
|
|
| 1377 |
/**
|
|
| 1378 |
* Calculate the direction of travel given the src
|
|
| 1379 |
* and dest point.
|
|
| 1380 |
* @param src Source
|
|
| 1381 |
* @param dest Destination
|
|
| 1382 |
* @return -1 if dest < src, 0 if dest = src, and 1 if dest > src
|
|
| 1383 |
*/
|
|
| 1384 | 63018 |
private static int getDir(final int src, final int dest) { |
| 1385 | 63018 |
if (src == dest) {
|
| 1386 | 13817 |
return 0;
|
| 1387 | 49201 |
} else if (src < dest) { |
| 1388 | 29655 |
return 1;
|
| 1389 |
} else {
|
|
| 1390 | 19546 |
return -1;
|
| 1391 |
} |
|
| 1392 |
} |
|
| 1393 |
} |
|
| 1394 |
|
|
||||||||||