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: FYI: missing EventQueue methods


I'm checking this in on the trunk.

This adds some missing methods to EventQueue and cleans up some old
FIXMEs.  It should be at least as correct as the rest of EventQueue,
given our singleton model of event queues.  (I'm not certain that is
correct, but I'm not going to change it now...)

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* java/awt/EventQueue.java (currentEvent, lastWhen): New fields.
	(postEvent): Removed FIXME comment.
	(isDispatchThread): Documented.
	(getCurrentEvent): New method.
	(dispatchEvent): Set currentEvent and lastWhen.
	(getMostRecentEventTime): Rewrote.
	(invokeLater): Documented.

Index: java/awt/EventQueue.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/EventQueue.java,v
retrieving revision 1.10
diff -u -r1.10 EventQueue.java
--- java/awt/EventQueue.java 5 Jun 2003 19:58:39 -0000 1.10
+++ java/awt/EventQueue.java 11 Aug 2003 18:18:31 -0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999, 2000, 2001, 2002  Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001, 2002, 2003  Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -37,6 +37,8 @@
 
 package java.awt;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.InputEvent;
 import java.awt.event.InvocationEvent;
 import java.lang.reflect.InvocationTargetException;
 import java.util.EmptyStackException;
@@ -44,7 +46,7 @@
 /* Written using on-line Java 2 Platform Standard Edition v1.3 API 
  * Specification, as well as "The Java Class Libraries", 2nd edition 
  * (Addison-Wesley, 1998).
- * Status:  Believed complete, but untested. Check FIXME's.
+ * Status:  Believed complete, but untested.
  */
 
 /**
@@ -65,6 +67,8 @@
 
   private EventQueue next;
   private EventQueue prev;
+  private AWTEvent currentEvent;
+  private long lastWhen = System.currentTimeMillis();
 
   private EventDispatchThread dispatchThread = new EventDispatchThread(this);
 
@@ -162,7 +166,6 @@
         next.postEvent(evt);
         return;
       }
-    // FIXME: Security checks?
 
     /* Check for any events already on the queue with the same source 
        and ID. */	
@@ -249,6 +252,10 @@
   }
 
   /**
+   * This arranges for runnable to have its run method called in the
+   * dispatch thread of the EventQueue.  This will happen after all
+   * pending events are processed.
+   *
    * @since 1.2
    */
   public static void invokeLater(Runnable runnable)
@@ -261,6 +268,10 @@
     eq.postEvent(ie);
   }
 
+  /**
+   * Return true if the current thread is the AWT event dispatch
+   * thread.
+   */
   public static boolean isDispatchThread()
   {
     EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); 
@@ -268,6 +279,21 @@
   }
 
   /**
+   * Return the event currently being dispatched by the event
+   * dispatch thread.  If the current thread is not the event
+   * dispatch thread, this method returns null.
+   *
+   * @since 1.4
+   */
+  public static AWTEvent getCurrentEvent()
+  {
+    EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); 
+    if (Thread.currentThread() != eq.dispatchThread)
+      return null;
+    return eq.currentEvent;
+  }
+
+  /**
    * Allows a custom EventQueue implementation to replace this one. 
    * All pending events are transferred to the new queue. Calls to postEvent,
    * getNextEvent, and peekEvent are forwarded to the pushed queue until it
@@ -332,6 +358,15 @@
    */
   protected void dispatchEvent(AWTEvent evt)
   {
+    currentEvent = evt;
+
+    if (evt instanceof InputEvent)
+      lastWhen = ((InputEvent) evt).getWhen();
+    else if (evt instanceof ActionEvent)
+      lastWhen = ((ActionEvent) evt).getWhen();
+    else if (evt instanceof InvocationEvent)
+      lastWhen = ((InvocationEvent) evt).getWhen();
+
     if (evt instanceof ActiveEvent)
       {
         ActiveEvent active_evt = (ActiveEvent) evt;
@@ -373,7 +408,9 @@
    */
   public static long getMostRecentEventTime()
   {
-    // XXX For now, this ONLY does the current time.
-    return System.currentTimeMillis();
+    EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); 
+    if (Thread.currentThread() != eq.dispatchThread)
+      return System.currentTimeMillis();
+    return eq.lastWhen;
   }
 }


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