pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Bartlett <cbartlet...@gmail.com>
Subject Re: Center Dialog in Window
Date Fri, 26 Aug 2011 11:31:56 GMT
Denis,

Yes, that is what you need to do.

This line ...
window.open(display);
... starts to open the Frame, but it will fire the windowOpened event
before the Frame has been fully set up.

This means that your WindowStateListener will be called when the size
of the Frame is still 0 x 0 pixels.
(You can see this if you include this line in the windowOpened() method)
System.out.println(window.getSize());

The WindowStateListener opens the Dialog on top of the Frame.  The
Dialog will try to place itself in the centre of the Frame, but the
frame hasn't been given a size yet, so it ends up at position 0,0 (top
left corner)

ApplicationContext.queueCallback() will postpone the opening of the
Dialog until all other queued events have been processed.  When it
does execute, it the parent Frame will have been fully set up and it
will have a proper size, so the Dialog is shown where you expect it to
be shown.

Chris

On 26 August 2011 13:02, Denis Kononenko <deniskononenko@yahoo.com> wrote:
> It is correct?
>
> @Override
> public void windowOpened(final Window window) {
>    ApplicationContext.queueCallback(new Runnable() {
>        @Override
>        public void run() {
>            Dialog dlg = new Dialog("Test");
>            dlg.open(window);
>        }
>    });
> }
>
> full example
>
> import org.apache.pivot.collections.Map;
> import org.apache.pivot.wtk.*;
>
> public class App extends WindowStateListener.Adapter implements Application {
>    @Override
>    public void startup(Display display, Map<String, String> stringStringMap)
throws Exception {
>        window = new Frame();
>        window.getWindowStateListeners().add(this);
>        window.setStyles("{showWindowControls:false}");
>        window.setMaximized(true);
>        window.setTitle("Pivot");
>        window.open(display);
>    }
>
>    @Override
>    public void windowOpened(final Window window) {
>        ApplicationContext.queueCallback(new Runnable() {
>            @Override
>            public void run() {
>                Dialog dlg = new Dialog("Test");
>                dlg.open(window);
>            }
>        });
>    }
>
>    @Override
>    public boolean shutdown(boolean value) throws Exception {
>        if (window != null)
>            window.close();
>
>        return false;
>    }
>
>    @Override
>    public void suspend() throws Exception {
>    }
>
>    @Override
>    public void resume() throws Exception {
>    }
>
>    public static void main(String[] args) {
>        DesktopApplicationContext.main(App.class, args);
>    }
>
>    private Window window;
> }
>
>
>
> --- On Thu, 8/25/11, Denis Kononenko <deniskononenko@yahoo.com> wrote:
>
>> From: Denis Kononenko <deniskononenko@yahoo.com>
>> Subject: Re: Center Dialog in Window
>> To: user@pivot.apache.org
>> Date: Thursday, August 25, 2011, 6:39 PM
>> all the same as?
>> In WindowStateListener.windowOpened size win = 0,0. why?
>>
>> --- On Thu, 8/25/11, Denis Kononenko <deniskononenko@yahoo.com>
>> wrote:
>>
>> > From: Denis Kononenko <deniskononenko@yahoo.com>
>> > Subject: Re: Center Dialog in Window
>> > To: user@pivot.apache.org
>> > Date: Thursday, August 25, 2011, 2:14 AM
>> > import
>> > org.apache.pivot.collections.Map;
>> > import org.apache.pivot.wtk.*;
>> >
>> > public class App implements Application {
>> >     @Override
>> >     public void startup(Display display,
>> > Map<String, String> stringStringMap) throws
>> Exception
>> > {
>> >         window = new Frame();
>> >         window.setMaximized(true);
>> >         window.setTitle("Pivot");
>> >
>> >
>> > window.getWindowStateListeners().add(new
>> > WindowStateListener.Adapter(){
>> >             @Override
>> >             public void
>> > windowOpened(Window window) {
>> >
>> > Dialog dialog = new Dialog();
>> >
>> > dialog.open(window);
>> >             }
>> >         });
>> >
>> >         window.open(display);
>> >     }
>> >
>> >     @Override
>> >     public boolean shutdown(boolean value) throws
>> > Exception {
>> >         if (window != null)
>> >             window.close();
>> >
>> >         return false;
>> >     }
>> >
>> >     @Override
>> >     public void suspend() throws Exception {
>> >     }
>> >
>> >     @Override
>> >     public void resume() throws Exception {
>> >     }
>> >
>> >     public static void main(String[] args) {
>> >
>> > DesktopApplicationContext.main(App.class, args);
>> >     }
>> >
>> >     private Window window;
>> > }
>> >
>> >
>> > --- On Thu, 8/25/11, Chris Bartlett <cbartlett.x@gmail.com>
>> > wrote:
>> >
>> > > From: Chris Bartlett <cbartlett.x@gmail.com>
>> > > Subject: Re: Center Dialog in Window
>> > > To: user@pivot.apache.org
>> > > Date: Thursday, August 25, 2011, 1:56 AM
>> > > Denis,
>> > >
>> > > Have you seen this tutorial?
>> > > http://pivot.apache.org/tutorials/windows.html
>> > >
>> > > It shows how to open Frames, Alerts,
>> Dialogs,Prompts
>> > &
>> > > Sheets, and how
>> > > to position Windows with
>> > > http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Component.html#setLocation(int,
>> > > int)
>> > >
>> > > The source is available here.
>> > > http://svn.apache.org/repos/asf/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/
>> > >
>> > > On 25 August 2011 13:07, Denis Kononenko <deniskononenko@yahoo.com>
>> > > wrote:
>> > > > How open Dialog in center after opened main
>> > Window?
>> > > >
>> > > > Thanks
>> > > >
>> > >
>> >
>>
>

Mime
View raw message