aboutsummaryrefslogtreecommitdiff
path: root/libjava/java
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-11 18:26:08 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-11 18:26:08 +0000
commit5b89bf44d35ed7ec2d02d20108af48a2db19a8da (patch)
tree154d20505f42a83a6c31e7eaa7b460c17e5e8379 /libjava/java
parent027edd6bcee7ae541422a0ea6bc053e3b3c92961 (diff)
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@70333 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java')
-rw-r--r--libjava/java/awt/EventQueue.java47
1 files changed, 42 insertions, 5 deletions
diff --git a/libjava/java/awt/EventQueue.java b/libjava/java/awt/EventQueue.java
index d6204cefd9a..45dc9713b6e 100644
--- a/libjava/java/awt/EventQueue.java
+++ b/libjava/java/awt/EventQueue.java
@@ -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 @@ exception statement from your version. */
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 @@ import java.util.EmptyStackException;
/* 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 @@ public class EventQueue
private EventQueue next;
private EventQueue prev;
+ private AWTEvent currentEvent;
+ private long lastWhen = System.currentTimeMillis();
private EventDispatchThread dispatchThread = new EventDispatchThread(this);
@@ -162,7 +166,6 @@ public class EventQueue
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 @@ public class EventQueue
}
/**
+ * 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 @@ public class EventQueue
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 @@ public class EventQueue
}
/**
+ * 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 @@ public class EventQueue
*/
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 class EventQueue
*/
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;
}
}