Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Waiting for non-blocking open sheet



	I'm using sample Apple code to use an "open file sheet" (rather
	than an "open dialog") -- you know, 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 sheet does so, but doesn't
	block.  I want the caller to block like an ordinary dialog, yet
	not 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 sheet,
	wait(), pop the sheet, 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 OpenSheet {
    public OpenSheet( 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;
}
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.