481 /** 482 * Sets whether this Robot automatically invokes <code>waitForIdle</code> 483 * after generating an event. 484 * @param isOn Whether <code>waitForIdle</code> is automatically invoked 485 */ 486 public synchronized void setAutoWaitForIdle(boolean isOn) { 487 isAutoWaitForIdle = isOn; 488 } 489 490 /* 491 * Calls waitForIdle after every event if so desired. 492 */ 493 private void autoWaitForIdle() { 494 if (isAutoWaitForIdle) { 495 waitForIdle(); 496 } 497 } 498 499 /** 500 * Returns the number of milliseconds this Robot sleeps after generating an event. 501 */ 502 public synchronized int getAutoDelay() { 503 return autoDelay; 504 } 505 506 /** 507 * Sets the number of milliseconds this Robot sleeps after generating an event. 508 * @throws IllegalArgumentException If <code>ms</code> is not between 0 and 60,000 milliseconds inclusive 509 */ 510 public synchronized void setAutoDelay(int ms) { 511 checkDelayArgument(ms); 512 autoDelay = ms; 513 } 514 515 /* 516 * Automatically sleeps for the specified interval after event generated. 517 */ 518 private void autoDelay() { 519 delay(autoDelay); 520 } 521 522 /** 523 * Sleeps for the specified time. 524 * To catch any <code>InterruptedException</code>s that occur, 525 * <code>Thread.sleep()</code> may be used instead. 526 * @param ms time to sleep in milliseconds 527 * @throws IllegalArgumentException if <code>ms</code> is not between 0 and 60,000 milliseconds inclusive 528 * @see java.lang.Thread#sleep 529 */ 530 public synchronized void delay(int ms) { 531 checkDelayArgument(ms); 532 try { 533 Thread.sleep(ms); 534 } catch(InterruptedException ite) { 535 ite.printStackTrace(); 536 } 537 } 538 539 private void checkDelayArgument(int ms) { 540 if (ms < 0 || ms > MAX_DELAY) { 541 throw new IllegalArgumentException("Delay must be to 0 to 60,000ms"); 542 } 543 } 544 545 /** 546 * Waits until all events currently on the event queue have been processed. 547 * @throws IllegalThreadStateException if called on the AWT event dispatching thread | 481 /** 482 * Sets whether this Robot automatically invokes <code>waitForIdle</code> 483 * after generating an event. 484 * @param isOn Whether <code>waitForIdle</code> is automatically invoked 485 */ 486 public synchronized void setAutoWaitForIdle(boolean isOn) { 487 isAutoWaitForIdle = isOn; 488 } 489 490 /* 491 * Calls waitForIdle after every event if so desired. 492 */ 493 private void autoWaitForIdle() { 494 if (isAutoWaitForIdle) { 495 waitForIdle(); 496 } 497 } 498 499 /** 500 * Returns the number of milliseconds this Robot sleeps after generating an event. 501 * 502 * @return the delay duration in milliseconds 503 */ 504 public synchronized int getAutoDelay() { 505 return autoDelay; 506 } 507 508 /** 509 * Sets the number of milliseconds this Robot sleeps after generating an event. 510 * 511 * @param ms the delay duration in milliseconds 512 * @throws IllegalArgumentException If {@code ms} 513 * is not between 0 and 60,000 milliseconds inclusive 514 */ 515 public synchronized void setAutoDelay(int ms) { 516 checkDelayArgument(ms); 517 autoDelay = ms; 518 } 519 520 /* 521 * Automatically sleeps for the specified interval after event generated. 522 */ 523 private void autoDelay() { 524 delay(autoDelay); 525 } 526 527 /** 528 * Sleeps for the specified time. 529 * To catch any <code>InterruptedException</code>s that occur, 530 * <code>Thread.sleep()</code> may be used instead. 531 * 532 * @param ms time to sleep in milliseconds 533 * @throws IllegalArgumentException if {@code ms} 534 * is not between 0 and 60,000 milliseconds inclusive 535 * @see java.lang.Thread#sleep 536 */ 537 public synchronized void delay(int ms) { 538 checkDelayArgument(ms); 539 try { 540 Thread.sleep(ms); 541 } catch(InterruptedException ite) { 542 ite.printStackTrace(); 543 } 544 } 545 546 private void checkDelayArgument(int ms) { 547 if (ms < 0 || ms > MAX_DELAY) { 548 throw new IllegalArgumentException("Delay must be to 0 to 60,000ms"); 549 } 550 } 551 552 /** 553 * Waits until all events currently on the event queue have been processed. 554 * @throws IllegalThreadStateException if called on the AWT event dispatching thread |