summaryrefslogtreecommitdiff
path: root/java/awt/event/InvocationEvent.java
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2002-03-30 12:02:29 +0000
committerEric Blake <ebb9@byu.net>2002-03-30 12:02:29 +0000
commite498e3a548f2670a351161d07f8c964f05a6a979 (patch)
tree621c9128ed4b80bd57527d24b489bd8ebfffb8b2 /java/awt/event/InvocationEvent.java
parent003f1580b9d8bf681b3d844a73673c7694da4446 (diff)
downloadclasspath-e498e3a548f2670a351161d07f8c964f05a6a979.tar.gz
2002-03-30 Eric Blake <ebb9@email.byu.edu>
* java/awt/EventQueue.java (getMostRecentEventTime): New method. * java/util/EventListenerProxy.java: Fix typos. * java/util/EventObject.java: Fix typos. * java/awt/event/AWTEventListener.java: Update to 1.4. * java/awt/event/AWTEventListenerProxy.java: New file. * java/awt/event/ActionEvent.java: Update to 1.4. * java/awt/event/ActionListener.java: Update to 1.4. * java/awt/event/AdjustmentEvent.java: Update to 1.4. * java/awt/event/AdjustmentListener.java: Update to 1.4. * java/awt/event/ComponentAdapter.java: Update to 1.4. * java/awt/event/ComponentEvent.java: Update to 1.4. * java/awt/event/ComponentListener.java: Update to 1.4. * java/awt/event/ContainerAdapter.java: Update to 1.4. * java/awt/event/ContainerEvent.java: Update to 1.4. * java/awt/event/ContainerListener.java: Update to 1.4. * java/awt/event/FocusAdapter.java: Update to 1.4. * java/awt/event/FocusEvent.java: Update to 1.4. * java/awt/event/FocusListener.java: Update to 1.4. * java/awt/event/HierarchyBoundsAdapter.java: Update to 1.4. * java/awt/event/HierarchyBoundsListener.java: Update to 1.4. * java/awt/event/HierarchyEvent.java: Update to 1.4. * java/awt/event/HierarchyListener.java: Update to 1.4. * java/awt/event/InputEvent.java: Update to 1.4. * java/awt/event/InputMethodEvent.java: Update to 1.4. * java/awt/event/InputMethodListener.java: Update to 1.4. * java/awt/event/InvocationEvent.java: Update to 1.4. * java/awt/event/ItemEvent.java: Update to 1.4. * java/awt/event/ItemListener.java: Update to 1.4. * java/awt/event/KeyAdapter.java: Update to 1.4. * java/awt/event/KeyEvent.java: Update to 1.4. * java/awt/event/KeyListener.java: Update to 1.4. * java/awt/event/Makefile.am (EXTRA_DIST): Add new files. * java/awt/event/MouseAdapter.java: Update to 1.4. * java/awt/event/MouseEvent.java: Update to 1.4. * java/awt/event/MouseListener.java: Update to 1.4. * java/awt/event/MouseMotionAdapter.java: Update to 1.4. * java/awt/event/MouseMotionListener.java: Update to 1.4. * java/awt/event/MouseWheelEvent.java: New file. * java/awt/event/MouseWheelListener.java: New file. * java/awt/event/PaintEvent.java: Update to 1.4. * java/awt/event/TextEvent.java: Update to 1.4. * java/awt/event/TextListener.java: Update to 1.4. * java/awt/event/WindowAdapter.java: Update to 1.4. * java/awt/event/WindowEvent.java: Update to 1.4. * java/awt/event/WindowFocusListener.java: New file. * java/awt/event/WindowListener.java: Update to 1.4. * java/awt/event/WindowStateListener.java: New file.
Diffstat (limited to 'java/awt/event/InvocationEvent.java')
-rw-r--r--java/awt/event/InvocationEvent.java359
1 files changed, 180 insertions, 179 deletions
diff --git a/java/awt/event/InvocationEvent.java b/java/awt/event/InvocationEvent.java
index 621a4746f..fbf7b5e93 100644
--- a/java/awt/event/InvocationEvent.java
+++ b/java/awt/event/InvocationEvent.java
@@ -1,5 +1,5 @@
-/* InvocationEvent.java -- Call a runnable when dispatched.
- Copyright (C) 1999 Free Software Foundation, Inc.
+/* InvocationEvent.java -- call a runnable when dispatched
+ Copyright (C) 1999, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -40,192 +40,193 @@ package java.awt.event;
import java.awt.ActiveEvent;
import java.awt.AWTEvent;
+import java.awt.EventQueue;
/**
- * This event executes the <code>run()</code> method of a <code>Runnable</code>
- * when it is dispatched.
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- */
-public class InvocationEvent extends AWTEvent implements ActiveEvent,
- java.io.Serializable
-{
-
-/*
- * Static Variables
- */
-
-/**
- * This is the first id in the range of event ids used by this class.
- */
-public static final int INVOCATION_FIRST = 3838;
-
-/**
- * This is the last id in the range of event ids used by this class.
- */
-public static final int INVOCATION_LAST = 3838;
-
-/**
- * This is the default id for this event type.
- */
-public static final int INVOCATION_DEFAULT = 3838;
-
-/*************************************************************************/
-
-/*
- * Instance Methods
- */
-
-/**
- * @serial This is the <code>Runnable</code> object to call when dispatched.
- */
-protected Runnable runnable;
-
-/**
- * @serial This is the object to call <code>notifyAll()</code> on when
- * the call to <code>run()</code> returns, or <code>null</code> if no
- * object is to be notified.
- */
-protected Object notifier;
-
-/**
- * @serial This variable is set to <code>true</code> if exceptions are caught
- * and stored in a variable during the call to <code>run()</code>, otherwise
- * exceptions are ignored and propagate up.
- */
-protected boolean catchExceptions;
-
-/**
- * @serial This is the caught exception thrown in the <code>run()</code>
- * method.
- */
-private Exception exception;
-
-/*************************************************************************/
-
-/*
- * Constructors
- */
-
-/**
- * Initializes a new instance of <code>InvocationEvent</code> that has
- * the specified source, id, runnable object, and notification object.
- * It will also catch exceptions if that behavior is specified.
- *
- * @param source The source of the event.
- * @param id The parameter id.
- * @param runnable The <code>Runnable</code> object to invoke.
- * @param notifier The object to call <code>notifyAll</code> on when
- * the invocation of the runnable object is complete.
- * @param catchExceptions <code>true</code> if exceptions are caught when
- * the runnable is running, <code>false</code> otherwise.
- */
-public
-InvocationEvent(Object source, int id, Runnable runnable, Object notifier,
- boolean catchExceptions)
-{
- super(source, id);
- this.runnable = runnable;
- this.notifier = notifier;
- this.catchExceptions = catchExceptions;
-}
-
-/*************************************************************************/
-
-/**
- * Initializes a new instance of <code>InvocationEvent</code> with the
- * specified source, runnable, and notifier. It will also catch
- * exceptions if specified.
- *
- * @param source The source of the event.
- * @param runnable The <code>Runnable</code> object to invoke.
- * @param notifier The object to call <code>notifyAll</code> on when
- * the invocation of the runnable object is complete.
- * @param catchExceptions <code>true</code> if exceptions are caught when
- * the runnable is running, <code>false</code> otherwise.
- */
-public
-InvocationEvent(Object source, Runnable runnable, Object notifier,
- boolean catchExceptions)
-{
- this(source, INVOCATION_DEFAULT, runnable, notifier, catchExceptions);
-}
-
-/*************************************************************************/
-
-/**
- * Initializes a new instance of <code>InvocationEvent</code> with the
- * specified source and runnable.
- *
- * @param source The source of the event.
- * @param runnable The <code>Runnable</code> object to invoke.
- */
-public
-InvocationEvent(Object source, Runnable runnable)
-{
- this(source, INVOCATION_DEFAULT, runnable, null, false);
-}
-
-/*************************************************************************/
-
-/*
- * Instance Variables
+ * This event executes {@link Runnable#run()} of a target object when it is
+ * dispatched. This class is used by calls to <code>invokeLater</code> and
+ * <code>invokeAndWait</code>, so client code can use this fact to avoid
+ * writing special-casing AWTEventListener objects.
+ *
+ * @author Aaron M. Renn <arenn@urbanophile.com>
+ * @see ActiveEvent
+ * @see EventQueue#invokeLater(Runnable)
+ * @see EventQueue#invokeAndWait(Runnable)
+ * @see AWTEventListener
+ * @since 1.2
+ * @status updated to 1.4
*/
-
-/**
- * This method calls the <code>run()</code> method of the runnable and
- * performs any other functions specified in the constructor.
- */
-public void
-dispatch()
+public class InvocationEvent extends AWTEvent implements ActiveEvent
{
- if (catchExceptions)
- {
+ /**
+ * Compatible with JDK 1.2+.
+ */
+ private static final long serialVersionUID = 436056344909459450L;
+
+ /** This is the first id in the range of event ids used by this class. */
+ public static final int INVOCATION_FIRST = 1200;
+
+ /** This is the default id for this event type. */
+ public static final int INVOCATION_DEFAULT = 1200;
+
+ /** This is the last id in the range of event ids used by this class. */
+ public static final int INVOCATION_LAST = 1200;
+
+ /**
+ * This is the <code>Runnable</code> object to call when dispatched.
+ *
+ * @serial the runnable to execute
+ */
+ protected Runnable runnable;
+
+ /**
+ * This is the object to call <code>notifyAll()</code> on when
+ * the call to <code>run()</code> returns, or <code>null</code> if no
+ * object is to be notified.
+ *
+ * @serial the object to notify
+ */
+ protected Object notifier;
+
+ /**
+ * This variable is set to <code>true</code> if exceptions are caught
+ * and stored in a variable during the call to <code>run()</code>, otherwise
+ * exceptions are ignored and propagate up.
+ *
+ * @serial true to catch exceptions
+ */
+ protected boolean catchExceptions;
+
+ /**
+ * This is the caught exception thrown in the <code>run()</code> method. It
+ * is null if exceptions are ignored, the run method hasn't completed, or
+ * there were no exceptions.
+ *
+ * @serial the caught exception, if any
+ */
+ private Exception exception;
+
+ /**
+ * The timestamp when this event was created.
+ *
+ * @see #getWhen()
+ * @serial the timestamp
+ * @since 1.4
+ */
+ private final long when = EventQueue.getMostRecentEventTime();
+
+ /**
+ * Initializes a new instance of <code>InvocationEvent</code> with the
+ * specified source and runnable.
+ *
+ * @param source the source of the event
+ * @param runnable the <code>Runnable</code> object to invoke
+ * @throws IllegalArgumentException if source is null
+ */
+ public InvocationEvent(Object source, Runnable runnable)
+ {
+ this(source, INVOCATION_DEFAULT, runnable, null, false);
+ }
+
+ /**
+ * Initializes a new instance of <code>InvocationEvent</code> with the
+ * specified source, runnable, and notifier. It will also catch exceptions
+ * if specified. If notifier is non-null, this will call notifyAll() on
+ * the object when the runnable is complete. If catchExceptions is true,
+ * this traps any exception in the runnable, otherwise it lets the exception
+ * propagate up the Event Dispatch thread.
+ *
+ * @param source the source of the event
+ * @param runnable the <code>Runnable</code> object to invoke
+ * @param notifier the object to notify, or null
+ * @param catchExceptions true to catch exceptions from the runnable
+ */
+ public InvocationEvent(Object source, Runnable runnable, Object notifier,
+ boolean catchExceptions)
+ {
+ this(source, INVOCATION_DEFAULT, runnable, notifier, catchExceptions);
+ }
+
+ /**
+ * Initializes a new instance of <code>InvocationEvent</code> with the
+ * specified source, runnable, and notifier. It will also catch exceptions
+ * if specified. If notifier is non-null, this will call notifyAll() on
+ * the object when the runnable is complete. If catchExceptions is true,
+ * this traps any exception in the runnable, otherwise it lets the exception
+ * propagate up the Event Dispatch thread. Note that an invalid id leads to
+ * unspecified results.
+ *
+ * @param source the source of the event
+ * @param id the event id
+ * @param runnable the <code>Runnable</code> object to invoke
+ * @param notifier the object to notify, or null
+ * @param catchExceptions true to catch exceptions from the runnable
+ */
+ protected InvocationEvent(Object source, int id, Runnable runnable,
+ Object notifier, boolean catchExceptions)
+ {
+ super(source, id);
+ this.runnable = runnable;
+ this.notifier = notifier;
+ this.catchExceptions = catchExceptions;
+ }
+
+ /**
+ * This method calls the <code>run()</code> method of the runnable, traps
+ * exceptions if instructed to do so, and calls <code>notifyAll()</code>
+ * on any notifier if all worked successfully.
+ */
+ public void dispatch()
+ {
+ if (catchExceptions)
try
{
runnable.run();
}
- catch(Exception e)
+ catch (Exception e)
{
- this.exception = e;
+ exception = e;
}
- }
- else
- {
+ else
runnable.run();
- }
-
- if (notifier != null)
- notifier.notifyAll();
-}
-
-/*************************************************************************/
-
-/**
- * This method returns the exception that occurred during the execution of
- * the runnable, or <code>null</code> if not exception was thrown or
- * exceptions were not caught.
- *
- * @return The exception thrown by the runnable.
- */
-public Exception
-getException()
-{
- return(exception);
-}
-
-/*************************************************************************/
-
-/**
- * This method returns a string identifying this event.
- *
- * @return A string identifying this event.
- */
-public String
-paramString()
-{
- return(getClass().getName());
-}
-
+ if (notifier != null)
+ notifier.notifyAll();
+ }
+
+ /**
+ * This method returns the exception that occurred during the execution of
+ * the runnable, or <code>null</code> if not exception was thrown or
+ * exceptions were not caught.
+ *
+ * @return the exception thrown by the runnable
+ */
+ public Exception getException()
+ {
+ return exception;
+ }
+
+ /**
+ * Gets the timestamp of when this event was created.
+ *
+ * @return the timestamp of this event
+ * @since 1.4
+ */
+ public long getWhen()
+ {
+ return when;
+ }
+
+ /**
+ * This method returns a string identifying this event. This is formatted as:
+ * <code>"INVOCATION_DEFAULT,runnable=" + runnable + ",notifier=" + notifier
+ * + ",catchExceptions=" + catchExceptions + ",when=" + getWhen()</code>.
+ *
+ * @return a string identifying this event
+ */
+ public String paramString()
+ {
+ return (id == INVOCATION_DEFAULT ? "INVOCATION_DEFAULT,runnable="
+ : "unknown type,runnable=") + runnable + ",notifier=" + notifier
+ + ",catchExceptions=" + catchExceptions + ",when=" + when;
+ }
} // class InvocationEvent
-