583 return trackEvent(ActionEvent.ACTION_PERFORMED, button, action, time, printEvent); 584 } 585 586 /* 587 * Requests focus on the component provided and waits for the result. 588 * @return true if the component has been focused, false otherwise. 589 */ 590 public static boolean focusComponent(Component comp, int time) { 591 return focusComponent(comp, time, false); 592 } 593 public static boolean focusComponent(final Component comp, int time, boolean printEvent) { 594 return trackFocusGained(comp, 595 new Runnable() { 596 public void run() { 597 comp.requestFocus(); 598 } 599 }, 600 time, printEvent); 601 602 } 603 } | 583 return trackEvent(ActionEvent.ACTION_PERFORMED, button, action, time, printEvent); 584 } 585 586 /* 587 * Requests focus on the component provided and waits for the result. 588 * @return true if the component has been focused, false otherwise. 589 */ 590 public static boolean focusComponent(Component comp, int time) { 591 return focusComponent(comp, time, false); 592 } 593 public static boolean focusComponent(final Component comp, int time, boolean printEvent) { 594 return trackFocusGained(comp, 595 new Runnable() { 596 public void run() { 597 comp.requestFocus(); 598 } 599 }, 600 time, printEvent); 601 602 } 603 604 605 /** 606 * Invokes the <code>task</code> on the EDT thread. 607 * 608 * @return result of the <code>task</code> 609 */ 610 public static <T> T invokeOnEDT(final java.util.concurrent.Callable<T> task) throws Exception { 611 final java.util.List<T> result = new java.util.ArrayList<T>(1); 612 final Exception[] exception = new Exception[1]; 613 614 javax.swing.SwingUtilities.invokeAndWait(new Runnable() { 615 616 @Override 617 public void run() { 618 try { 619 result.add(task.call()); 620 } catch (Exception e) { 621 exception[0] = e; 622 } 623 } 624 }); 625 626 if (exception[0] != null) { 627 throw exception[0]; 628 } 629 630 return result.get(0); 631 } 632 633 } |