Return-Path: Delivered-To: apmail-pivot-user-archive@www.apache.org Received: (qmail 31679 invoked from network); 26 Jan 2010 19:43:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 26 Jan 2010 19:43:14 -0000 Received: (qmail 78584 invoked by uid 500); 26 Jan 2010 19:43:13 -0000 Delivered-To: apmail-pivot-user-archive@pivot.apache.org Received: (qmail 78532 invoked by uid 500); 26 Jan 2010 19:43:13 -0000 Mailing-List: contact user-help@pivot.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@pivot.apache.org Delivered-To: mailing list user@pivot.apache.org Received: (qmail 78523 invoked by uid 99); 26 Jan 2010 19:43:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Jan 2010 19:43:13 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of tvolkert@gmail.com designates 209.85.210.181 as permitted sender) Received: from [209.85.210.181] (HELO mail-yx0-f181.google.com) (209.85.210.181) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Jan 2010 19:43:05 +0000 Received: by yxe11 with SMTP id 11so3559969yxe.15 for ; Tue, 26 Jan 2010 11:42:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=mVMUrwsuzNWOr5rL7kZIYsu9mq5jB9yMbK54NYk29+g=; b=AFF8EqyQ9Vu+QJ8DVRk6oiC9ti72L3uVhCw/Vfh7/uDU/MgPFVtVAsDZ9kPipBwnDR JEQ+au2gi+S/qXCDJkmrYylodNII7mnicUdiUx4Ej1nMWGMtuZ1f8gMuz8BDb0IJFWQp tBUy8r3nFEoIDH7JMNECL9kHBpFVih6JDR5+k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=UTB/CJXhZuHFM/1N9gY5ZppOp7vGRCnMlD9eKLM8NPwojuC3eAc8Tes/hSGo/H9ZV7 9fvwWo7yY4P/xn9l+M7OnQuegEf9SWTiyQtMbK80NqA0g5fqGrBI0kEmUU9ackjJMk1x SB/YyySUsV5irPG7frkVS6jg0yk2OwjY6BLR8= MIME-Version: 1.0 Received: by 10.100.50.10 with SMTP id x10mr5860169anx.154.1264534964397; Tue, 26 Jan 2010 11:42:44 -0800 (PST) In-Reply-To: References: <4B5E581D.2080604@hms.harvard.edu> <4B5F1D97.7030203@hms.harvard.edu> <508D35C5-C4C8-480F-AD85-D0255030231B@me.com> <4B5F22B9.9010009@hms.harvard.edu> <168ef9ac1001260946g9ab967s8e062d6581c3d847@mail.gmail.com> <4B5F2B4A.90908@hms.harvard.edu> <25A24210-0C9E-4D84-9AEC-65D1CDEB3450@me.com> <4C4E1A04-0991-4141-A40A-72BD6857840E@mac.com> Date: Tue, 26 Jan 2010 14:42:44 -0500 Message-ID: <168ef9ac1001261142i6065bb50r18c216d3f9f69b02@mail.gmail.com> Subject: Re: Blocking while a dialog/prompt/alert/sheet is open, like Javascript's alert() ? From: Todd Volkert To: user@pivot.apache.org Content-Type: multipart/alternative; boundary=0016e64719d65be897047e167d78 --0016e64719d65be897047e167d78 Content-Type: text/plain; charset=ISO-8859-1 However, that's not code that you should use in production, because you're calling gui.openDialog() on a worker thread, which opens up a slew of multi-threading issues. UI methods are meant to be called on the EDT and provide no synchronization constructs. -T On Tue, Jan 26, 2010 at 2:32 PM, Andreas Siegrist wrote: > I was just thinking of how to achieve the simple task to get a javascript > like alert(), where the business logic stops until the user closes the > alert. > And here is was I'm suggesting and this works: > > import java.util.concurrent.Semaphore; > > import org.apache.pivot.wtk.Dialog; > import org.apache.pivot.wtk.DialogStateListener; > > public class Model implements Runnable { > private static App gui; > private Model() {} > > @Override > public void run() { > // The business logic > BlockingNotifier.alert("Wait, I've stopped the business > logic"); > System.out.println("ok now I run again"); > BlockingNotifier.alert("bye"); > } > > public static void start(App app) { > gui = app; > new Thread(new Model()).start(); > } > > private static class BlockingNotifier { > private static Semaphore lock = new Semaphore(0); > > public static void alert(String txt) { > DialogStateListener listener = new > DialogStateListener.Adapter() { > @Override > public void dialogClosed(Dialog arg0, > boolean arg1) { > lock.release(); > } > }; > gui.openDialog(txt, listener); > try { > lock.acquire(); > } catch (InterruptedException e) { > e.printStackTrace(); > } > } > } > } > > import org.apache.pivot.collections.Map; > import org.apache.pivot.wtk.*; > > public class App implements Application { > private BoxPane content = new BoxPane(); > Frame frame = new Frame(); > > @Override > public void resume() throws Exception {} > > @Override > public boolean shutdown(boolean arg0) throws Exception { > return false; > } > > @Override > public void startup(Display arg0, Map arg1) > throws Exception { > frame.open(arg0); > frame.setContent(content); > Model.start(this); > } > > @Override > public void suspend() throws Exception {} > > public static void main(String[] args) { > DesktopApplicationContext.main(App.class, args); > } > > public void openDialog(String txt, DialogStateListener listener) { > Dialog dialog = new Dialog(); > dialog.setContent(new Label(txt)); > dialog.open(frame); > dialog.getDialogStateListeners().add(listener); > } > } > > > > On Jan 26, 2010, at 7:45 PM, Greg Brown wrote: > > > I'm not sure exactly what you are suggesting here. All UI-related > operations must occur on the EDT. This includes model updates as well as > business logic. > > > > You can execute any task in the background, but you must always notify > the UI by calling ApplicationContext.queueCallback(). You shouldn't ever > call into the UI directly from another thread. > > > > > > On Jan 26, 2010, at 1:00 PM, Andreas Siegrist wrote: > > > >> It's impossible. > >> So you should keep the gui and your model+logic in seperate threads. > >> It's the only way to do the thing you want. > >> > >> On Jan 26, 2010, at 6:50 PM, Clint Gilbert wrote: > >> > >>> -----BEGIN PGP SIGNED MESSAGE----- > >>> Hash: SHA1 > >>> > >>> > >>> Yeah, that's the behavior I saw when I tried a solution like Andreas's > >>> using a CountDownLatch or a Lock/Condition pair. :( > >>> > >>> Todd Volkert wrote: > >>>> But the dialog is opened on the EDT, meaning that you'll lock up the > UI thread, and the UI will appear to hang. > >>>> > >>>> -T > >>>> > >>>> On Tue, Jan 26, 2010 at 12:43 PM, Andreas Siegrist < > andreas.siegrist@me.com> wrote: > >>>> I'm sorry I think I've misunderstood your questions. > >>>> So if you want to do that: > >>>> new Dialog("ajsdfoj"); > >>>> System.out.println("I'm 100% sure that the Dialog is closed now!"); > >>>> > >>>> try it with this class: > >>>> > >>>> import java.util.concurrent.Semaphore; > >>>> > >>>> import org.apache.pivot.wtk.Dialog; > >>>> import org.apache.pivot.wtk.DialogCloseListener; > >>>> import org.apache.pivot.wtk.Display; > >>>> import org.apache.pivot.wtk.Window; > >>>> > >>>> public class BlockingDialog extends Dialog { > >>>> static Semaphore lock = new Semaphore(0); > >>>> > >>>> public void open(Display display, Window owner, boolean modal) { > >>>> DialogCloseListener closeListener = new > DialogCloseListener() { > >>>> @Override > >>>> public void dialogClosed(Dialog arg0, > boolean arg1) { > >>>> lock.release(); > >>>> } > >>>> }; > >>>> open(display, owner, modal, closeListener); > >>>> > >>>> try { > >>>> lock.acquire(); > >>>> } catch (InterruptedException e) { > >>>> e.printStackTrace(); > >>>> } > >>>> } > >>>> } > >>>> > >>>> > >>>> On Jan 26, 2010, at 6:13 PM, Clint Gilbert wrote: > >>>> > >>>> Thanks very much, I'll try this out later. I tried similar strategies > >>>> with different util.concurrent primitives, but never with a Semaphore > in > >>>> this way. > >>>> > >>>> Andreas Siegrist wrote: > >>>>>>> like that: > >>>>>>> > >>>>>>> import java.util.concurrent.Semaphore; > >>>>>>> > >>>>>>> import org.apache.pivot.wtk.Dialog; > >>>>>>> import org.apache.pivot.wtk.DialogCloseListener; > >>>>>>> import org.apache.pivot.wtk.Display; > >>>>>>> import org.apache.pivot.wtk.Window; > >>>>>>> > >>>>>>> public class DialogProxy extends Dialog { > >>>>>>> static Semaphore lock = new Semaphore(1); > >>>>>>> > >>>>>>> public void open(Display display, Window owner, boolean modal) { > >>>>>>> try { > >>>>>>> lock.acquire(); > >>>>>>> DialogCloseListener closeListener = new > DialogCloseListener() { > >>>>>>> @Override > >>>>>>> public void dialogClosed(Dialog arg0, > boolean arg1) { > >>>>>>> lock.release(); > >>>>>>> } > >>>>>>> }; > >>>>>>> open(display, owner, modal, closeListener); > >>>>>>> > >>>>>>> } catch (InterruptedException e) { > >>>>>>> e.printStackTrace(); > >>>>>>> } > >>>>>>> } > >>>>>>> } > >>>>>>> > >>>>>>> > >>>>>>> On Jan 26, 2010, at 5:51 PM, Clint Gilbert wrote: > >>>>>>> > >>>>>>> Could you elaborate on this please? > >>>>>>> > >>>>>>> Andreas Siegrist wrote: > >>>>>>>>>> Hi there > >>>>>>>>>> > >>>>>>>>>> I also did something like that > >>>>>>>>>> All I needed to do is making a Proxy class with a synchronized > method. > >>>>>>>>>> > >>>>>>>>>> Andreas > >>>>>>>>>> > >>>>>>>>>> On Jan 26, 2010, at 3:06 PM, Christopher Brind wrote: > >>>>>>>>>> > >>>>>>>>>>> Hi Bob, > >>>>>>>>>>> > >>>>>>>>>>> This isn't really about being modal, but about stopping the > flow of execution. For example, in Javascript: > >>>>>>>>>>> > >>>>>>>>>>> Alert.show("hello"); > >>>>>>>>>>> Alert.show("world"); > >>>>>>>>>>> > >>>>>>>>>>> The second alert doesn't appear until you press OK on the > first. > >>>>>>>>>>> > >>>>>>>>>>> In Pivot or Swing (and every other UI framework?) if you popup > an Alert processing continues, for instance in Flex: > >>>>>>>>>>> > >>>>>>>>>>> Alert.show("hello"); > >>>>>>>>>>> Alert.show("world"); > >>>>>>>>>>> > >>>>>>>>>>> The second alert appears immediately and on top of the previous > one. > >>>>>>>>>>> > >>>>>>>>>>> Clint wants to achieve the first scenario, but this is not > possible with Pivot. > >>>>>>>>>>> > >>>>>>>>>>> Cheers, > >>>>>>>>>>> Chris > >>>>>>>>>>> > >>>>>>>>>>> > >>>>>>>>>>> > >>>>>>>>>>> 2010/1/26 Bob Santos bob.santosjr@gmail.com>> > >>>>>>>>>>> If I'm not mistaken, in Swing, you can create confirm > dialogs(Yes/No), message dialogs or option dialogs by using JOptionPane and > also I think they are by default modal(?), which means access to other part > of the application is not allowed until interaction with the active dialog > is done. > >>>>>>>>>>> > >>>>>>>>>>> You can also create your custom dialog by extending Dialog and > specifying the modality. > >>>>>>>>>>> > >>>>>>>>>>> And yes it helps to know that everything you want to do with > the UI should be done within the EDT as Greg stated. > >>>>>>>>>>> > >>>>>>>>>>> > >>>>>>>>>>> > >>>>>>>>>>> On Tue, Jan 26, 2010 at 9:40 PM, Greg Brown > wrote: > >>>>>>>>>>> Hi Clint, > >>>>>>>>>>> > >>>>>>>>>>>> Now, my question: Is it possible to achieve behavior like the > >>>>>>>>>>>> Javascript's alert() function with Pivot? That is, I'd like > to put up a > >>>>>>>>>>>> simple yes/no "do something"/"please don't" popup on the > screen, and > >>>>>>>>>>>> have the app block - the alert doesn't just block input to > other > >>>>>>>>>>>> elements - until the user chooses an option, or closes the > popup. This > >>>>>>>>>>>> is possible in SWT, I don't know about Swing. > >>>>>>>>>>> Sorry, it is not possible - as you noted, Window#open() is not > a blocking call in WTK. Pivot is ultimately based on AWT, which uses a push > model for event notifications (vs. pull). If you were to call a blocking > method from a user input event such as a button press, no further event > processing could occur until that method had returned, and the entire UI > would appear to freeze. > >>>>>>>>>>> > >>>>>>>>>>> I personally don't mind the anonymous inner class syntax: > >>>>>>>>>>> > >>>>>>>>>>> dialog.open(owner, new DialogCloseListener() { > >>>>>>>>>>> @Override > >>>>>>>>>>> public void dialogClosed(Dialog dialog, boolean modal) { > >>>>>>>>>>> // Get selected option and act on it > >>>>>>>>>>> } > >>>>>>>>>>> }); > >>>>>>>>>>> > >>>>>>>>>>> I actually think this reflects a pretty consistent design - you > open the dialog in response to one event (e.g. "button pressed"), and you > handle the dialog's result in response to another event (e.g. "dialog > closed"). > >>>>>>>>>>> > >>>>>>>>>>>> Making the call to Dialog.open() from another thread doesn't > have any effect. > >>>>>>>>>>> Note that, as in Swing, multi-threaded access to UI elements is > not supported. All UI operations must be performed on the EDT. > >>>>>>>>>>> > >>>>>>>>>>> Hope this helps, > >>>>>>>>>>> Greg > >>>>>>>>>>> > >>>>>>>>>>> > >>>>>>>>>>> > >>> -----BEGIN PGP SIGNATURE----- > >>> Version: GnuPG v1.4.9 (GNU/Linux) > >>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > >>> > >>> iEYEARECAAYFAktfK0oACgkQ5IyIbnMUeTuAqQCeOW6N30B02+lbxrC1NZPTeabs > >>> d1UAn3kkJ8ihtRhF+8Q6Tl4G9N0diW9m > >>> =p74V > >>> -----END PGP SIGNATURE----- > >> > > > > --0016e64719d65be897047e167d78 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable However, that's not code that you should use in production, because you= 're calling gui.openDialog() on a worker thread, which opens up a slew = of multi-threading issues.=A0 UI methods are meant to be called on the EDT = and provide no synchronization constructs.

-T

On Tue, Jan 26, 2010 at 2:32 PM, A= ndreas Siegrist <andreas.siegrist@me.com> wrote:
I was just thinking of how to achieve the simple task to get a javascript l= ike alert(), where the business logic stops until the user closes the alert= .
And here is was I'm suggesting and this works:

import java.util.concurrent.Semaphore;

import org.apache.pivot.wtk.Dialog;
import org.apache.pivot.wtk.DialogStateListener;

public class Model implements Runnable {
=A0 =A0 =A0 =A0private static App gui;
=A0 =A0 =A0 =A0private Model() {}

=A0 =A0 =A0 =A0@Override
=A0 =A0 =A0 =A0public void run() {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// The business logic
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0BlockingNotifier.alert("Wait, I've= stopped the business logic");
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0System.out.println("ok now I run again= ");
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0BlockingNotifier.alert("bye"); =A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0public static void start(App app) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0gui =3D app;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0new Thread(new Model()).start();
=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0private static class BlockingNotifier {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0private static Semaphore lock =3D new Semap= hore(0);

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0public static void alert(String txt) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0DialogStateListener listene= r =3D new DialogStateListener.Adapter() {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0@Override
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0public void= dialogClosed(Dialog arg0, boolean arg1) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0lock.release();
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0};
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0gui.openDialog(txt, l= istener);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0try {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0lock.acquir= e();
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} catch (InterruptedExcepti= on e) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0e.printStac= kTrace();
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
=A0 =A0 =A0 =A0}
}

import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.*;

public class App implements Application {
=A0 =A0 =A0 =A0private BoxPane content =3D new BoxPane();
=A0 =A0 =A0 =A0Frame frame =3D new Frame();

=A0 =A0 =A0 =A0@Override
=A0 =A0 =A0 =A0public void resume() throws Exception {}

=A0 =A0 =A0 =A0@Override
=A0 =A0 =A0 =A0public boolean shutdown(boolean arg0) throws Exception { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return false;
=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0@Override
=A0 =A0 =A0 =A0public void startup(Display arg0, Map<String, String>= arg1)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0throws Exception {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0frame.open(arg0);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0frame.setContent(content);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Model.start(this);
=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0@Override
=A0 =A0 =A0 =A0public void suspend() throws Exception {}

=A0 =A0 =A0 =A0public static void main(String[] args) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0DesktopApplicationContext.main(App.class, a= rgs);
=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0public void openDialog(String txt, DialogStateListener list= ener) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Dialog dialog =3D new Dialog();
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dialog.setContent(new Label(txt));
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dialog.open(frame);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dialog.getDialogStateListeners().add(listen= er);
=A0 =A0 =A0 =A0}
}



On Jan 26, 2010, at 7:45 PM, Greg Brown wrote:

> I'm not sure exactly what you are suggesting here. All UI-related = operations must occur on the EDT. This includes model updates as well as bu= siness logic.
>
> You can execute any task in the background, but you must always notify= the UI by calling ApplicationContext.queueCallback(). You shouldn't ev= er call into the UI directly from another thread.
>
>
> On Jan 26, 2010, at 1:00 PM, Andreas Siegrist wrote:
>
>> It's impossible.
>> So you should keep the gui and your model+logic in seperate thread= s.
>> It's the only way to do the thing you want.
>>
>> On Jan 26, 2010, at 6:50 PM, Clint Gilbert wrote:
>>
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>>
>>>
>>> Yeah, that's the behavior I saw when I tried a solution li= ke Andreas's
>>> using a CountDownLatch or a Lock/Condition pair. :(
>>>
>>> Todd Volkert wrote:
>>>> But the dialog is opened on the EDT, meaning that you'= ll lock up the UI thread, and the UI will appear to hang.
>>>>
>>>> -T
>>>>
>>>> On Tue, Jan 26, 2010 at 12:43 PM, Andreas Siegrist <andreas.siegrist@me.com<mail= to:andreas.siegrist@me.com&g= t;> wrote:
>>>> I'm sorry I think I've misunderstood your question= s.
>>>> So if you want to do that:
>>>> new Dialog("ajsdfoj");
>>>> System.out.println("I'm 100% sure that the Dialog= is closed now!");
>>>>
>>>> try it with this class:
>>>>
>>>> import java.util.concurrent.Semaphore;
>>>>
>>>> import org.apache.pivot.wtk.Dialog;
>>>> import org.apache.pivot.wtk.DialogCloseListener;
>>>> import org.apache.pivot.wtk.Display;
>>>> import org.apache.pivot.wtk.Window;
>>>>
>>>> public class BlockingDialog extends Dialog {
>>>> =A0 =A0 static Semaphore lock =3D new Semaphore(0);
>>>>
>>>> =A0 =A0 public void open(Display display, Window owner, bo= olean modal) {
>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DialogCloseListene= r closeListener =3D new DialogCloseListener() {
>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 @O= verride
>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pu= blic void dialogClosed(Dialog arg0, boolean arg1) {
>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 lock.release();
>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }<= br> >>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 };
>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 open(display, owne= r, modal, closeListener);
>>>>
>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 try {
>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 lo= ck.acquire();
>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } catch (Interrupt= edException e) {
>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 e.= printStackTrace();
>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
>>>> =A0 =A0 }
>>>> }
>>>>
>>>>
>>>> On Jan 26, 2010, at 6:13 PM, Clint Gilbert wrote:
>>>>
>>>> Thanks very much, I'll try this out later. =A0I tried = similar strategies
>>>> with different util.concurrent primitives, but never with = a Semaphore in
>>>> this way.
>>>>
>>>> Andreas Siegrist wrote:
>>>>>>> like that:
>>>>>>>
>>>>>>> import java.util.concurrent.Semaphore;
>>>>>>>
>>>>>>> import org.apache.pivot.wtk.Dialog;
>>>>>>> import org.apache.pivot.wtk.DialogCloseListene= r;
>>>>>>> import org.apache.pivot.wtk.Display;
>>>>>>> import org.apache.pivot.wtk.Window;
>>>>>>>
>>>>>>> public class DialogProxy extends Dialog {
>>>>>>> =A0 static Semaphore lock =3D new Semaphore(1)= ;
>>>>>>>
>>>>>>> =A0 public void open(Display display, Window o= wner, boolean modal) {
>>>>>>> =A0 =A0 =A0 =A0 =A0 try {
>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 lock.acqui= re();
>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DialogClos= eListener closeListener =3D new DialogCloseListener() {
>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 @Override
>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 public void dialogClosed(Dialog arg0, boolean arg1) {
>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 lock.release();
>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 }
>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 };
>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 open(displ= ay, owner, modal, closeListener);
>>>>>>>
>>>>>>> =A0 =A0 =A0 =A0 =A0 } catch (InterruptedExcept= ion e) {
>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 e.printSta= ckTrace();
>>>>>>> =A0 =A0 =A0 =A0 =A0 }
>>>>>>> =A0 }
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> On Jan 26, 2010, at 5:51 PM, Clint Gilbert wro= te:
>>>>>>>
>>>>>>> Could you elaborate on this please?
>>>>>>>
>>>>>>> Andreas Siegrist wrote:
>>>>>>>>>> Hi there
>>>>>>>>>>
>>>>>>>>>> I also did something like that
>>>>>>>>>> All I needed to do is making a Pro= xy class with a synchronized method.
>>>>>>>>>>
>>>>>>>>>> Andreas
>>>>>>>>>>
>>>>>>>>>> On Jan 26, 2010, at 3:06 PM, Chris= topher Brind wrote:
>>>>>>>>>>
>>>>>>>>>>> Hi Bob,
>>>>>>>>>>>
>>>>>>>>>>> This isn't really about be= ing modal, but about stopping the flow of execution. =A0For example, in Jav= ascript:
>>>>>>>>>>>
>>>>>>>>>>> Alert.show("hello");=
>>>>>>>>>>> Alert.show("world");=
>>>>>>>>>>>
>>>>>>>>>>> The second alert doesn't a= ppear until you press OK on the first.
>>>>>>>>>>>
>>>>>>>>>>> In Pivot or Swing (and every o= ther UI framework?) if you popup an Alert processing continues, for instanc= e in Flex:
>>>>>>>>>>>
>>>>>>>>>>> Alert.show("hello");=
>>>>>>>>>>> Alert.show("world");=
>>>>>>>>>>>
>>>>>>>>>>> The second alert appears immed= iately and on top of the previous one.
>>>>>>>>>>>
>>>>>>>>>>> Clint wants to achieve the fir= st scenario, but this is not possible with Pivot.
>>>>>>>>>>>
>>>>>>>>>>> Cheers,
>>>>>>>>>>> Chris
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> 2010/1/26 Bob Santos <bob.santosjr@gmail.com<mailto:<= a href=3D"mailto:bob.santosjr@gmail.com">bob.santosjr@gmail.com>>=
>>>>>>>>>>> If I'm not mistaken, in Sw= ing, you can create confirm dialogs(Yes/No), message dialogs or option dial= ogs by using JOptionPane and also I think they are by default modal(?), whi= ch means access to other part of the application is not allowed until inter= action with the active dialog is done.
>>>>>>>>>>>
>>>>>>>>>>> You can also create your custo= m dialog by extending Dialog and specifying the modality.
>>>>>>>>>>>
>>>>>>>>>>> And yes it helps to know that = everything you want to do with the UI should be done within the EDT as Greg= stated.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Tue, Jan 26, 2010 at 9:40 P= M, Greg Brown <gkbrown@mac.com<= ;mailto:gkbrown@mac.com>> wrot= e:
>>>>>>>>>>> Hi Clint,
>>>>>>>>>>>
>>>>>>>>>>>> Now, my question: Is it po= ssible to achieve behavior like the
>>>>>>>>>>>> Javascript's alert() f= unction with Pivot? =A0That is, I'd like to put up a
>>>>>>>>>>>> simple yes/no "do som= ething"/"please don't" popup on the screen, and
>>>>>>>>>>>> have the app block - the a= lert doesn't just block input to other
>>>>>>>>>>>> elements - until the user = chooses an option, or closes the popup. =A0This
>>>>>>>>>>>> is possible in SWT, I don&= #39;t know about Swing.
>>>>>>>>>>> Sorry, it is not possible - as= you noted, Window#open() is not a blocking call in WTK. Pivot is ultimatel= y based on AWT, which uses a push model for event notifications (vs. pull).= If you were to call a blocking method from a user input event such as a bu= tton press, no further event processing could occur until that method had r= eturned, and the entire UI would appear to freeze.
>>>>>>>>>>>
>>>>>>>>>>> I personally don't mind th= e anonymous inner class syntax:
>>>>>>>>>>>
>>>>>>>>>>> dialog.open(owner, new DialogC= loseListener() {
>>>>>>>>>>> =A0 @Override
>>>>>>>>>>> =A0 public void dialogClosed(D= ialog dialog, boolean modal) {
>>>>>>>>>>> =A0 =A0 =A0 // Get selected op= tion and act on it
>>>>>>>>>>> =A0 }
>>>>>>>>>>> });
>>>>>>>>>>>
>>>>>>>>>>> I actually think this reflects= a pretty consistent design - you open the dialog in response to one event = (e.g. "button pressed"), and you handle the dialog's result i= n response to another event (e.g. "dialog closed").
>>>>>>>>>>>
>>>>>>>>>>>> Making the call to Dialog.= open() from another thread doesn't have any effect.
>>>>>>>>>>> Note that, as in Swing, multi-= threaded access to UI elements is not supported. All UI operations must be = performed on the EDT.
>>>>>>>>>>>
>>>>>>>>>>> Hope this helps,
>>>>>>>>>>> Greg
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>> -----BEGIN PGP SIGNATURE-----
>>> Version: GnuPG v1.4.9 (GNU/Linux)
>>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>>>
>>> iEYEARECAAYFAktfK0oACgkQ5IyIbnMUeTuAqQCeOW6N30B02+lbxrC1NZPTea= bs
>>> d1UAn3kkJ8ihtRhF+8Q6Tl4G9N0diW9m
>>> =3Dp74V
>>> -----END PGP SIGNATURE-----
>>
>


--0016e64719d65be897047e167d78--