This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: Robot.waitForIdle


Hi,

This patch fixes java.awt.Robot's waitForIdle implementation and
corrects a typo in the documentation.

OK for mainline?
Tom

2005-02-20  Thomas Fitzsimmons  <fitzsim@redhat.com>

	* java/awt/Robot.java (waitForIdle): Call invokeAndWait on an
	empty Runnable.

Index: java/awt/Robot.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Robot.java,v
retrieving revision 1.4
diff -u -r1.4 Robot.java
--- java/awt/Robot.java	16 Feb 2005 20:01:53 -0000	1.4
+++ java/awt/Robot.java	21 Feb 2005 03:07:24 -0000
@@ -40,6 +40,7 @@
 
 import gnu.java.awt.ClasspathToolkit;
 
+import java.lang.reflect.InvocationTargetException;
 import java.awt.event.InputEvent;
 import java.awt.image.BufferedImage;
 import java.awt.peer.RobotPeer;
@@ -53,8 +54,8 @@
  *
  * Since Robot generates native windowing system events, rather than
  * simply inserting {@link AWTEvents} on the AWT event queue, its use
- * is not restricted to Java programs.  It can be to programatically
- * drive any graphical application.
+ * is not restricted to Java programs.  It can be used to
+ * programatically drive any graphical application.
  *
  * This implementation requires an X server that supports the XTest
  * extension.
@@ -384,7 +385,8 @@
   }
 
   /**
-   * Wait until the event dispatch thread is idle.
+   * Wait until all events currently on the event queue have been
+   * dispatched.
    */
   public void waitForIdle ()
   {
@@ -393,17 +395,17 @@
 					     + "the event dispatch thread");
 
     EventQueue q = Toolkit.getDefaultToolkit ().getSystemEventQueue ();
-
-    while (q.peekEvent () != null)
+    try
+      {
+	q.invokeAndWait (new Runnable () { public void run () { } });
+      }
+    catch (InterruptedException e)
+      {
+	System.err.println ("Robot: waitForIdle interrupted");
+      }
+    catch (InvocationTargetException e)
       {
-	try
-	  {
-	    wait ();
-	  }
-	catch (InterruptedException e)
-	  {
-	    System.err.println ("Robot: waitForIdle interrupted");
-	  }
+	System.err.println ("Robot: waitForIdle cannot invoke target");
       }
   }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]