Waiting for a non-blocking dialog
- From: pauljlucas.removethis@xxxxxxxxxxxxxxxxxxxxx (Paul J. Lucas)
- Date: Mon, 29 Aug 2005 14:43:47 GMT
I'm using sample Apple code to use an "open file ***" (rather
than an "open dialog") -- if you've used Mac OS X, you'll know
that a "***" is the kind of dialog that slides down from the
top of a window like a window shade and is attached to its
parent window.
Anyway, the call to display the *** does so, but doesn't
block. I want the caller to block like an ordinary dialog, yet
have the event thread blocked so it can still process repain
events.
What I'm trying to do is push a new EventQueue, show the ***,
wait(), pop the ***, and continue. It works in the sense that
the event thread doesn't block, but what happens is quite often,
the entire program dies with a null pointer exception because
some of the events in the queue have null fields, i.e., it seems
like some events are bogus or corrupted somehow.
The sheet code from Apple uses an OpenSheetListener as a
callback. Both of the callback methods call notifyAll() to
allow the original thread of control to continue. Below is the
code.
Any ideas why the events are seemingly corrupted? It's most
likely a race condition, but I don't see where/why.
- Paul
class Open*** {
public Open***( Frame parentFrame ) {
m_parentFrame = parentFrame;
}
public String getSelectedFile() {
final PoppableEventQueue eq = new PoppableEventQueue();
Toolkit.getDefaultToolkit().getSystemEventQueue().push( eq );
final OpenSheetImpl os = new OpenSheetImpl();
os.show();
eq.pop();
return m_selectedFile;
}
private class OpenSheetImpl implements OpenSheetListener {
public synchronized void openSheetFinished( SheetEvent sheetEvent ) {
m_selectedFile = sheetEvent.getFilename();
notifyAll();
}
public synchronized void show() {
JSheetDelegate.showOpenSheet( m_parentFrame, this );
try {
wait();
}
catch ( InterruptedException e ) {
}
}
public synchronized void sheetCancelled() {
notifyAll();
}
}
private final Frame m_parentFrame;
private String m_selectedFile;
}
.
- Prev by Date: opening a window from an applet..
- Next by Date: Re: panel question..
- Previous by thread: opening a window from an applet..
- Next by thread: a strange problem regarding popup JDialogs/Windows
- Index(es):