src/java.desktop/share/classes/java/awt/event/InvocationEvent.java
author darcy
Tue, 24 Sep 2019 18:25:54 -0700
changeset 58309 c6f8b2c3dc66
parent 53185 450c1abf9c62
permissions -rw-r--r--
8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21246
diff changeset
     2
 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4264
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4264
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4264
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4264
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4264
diff changeset
    23
 * questions.
2
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
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
    28
import sun.awt.AWTAccessor;
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
    29
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.ActiveEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.AWTEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
    34
 * An event which executes the {@code run()} method on a {@code Runnable
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
    35
 * } when dispatched by the AWT event dispatcher thread. This class can
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
    36
 * be used as a reference implementation of {@code ActiveEvent} rather
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
    37
 * than declaring a new class and defining {@code dispatch()}.<p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
    39
 * Instances of this class are placed on the {@code EventQueue} by calls
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
    40
 * to {@code invokeLater} and {@code invokeAndWait}. Client code
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
    41
 * can use this fact to write replacement functions for {@code invokeLater
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
    42
 * } and {@code invokeAndWait} without writing special-case code
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
    43
 * in any {@code AWTEventListener} objects.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    44
 * <p>
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    45
 * An unspecified behavior will be caused if the {@code id} parameter
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    46
 * of any particular {@code InvocationEvent} instance is not
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    47
 * in the range from {@code INVOCATION_FIRST} to {@code INVOCATION_LAST}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author      Fred Ecks
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author      David Mendenhall
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see         java.awt.ActiveEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see         java.awt.EventQueue#invokeLater
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see         java.awt.EventQueue#invokeAndWait
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see         AWTEventListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @since       1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
public class InvocationEvent extends AWTEvent implements ActiveEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
    61
    static {
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
    62
        AWTAccessor.setInvocationEventAccessor(new AWTAccessor.InvocationEventAccessor() {
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
    63
            @Override
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
    64
            public void dispose(InvocationEvent invocationEvent) {
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
    65
                invocationEvent.finishedDispatching(false);
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
    66
            }
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
    67
        });
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
    68
    }
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
    69
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Marks the first integer id for the range of invocation event ids.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public static final int INVOCATION_FIRST = 1200;
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 default id for all InvocationEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final int INVOCATION_DEFAULT = INVOCATION_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Marks the last integer id for the range of invocation event ids.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static final int INVOCATION_LAST = INVOCATION_DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * The Runnable whose run() method will be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
58309
c6f8b2c3dc66 8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents: 53185
diff changeset
    88
    @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected Runnable runnable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * The (potentially null) Object whose notifyAll() method will be called
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
    93
     * immediately after the Runnable.run() method has returned or thrown an exception
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
    94
     * or after the event was disposed.
4264
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
    95
     *
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
    96
     * @see #isDispatched
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
58309
c6f8b2c3dc66 8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents: 53185
diff changeset
    98
    @SuppressWarnings("serial") // Not statically typed as Serializable
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
    99
    protected volatile Object notifier;
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   100
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   101
    /**
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   102
     * The (potentially null) Runnable whose run() method will be called
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   103
     * immediately after the event was dispatched or disposed.
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   104
     *
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   105
     * @see #isDispatched
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   106
     * @since 1.8
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   107
     */
58309
c6f8b2c3dc66 8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents: 53185
diff changeset
   108
    @SuppressWarnings("serial") // Not statically typed as Serializable
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   109
    private final Runnable listener;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   112
     * Indicates whether the {@code run()} method of the {@code runnable}
4264
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   113
     * was executed or not.
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   114
     *
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   115
     * @see #isDispatched
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   116
     * @since 1.7
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   117
     */
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   118
    private volatile boolean dispatched = false;
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   119
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   120
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Set to true if dispatch() catches Throwable and stores it in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * exception instance variable. If false, Throwables are propagated up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * to the EventDispatchThread's dispatch loop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    protected boolean catchExceptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * The (potentially null) Exception thrown during execution of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Runnable.run() method. This variable will also be null if a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * instance does not catch exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private Exception exception = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * The (potentially null) Throwable thrown during execution of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Runnable.run() method. This variable will also be null if a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * instance does not catch exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private Throwable throwable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * The timestamp of when this event occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @see #getWhen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private long when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * JDK 1.1 serialVersionUID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    private static final long serialVersionUID = 436056344909459450L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   155
     * Constructs an {@code InvocationEvent} with the specified
53185
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   156
     * source which will execute the runnable's {@code run()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * method when dispatched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <p>This is a convenience constructor.  An invocation of the form
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   159
     * {@code InvocationEvent(source, runnable)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * behaves in exactly the same way as the invocation of
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   161
     * {@link #InvocationEvent(Object, Runnable, Object, boolean)
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   162
     * InvocationEvent(source, runnable, null, false)}.
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   163
     * <p> This method throws an {@code IllegalArgumentException}
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   164
     * if {@code source} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   166
     * @param source    The {@code Object} that originated the event
53185
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   167
     * @param runnable  The {@code Runnable} whose {@code run()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *                  method will be executed
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   169
     * @throws IllegalArgumentException if {@code source} is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   171
     * @see #getSource()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   172
     * @see #InvocationEvent(Object, Runnable, Object, boolean)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public InvocationEvent(Object source, Runnable runnable) {
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   175
        this(source, INVOCATION_DEFAULT, runnable, null, null, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   179
     * Constructs an {@code InvocationEvent} with the specified
53185
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   180
     * source which will execute the runnable's {@code run()}
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   181
     * method when dispatched.  If notifier is non-{@code null},
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   182
     * {@code notifyAll()} will be called on it
53185
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   183
     * immediately after {@code run()} has returned or thrown an exception.
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   184
     * <p>An invocation of the form
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   185
     * {@code InvocationEvent(source, runnable, notifier, catchThrowables)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * behaves in exactly the same way as the invocation of
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   187
     * {@link #InvocationEvent(Object, int, Runnable, Object, boolean)
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   188
     * InvocationEvent(source, InvocationEvent.INVOCATION_DEFAULT, runnable, notifier, catchThrowables)}.
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   189
     * <p>This method throws an {@code IllegalArgumentException}
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   190
     * if {@code source} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   192
     * @param source            The {@code Object} that originated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *                          the event
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   194
     * @param runnable          The {@code Runnable} whose
53185
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   195
     *                          {@code run()} method will be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *                          executed
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   197
     * @param notifier          The {@code Object} whose {@code notifyAll}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *                          method will be called after
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   199
     *                          {@code Runnable.run} has returned or
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   200
     *                          thrown an exception or after the event was
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   201
     *                          disposed
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   202
     * @param catchThrowables   Specifies whether {@code dispatch}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *                          should catch Throwable when executing
53185
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   204
     *                          the {@code Runnable}'s {@code run()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *                          method, or should instead propagate those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *                          Throwables to the EventDispatchThread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *                          dispatch loop
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   208
     * @throws IllegalArgumentException if {@code source} is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   210
     * @see #getSource()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @see     #InvocationEvent(Object, int, Runnable, Object, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public InvocationEvent(Object source, Runnable runnable, Object notifier,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                           boolean catchThrowables) {
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   215
        this(source, INVOCATION_DEFAULT, runnable, notifier, null, catchThrowables);
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   216
    }
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   217
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   218
    /**
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   219
     * Constructs an {@code InvocationEvent} with the specified
53185
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   220
     * source which will execute the runnable's {@code run()}
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   221
     * method when dispatched.  If listener is non-{@code null},
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   222
     * {@code listener.run()} will be called immediately after
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   223
     * {@code run} has returned, thrown an exception or the event
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   224
     * was disposed.
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   225
     * <p>This method throws an {@code IllegalArgumentException}
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   226
     * if {@code source} is {@code null}.
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   227
     *
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   228
     * @param source            The {@code Object} that originated
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   229
     *                          the event
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   230
     * @param runnable          The {@code Runnable} whose
53185
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   231
     *                          {@code run()} method will be
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   232
     *                          executed
53185
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   233
     * @param listener          The {@code Runnable} whose
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   234
     *                          {@code run()} method will be called
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   235
     *                          after the {@code InvocationEvent}
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   236
     *                          was dispatched or disposed
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   237
     * @param catchThrowables   Specifies whether {@code dispatch}
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   238
     *                          should catch Throwable when executing
53185
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   239
     *                          the {@code Runnable}'s {@code run()}
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   240
     *                          method, or should instead propagate those
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   241
     *                          Throwables to the EventDispatchThread's
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   242
     *                          dispatch loop
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   243
     * @throws IllegalArgumentException if {@code source} is null
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   244
     */
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   245
    public InvocationEvent(Object source, Runnable runnable, Runnable listener,
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   246
                           boolean catchThrowables)  {
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   247
        this(source, INVOCATION_DEFAULT, runnable, null, listener, catchThrowables);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   251
     * Constructs an {@code InvocationEvent} with the specified
53185
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   252
     * source and ID which will execute the runnable's {@code run()}
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   253
     * method when dispatched.  If notifier is non-{@code null},
53185
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   254
     * {@code notifyAll()} will be called on it immediately after
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   255
     * {@code run()} has returned or thrown an exception.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   256
     * <p>This method throws an
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   257
     * {@code IllegalArgumentException} if {@code source}
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   258
     * is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   260
     * @param source            The {@code Object} that originated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *                          the event
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   262
     * @param id     An integer indicating the type of event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   263
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   264
     *                     the class description for {@link InvocationEvent}
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   265
     * @param runnable          The {@code Runnable} whose
53185
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   266
     *                          {@code run()} method will be executed
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   267
     * @param notifier          The {@code Object} whose {@code notifyAll}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *                          method will be called after
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   269
     *                          {@code Runnable.run} has returned or
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   270
     *                          thrown an exception or after the event was
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   271
     *                          disposed
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   272
     * @param catchThrowables   Specifies whether {@code dispatch}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *                          should catch Throwable when executing the
53185
450c1abf9c62 8215910: Typo in AWT InvocationEvent Method Documentation.
kaddepalli
parents: 47216
diff changeset
   274
     *                          {@code Runnable}'s {@code run()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *                          method, or should instead propagate those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *                          Throwables to the EventDispatchThread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *                          dispatch loop
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   278
     * @throws IllegalArgumentException if {@code source} is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   279
     * @see #getSource()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   280
     * @see #getID()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    protected InvocationEvent(Object source, int id, Runnable runnable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                              Object notifier, boolean catchThrowables) {
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   284
        this(source, id, runnable, notifier, null, catchThrowables);
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   285
    }
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   286
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   287
    private InvocationEvent(Object source, int id, Runnable runnable,
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   288
                            Object notifier, Runnable listener, boolean catchThrowables) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        super(source, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        this.runnable = runnable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        this.notifier = notifier;
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   292
        this.listener = listener;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        this.catchExceptions = catchThrowables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        this.when = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   297
     * Executes the Runnable's {@code run()} method and notifies the
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   298
     * notifier (if any) when {@code run()} has returned or thrown an exception.
4264
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   299
     *
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   300
     * @see #isDispatched
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public void dispatch() {
4264
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   303
        try {
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   304
            if (catchExceptions) {
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   305
                try {
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   306
                    runnable.run();
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   307
                }
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   308
                catch (Throwable t) {
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   309
                    if (t instanceof Exception) {
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   310
                        exception = (Exception) t;
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   311
                    }
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   312
                    throwable = t;
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   313
                }
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   314
            }
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   315
            else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                runnable.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
4264
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   318
        } finally {
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   319
            finishedDispatching(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   324
     * Returns any Exception caught while executing
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   325
     * the Runnable's {@code run()} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @return  A reference to the Exception if one was thrown; null if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *          Exception was thrown or if this InvocationEvent does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *          catch exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public Exception getException() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        return (catchExceptions) ? exception : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /**
32283
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   336
     * Returns any Throwable caught while executing
1a96ab120a48 8133134: docs: replace <tt> tags (obsolete in html5) for java.desktop
avstepan
parents: 25859
diff changeset
   337
     * the Runnable's {@code run()} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @return  A reference to the Throwable if one was thrown; null if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *          Throwable was thrown or if this InvocationEvent does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *          catch Throwables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public Throwable getThrowable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return (catchExceptions) ? throwable : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Returns the timestamp of when this event occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @return this event's timestamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    public long getWhen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
4264
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   359
     * Returns {@code true} if the event is dispatched or any exception is
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   360
     * thrown while dispatching, {@code false} otherwise. The method should
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   361
     * be called by a waiting thread that calls the {@code notifier.wait()} method.
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   362
     * Since spurious wakeups are possible (as explained in {@link Object#wait()}),
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   363
     * this method should be used in a waiting loop to ensure that the event
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   364
     * got dispatched:
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   365
     * <pre>
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   366
     *     while (!event.isDispatched()) {
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   367
     *         notifier.wait();
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   368
     *     }
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   369
     * </pre>
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   370
     * If the waiting thread wakes up without dispatching the event,
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   371
     * the {@code isDispatched()} method returns {@code false}, and
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   372
     * the {@code while} loop executes once more, thus, causing
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   373
     * the awakened thread to revert to the waiting mode.
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   374
     * <p>
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   375
     * If the {@code notifier.notifyAll()} happens before the waiting thread
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   376
     * enters the {@code notifier.wait()} method, the {@code while} loop ensures
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   377
     * that the waiting thread will not enter the {@code notifier.wait()} method.
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   378
     * Otherwise, there is no guarantee that the waiting thread will ever be woken
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   379
     * from the wait.
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   380
     *
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   381
     * @return {@code true} if the event has been dispatched, or any exception
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   382
     * has been thrown while dispatching, {@code false} otherwise
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   383
     * @see #dispatch
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   384
     * @see #notifier
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   385
     * @see #catchExceptions
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   386
     * @since 1.7
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   387
     */
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   388
    public boolean isDispatched() {
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   389
        return dispatched;
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   390
    }
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   391
40c232605c68 6852111: Unhandled 'spurious wakeup' in java.awt.EventQueue.invokeAndWait()
dcherepanov
parents: 440
diff changeset
   392
    /**
21246
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   393
     * Called when the event was dispatched or disposed
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   394
     * @param dispatched true if the event was dispatched
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   395
     *                   false if the event was disposed
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   396
     */
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   397
    private void finishedDispatching(boolean dispatched) {
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   398
        this.dispatched = dispatched;
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   399
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   400
        if (notifier != null) {
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   401
            synchronized (notifier) {
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   402
                notifier.notifyAll();
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   403
            }
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   404
        }
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   405
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   406
        if (listener != null) {
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   407
            listener.run();
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   408
        }
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   409
    }
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   410
9d1752954b0e 8025588: [macosx] Frozen AppKit thread in 7u40
pchelko
parents: 5506
diff changeset
   411
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * Returns a parameter string identifying this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * This method is useful for event-logging and for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @return  A string identifying the event and its attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    public String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        String typeStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            case INVOCATION_DEFAULT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                typeStr = "INVOCATION_DEFAULT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                typeStr = "unknown type";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        return typeStr + ",runnable=" + runnable + ",notifier=" + notifier +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            ",catchExceptions=" + catchExceptions + ",when=" + when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
}