/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A mechanism for ensuring that a series of AWTEvents are executed in a
* precise order, even across multiple AppContexts. The nested events will be
* dispatched in the order in which their wrapping SequencedEvents were
* constructed. The only exception to this rule is if the peer of the target of
* the nested event was destroyed (with a call to Component.removeNotify)
* before the wrapping SequencedEvent was able to be dispatched. In this case,
* the nested event is never dispatched.
*
* @author David Mendenhall
*/
/*
* serialVersionUID
*/
private static final int ID =
private boolean disposed;
static {
}
return event instanceof SequencedEvent;
}
});
}
/**
* Constructs a new SequencedEvent which will dispatch the specified
* nested event.
*
* @param nested the AWTEvent which this SequencedEvent's dispatch()
* method will dispatch
*/
// All AWTEvents that are wrapped in SequencedEvents are (at
// least currently) implicitly generated by the system
synchronized (SequencedEvent.class) {
}
}
/**
* Dispatches the nested event after all previous nested events have been
* dispatched or disposed. If this method is invoked before all previous nested events
* have been dispatched, then this method blocks until such a point is
* reached.
* While waiting disposes nested events to disposed AppContext
*
* NOTE: Locking protocol. Since dispose() can get EventQueue lock,
* dispatch() shall never call dispose() while holding the lock on the list,
* as EventQueue lock is held during dispatching. The locks should be acquired
* in the same order.
*/
public final void dispatch() {
try {
if (getFirst() != this) {
if (EventQueue.isDispatchThread()) {
public boolean evaluate() {
return !SequencedEvent.this.isFirstOrDisposed();
}
});
} else {
while(!isFirstOrDisposed()) {
synchronized (SequencedEvent.class) {
try {
} catch (InterruptedException e) {
break;
}
}
}
}
}
if (!disposed) {
setCurrentSequencedEvent(this);
}
} finally {
dispose();
}
}
/**
* true only if event exists and nested source appContext is disposed.
*/
}
}
return false;
}
/**
* Sequenced events are dispatched in order, so we cannot dispatch
* until we are the first sequenced event in the queue (i.e. it's our
* turn). But while we wait for our turn to dispatch, the event
* could have been disposed for a number of reasons.
*/
public final boolean isFirstOrDisposed() {
if (disposed) {
return true;
}
// getFirstWithContext can dispose this
return this == getFirstWithContext() || disposed;
}
}
/* Disposes all events from disposed AppContext
* return first valid event
*/
while(isOwnerAppContextDisposed(first)) {
}
return first;
}
/**
* Disposes of this instance. This method is invoked once the nested event
* has been dispatched and handled, or when the peer of the target of the
* nested event has been disposed with a call to Component.removeNotify.
*
* NOTE: Locking protocol. Since SunToolkit.postEvent can get EventQueue lock,
* it shall never be called while holding the lock on the list,
* as EventQueue lock is held during dispatching and dispatch() will get
* lock on the list. The locks should be acquired in the same order.
*/
final void dispose() {
synchronized (SequencedEvent.class) {
if (disposed) {
return;
}
getCurrentSequencedEvent() == this) {
}
disposed = true;
}
// Wake myself up
if (appContext != null) {
}
synchronized (SequencedEvent.class) {
SequencedEvent.class.notifyAll();
list.removeFirst();
}
} else {
}
}
// Wake up waiting threads
}
}
}