You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Bill van Melle <bi...@gmail.com> on 2010/12/01 23:00:15 UTC

Control of the startup window

I'm probably missing something obvious here, but since all the tutorials are
web-based, there doesn't seem to be any relevant documentation...

When I run as a desktop application, there seems to be a single (operating
system) window that is effectively the desktop for Pivot.

* Can I control its size?

* Can I learn its size?  When the user reshapes it, can I learn about that?

* Can I constrain my own org.apache.pivot.wtk.Window to be exactly the size
of this window?  (By default, it seems to behave like it has infinite
extent.)

* Can I escape this window, i.e., create a Pivot window/frame/dialog that is
a new (operating system) window?

Re: Control of the startup window

Posted by Chris Bartlett <cb...@gmail.com>.
Bill,

I'm sure Greg or someone else can give you a more complete answer, but here
is some info that should get you started.

Firstly, DesktopApplicationContext supports a number of command line
arguments that can be used to alter the host window upon startup.
http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java

Search for X_ARGUMENT and you will see them all grouped together

The arguments take the format of
--argument_name=value
(Note the 2 hypens at the start)

I'm not sure if these are documented elsewhere, but they should be fairly
simple to understand if you look at the source code.



You can also get a reference to the host window with the following code
java.awt.Frame hostFrame =
(java.awt.Frame)display.getDisplayHost().getParent();

If your app implements org.apache.pivot.wtk.Application, it will be receive
a Display object in its startup() method.
Refer to http://pivot.apache.org/tutorials/hello-world.html for an example.


On 2 December 2010 05:00, Bill van Melle <bi...@gmail.com> wrote:

> I'm probably missing something obvious here, but since all the tutorials
> are web-based, there doesn't seem to be any relevant documentation...
>
> When I run as a desktop application, there seems to be a single (operating
> system) window that is effectively the desktop for Pivot.
>
> * Can I control its size?
>
* Can I learn its size?  When the user reshapes it, can I learn about that?
>
You can use the startup properties mentioned above to determine start up
size and position.

This code will dump the size of the host frame, and resize it.
java.awt.Frame hostFrame =
(java.awt.Frame)display.getDisplayHost().getParent();
System.out.println(String.format("%-40s %-40s", "size",
hostFrame.getSize()));
hostFrame.setSize(200, 200);
System.out.println(String.format("%-40s %-40s", "size",
hostFrame.getSize()));
hostFrame.setSize(100, 100);
System.out.println(String.format("%-40s %d %d", "xy", hostFrame.getX(),
hostFrame.getY()));

You can interact with the java.awt.Frame and add your own listeners
hostFrame.getWindowStateListeners();
hostFrame.getWindowListeners();
etc


> * Can I constrain my own org.apache.pivot.wtk.Window to be exactly the size
> of this window?  (By default, it seems to behave like it has infinite
> extent.)
>
http://pivot.apache.org/tutorials/hello-wtkx.html
See    maximized="true"


> * Can I escape this window, i.e., create a Pivot window/frame/dialog that
> is a new (operating system) window?
>
I'm not sure if this is currently possible.

https://issues.apache.org/jira/browse/PIVOT-418
Perhaps this JIRA ticket is relevant, but I don't know exactly what
functionality the change brings.
Greg should be able to fill you in.

Chris

Re: Control of the startup window

Posted by Greg Brown <gk...@verizon.net>.
> When I run as a desktop application, there seems to be a single (operating system) window that is effectively the desktop for Pivot.
> 
> * Can I control its size?

As Chris mentioned, you can use the DesktopApplicationContext startup parameters to specify an initial size. You can also call getDisplay().getHostWindow() on any component to get a reference to the native (AWT) host window.

> * Can I learn its size?  When the user reshapes it, can I learn about that?

Yes - you can get the size of the AWT host, and you can either listen for AWT events fired by that window, or you can listen for ComponentListener#sizeChanged() events on the Pivot display. For portability, the latter is probably a better option.

> * Can I constrain my own org.apache.pivot.wtk.Window to be exactly the size of this window?  (By default, it seems to behave like it has infinite extent.)

Yes - if you set the "maximized" property of your Window to true, it will always fill the entire display.

> * Can I escape this window, i.e., create a Pivot window/frame/dialog that is a new (operating system) window?

Yes - you can call DesktopApplicationContext.createDisplay(). This will create a new display on which windows can also be opened. It is similar to calling window.open() in a web browser. The new display host is optionally modal - see this example and the Javadoc for more info:

http://svn.apache.org/repos/asf/pivot/trunk/examples/src/org/apache/pivot/examples/displays/multiple_display_example.bxml

G