jdk/src/share/classes/java/awt/event/InvocationEvent.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 440 a3dac373f62d
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.ActiveEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.AWTEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * An event which executes the <code>run()</code> method on a <code>Runnable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * </code> when dispatched by the AWT event dispatcher thread. This class can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * be used as a reference implementation of <code>ActiveEvent</code> rather
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * than declaring a new class and defining <code>dispatch()</code>.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Instances of this class are placed on the <code>EventQueue</code> by calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * to <code>invokeLater</code> and <code>invokeAndWait</code>. Client code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * can use this fact to write replacement functions for <code>invokeLater
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * </code> and <code>invokeAndWait</code> without writing special-case code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * in any <code>AWTEventListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author      Fred Ecks
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author      David Mendenhall
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @see         java.awt.ActiveEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @see         java.awt.EventQueue#invokeLater
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @see         java.awt.EventQueue#invokeAndWait
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see         AWTEventListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @since       1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class InvocationEvent extends AWTEvent implements ActiveEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Marks the first integer id for the range of invocation event ids.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static final int INVOCATION_FIRST = 1200;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * The default id for all InvocationEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static final int INVOCATION_DEFAULT = INVOCATION_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Marks the last integer id for the range of invocation event ids.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static final int INVOCATION_LAST = INVOCATION_DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * The Runnable whose run() method will be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected Runnable runnable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * The (potentially null) Object whose notifyAll() method will be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * immediately after the Runnable.run() method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected Object notifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Set to true if dispatch() catches Throwable and stores it in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * exception instance variable. If false, Throwables are propagated up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * to the EventDispatchThread's dispatch loop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected boolean catchExceptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * The (potentially null) Exception thrown during execution of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Runnable.run() method. This variable will also be null if a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * instance does not catch exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private Exception exception = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * The (potentially null) Throwable thrown during execution of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Runnable.run() method. This variable will also be null if a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * instance does not catch exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private Throwable throwable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * The timestamp of when this event occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @see #getWhen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private long when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * JDK 1.1 serialVersionUID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private static final long serialVersionUID = 436056344909459450L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Constructs an <code>InvocationEvent</code> with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * source which will execute the runnable's <code>run</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * method when dispatched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <p>This is a convenience constructor.  An invocation of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * <tt>InvocationEvent(source, runnable)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * behaves in exactly the same way as the invocation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * <tt>{@link #InvocationEvent(Object, Runnable, Object, boolean) InvocationEvent}(source, runnable, null, false)</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * <p> This method throws an <code>IllegalArgumentException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * if <code>source</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @param source    the <code>Object</code> that originated the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param runnable  the <code>Runnable</code> whose <code>run</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *                  method will be executed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @throws IllegalArgumentException if <code>source</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @see     #InvocationEvent(Object, Runnable, Object, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public InvocationEvent(Object source, Runnable runnable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        this(source, runnable, null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Constructs an <code>InvocationEvent</code> with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * source which will execute the runnable's <code>run</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * method when dispatched.  If notifier is non-<code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * <code>notifyAll()</code> will be called on it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * immediately after <code>run</code> returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * <p>An invocation of the form <tt>InvocationEvent(source,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * runnable, notifier, catchThrowables)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * behaves in exactly the same way as the invocation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * <tt>{@link #InvocationEvent(Object, int, Runnable, Object, boolean) InvocationEvent}(source, InvocationEvent.INVOCATION_DEFAULT, runnable, notifier, catchThrowables)</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * <p>This method throws an <code>IllegalArgumentException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * if <code>source</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @param source            the <code>Object</code> that originated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *                          the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param runnable          the <code>Runnable</code> whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *                          <code>run</code> method will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *                          executed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param notifier          the Object whose <code>notifyAll</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *                          method will be called after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *                          <code>Runnable.run</code> has returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param catchThrowables   specifies whether <code>dispatch</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *                          should catch Throwable when executing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *                          the <code>Runnable</code>'s <code>run</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *                          method, or should instead propagate those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *                          Throwables to the EventDispatchThread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *                          dispatch loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @throws IllegalArgumentException if <code>source</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @see     #InvocationEvent(Object, int, Runnable, Object, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public InvocationEvent(Object source, Runnable runnable, Object notifier,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                           boolean catchThrowables) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        this(source, INVOCATION_DEFAULT, runnable, notifier, catchThrowables);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Constructs an <code>InvocationEvent</code> with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * source and ID which will execute the runnable's <code>run</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * method when dispatched.  If notifier is non-<code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * <code>notifyAll</code> will be called on it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * immediately after <code>run</code> returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * <p>Note that passing in an invalid <code>id</code> results in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * unspecified behavior. This method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param source            the <code>Object</code> that originated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *                          the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param id                the ID for the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param runnable          the <code>Runnable</code> whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *                          <code>run</code> method will be executed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @param notifier          the <code>Object</code> whose <code>notifyAll</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *                          method will be called after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *                          <code>Runnable.run</code> has returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param catchThrowables   specifies whether <code>dispatch</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *                          should catch Throwable when executing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *                          <code>Runnable</code>'s <code>run</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *                          method, or should instead propagate those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *                          Throwables to the EventDispatchThread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *                          dispatch loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @throws IllegalArgumentException if <code>source</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    protected InvocationEvent(Object source, int id, Runnable runnable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                              Object notifier, boolean catchThrowables) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        super(source, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        this.runnable = runnable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        this.notifier = notifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        this.catchExceptions = catchThrowables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        this.when = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Executes the Runnable's <code>run()</code> method and notifies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * notifier (if any) when <code>run()</code> returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public void dispatch() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (catchExceptions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                runnable.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                if (t instanceof Exception) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    exception = (Exception) t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                throwable = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            runnable.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (notifier != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            synchronized (notifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                notifier.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Returns any Exception caught while executing the Runnable's <code>run()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * </code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @return  A reference to the Exception if one was thrown; null if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *          Exception was thrown or if this InvocationEvent does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *          catch exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public Exception getException() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return (catchExceptions) ? exception : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Returns any Throwable caught while executing the Runnable's <code>run()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * </code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @return  A reference to the Throwable if one was thrown; null if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *          Throwable was thrown or if this InvocationEvent does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *          catch Throwables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public Throwable getThrowable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return (catchExceptions) ? throwable : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Returns the timestamp of when this event occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @return this event's timestamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public long getWhen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Returns a parameter string identifying this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * This method is useful for event-logging and for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @return  A string identifying the event and its attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        String typeStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            case INVOCATION_DEFAULT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                typeStr = "INVOCATION_DEFAULT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                typeStr = "unknown type";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return typeStr + ",runnable=" + runnable + ",notifier=" + notifier +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            ",catchExceptions=" + catchExceptions + ",when=" + when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}