Mailing Lists: Apple Mailing Lists

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

Re: Waiting for non-blocking open sheet



Paul J. Lucas wrote:

    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.

There are two event loops running in sync -- the Java/Swing event loop, and AppKit's. When the sheet is up, it needs to get events from the AppKit event loop (it might even push its own). Are you calling show from the Java/Swing event dispatch thread? Blocking the event dispatch thread waiting for events on the AppKit thread may be problematic. If you are calling from a different thread, I would expect this code to work (without pushing a new event loop instance).

Note that sheets are fundamentally asynchronous (much like X11
callbacks). Since the sheet is window-modal, you should not
have any issues with components on the primary pane of the
window being active, the issue is just one of synchronizing
the calling code, and having it wait for the sheet to finish.

What is PoppableEventQueue? I Goggled it, but got no hits.

I think your problem is likely in the sync between the AppKit
and Java event queues, and that getting it right will require
inside knowledge of how Apple makes the event loop work. That
will require a DTS incident. For a quick and easy solution, I
suggest trying to call the sheet from a different thread, and
not messing around with creating a nested event loop. There is
serious voodoo going on between Swing and AppKit here.

There is also a timing issue when setting up an event loop in
Swing. I have seen calls to performSelectorOnMainThread (in
NSObject, called from Objective-C) sit waiting to execute until
a nested event loop finishes. A delay of a few hundred millis
to allow the nested event loop to stabilize before opening the
sheet might help. For more info on the timing issue, see:

http://lists.apple.com/archives/java-dev/2005/May/msg00453.html
_______________________________________________
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.