package net.xoetrope.html;
import java.awt.AWTEvent;
// Do not optimize these imports..........it will give problems with early JDKs
import java.awt.*;
import java.awt.peer.*;
// ------------------------------------------------------------------------------
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.MenuComponent;
public class XDialogEventDispatchThread extends Thread
{
private EventQueue theQueue;
private boolean doDispatch = true;
XDialogEventDispatchThread( String name, EventQueue queue )
{
super( name );
theQueue = queue;
}
public void stopDispatching( boolean bFireEmptyEvent )
{
doDispatch = false;
// fix 4128923
// post an empty event to ensure getNextEvent
// is unblocked - rkhan 4/14/98
// TODO: Look into using Thread.interrupt() instead
if ( bFireEmptyEvent )
theQueue.postEvent( new EmptyEvent() );
// wait for the dispatcher to complete
if ( Thread.currentThread() != this ) {
try {
join();
}
catch ( InterruptedException e ) {
}
}
}
class EmptyEvent extends AWTEvent implements ActiveEvent
{
public EmptyEvent()
{
super( XDialogEventDispatchThread.this, 0 );
}
public void dispatch()
{
}
}
public void run()
{
while ( doDispatch ) {
try {
AWTEvent event = theQueue.getNextEvent();
if ( false ) {
// Not until 1.2...
// theQueue.dispatchEvent(event);
}
else {
// old code...
Object src = event.getSource();
if ( event instanceof ActiveEvent ) {
// This could become the sole method of dispatching in time, and
// moved to the event queue's dispatchEvent() method.
( (ActiveEvent)event ).dispatch();
}
else if ( src instanceof Component ) {
( (Component)src ).dispatchEvent( event );
}
else if ( src instanceof MenuComponent ) {
( (MenuComponent)src ).dispatchEvent( event );
}
}
}
catch ( ThreadDeath death ) {
return;
}
catch ( Throwable e ) {
System.err.println( "Exception occurred during event dispatching:" );
e.printStackTrace();
}
}
}
}