You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by ChesStrategy <Ch...@gmail.com> on 2010/11/15 01:01:33 UTC

Setting a minimum (enforced) size for the Display

Hi,

I've currently using Pivot for my project, after I decided to abandon Swing.
I prematurely apologize if this is a dumb question, since I've only recently
started using Pivot.

Basically, I was wondering if I could enforce a minimum size (width and
height) for the display of my Pivot Desktop Application; that is: 

In the event that the user resizes the Display to something smaller than the
minimum size and height of the child Window, that the Display will remain at
the minimum size of the enclosed child window. 

If the user has a large monitor, and sizes the Display to anything larger,
all the child elements and display will scale to the larger size.

Currently, I've tried to add a ComponentListener to the Display passed in
startup(). The componentListener has the sizeChanged() function implemented
to call DesktopApplicationContext.sizeToFit() on the child Window. However,
doing this causes the window to "seize" and flicker everytime the Display is
resized by the user to a size smaller than the minimum size; thus this
solution is not ideal.

Any tips and advice would be appreciated; however, I personally prefer to do
this completely programmatically in Java, and would not like to use WTKX
(for now), unless using a WTKX source with my application is the only
solution.

Thanks,
Dave


-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Setting-a-minimum-enforced-size-for-the-Display-tp1902028p1902028.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Setting a minimum (enforced) size for the Display

Posted by ChesStrategy <Ch...@gmail.com>.
Thanks for your help! It seems that from the source code listed below:


Greg Brown wrote:
> 
> public java.awt.Window getHostWindow() {
>         java.awt.Container parent = displayHost.getParent();
>         while (parent != null
>             && !(parent instanceof java.awt.Window)) {
>             parent = parent.getParent();
>         }
> 
>         if (parent == null) {
>             throw new IllegalArgumentException("Window does not have a
> native host.");
>         }
> 
>         return (java.awt.Window)parent;
>     }
> 
> 

That I need to call getParent() off of the display host; Ill try this and
cross my fingers.

Thanks,
Dave

-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Setting-a-minimum-enforced-size-for-the-Display-tp1902028p1917433.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Setting a minimum (enforced) size for the Display

Posted by Greg Brown <gk...@mac.com>.
The source code for getHostWindow() can be found here:

http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/Display.java

On Nov 17, 2010, at 12:28 AM, ChesStrategy wrote:

> 
> 
> Greg Brown wrote:
>> 
>> 
>> Sorry, we must have added that method for 2.0. You can still get access to
>> it in 1.5, though. Call getDisplayHost() on the display and then walk up
>> the AWT hierarchy until you find the root AWT Window. 
>> 
>> 
> 
> Could you just post your source; you mentioned that you were able to get it
> to work? Since I was not able to find getHostWindow() in java.awt.*. I tried
> the following and got an error when running my pivot application in eclipse:
> 
> 
> Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved
> compilation problem: 
> 	The method getHostWindow() is undefined for the type
> ApplicationContext.DisplayHost
> 
> 	at com.teamdl.spindle.Spindle.startup(Spindle.java:40)
> 	at
> org.apache.pivot.wtk.DesktopApplicationContext$HostFrame.processWindowEvent(DesktopApplicationContext.java:95)
> 	at java.awt.Window.processEvent(Unknown Source)
> 	at java.awt.Component.dispatchEventImpl(Unknown Source)
> 	at java.awt.Container.dispatchEventImpl(Unknown Source)
> 	at java.awt.Window.dispatchEventImpl(Unknown Source)
> 	at java.awt.Component.dispatchEvent(Unknown Source)
> 	at java.awt.EventQueue.dispatchEvent(Unknown Source)
> 	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
> 	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
> 	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
> 	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> 	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> 	at java.awt.EventDispatchThread.run(Unknown Source)
> 
> -- 
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Setting-a-minimum-enforced-size-for-the-Display-tp1902028p1915459.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: Setting a minimum (enforced) size for the Display

Posted by ChesStrategy <Ch...@gmail.com>.

Greg Brown wrote:
> 
> 
> Sorry, we must have added that method for 2.0. You can still get access to
> it in 1.5, though. Call getDisplayHost() on the display and then walk up
> the AWT hierarchy until you find the root AWT Window. 
> 
> 

Could you just post your source; you mentioned that you were able to get it
to work? Since I was not able to find getHostWindow() in java.awt.*. I tried
the following and got an error when running my pivot application in eclipse:


Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved
compilation problem: 
	The method getHostWindow() is undefined for the type
ApplicationContext.DisplayHost

	at com.teamdl.spindle.Spindle.startup(Spindle.java:40)
	at
org.apache.pivot.wtk.DesktopApplicationContext$HostFrame.processWindowEvent(DesktopApplicationContext.java:95)
	at java.awt.Window.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Setting-a-minimum-enforced-size-for-the-Display-tp1902028p1915459.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Setting a minimum (enforced) size for the Display

Posted by Greg Brown <gk...@mac.com>.
> On another note, is 1.5.2 the latest stable version? If 2.0 is stable, where
> could I grab it (as well as the javadoc?) Since on the apache pivot site
> 1.5.2 is the shown version; if 2.0 is still beta, then nevermind.

1.5.2 is the latest stable release, though I would recommend looking at 2.0 if you can. It is very close to release and offers a lot of improvements over 1.5.x.

> Also, in the very strange event that I am unable to get your suggestions to
> work, what would I need to do to make the entire application not resizeable,
> that is Window/"Host Frame"? and/or Display?

You can pass "--resizable=false" to DesktopApplicationContext. You can also pass --width and --height arguments to set the size. However, getting the root Window and setting a min size on it should work. Let me know if you run into any problems.

G


Re: Setting a minimum (enforced) size for the Display

Posted by ChesStrategy <Ch...@gmail.com>.
Ok, thanks for the help!


On another note, is 1.5.2 the latest stable version? If 2.0 is stable, where
could I grab it (as well as the javadoc?) Since on the apache pivot site
1.5.2 is the shown version; if 2.0 is still beta, then nevermind.

Also, in the very strange event that I am unable to get your suggestions to
work, what would I need to do to make the entire application not resizeable,
that is Window/"Host Frame"? and/or Display?

Thanks,
Dave
-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Setting-a-minimum-enforced-size-for-the-Display-tp1902028p1911552.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Setting a minimum (enforced) size for the Display

Posted by Greg Brown <gk...@mac.com>.
Sorry, we must have added that method for 2.0. You can still get access to it in 1.5, though. Call getDisplayHost() on the display and then walk up the AWT hierarchy until you find the root AWT Window.
G

On Nov 15, 2010, at 11:19 AM, ChesStrategy wrote:

> 
> 
> Greg Brown wrote:
>> 
>> You are setting the min. size on the display host in this example - you
>> need to set it on the host window (returned by getHostWindow(), not
>> getDisplayHost()). I just tried this and it seems to work fine.
>> 
> 
> This is probably a very dumb/trivial question, but, I cannot seem to find
> getHostWindow() in the 1.5.2 javadoc. I googled for getHostWindow(), and
> found some stuff on it in the commits mailing list, suggesting that it is a
> function of Display; but when I check org.apache.pivot.wtk.Display in the
> 1.5.2 javadoc, I don't see the function.. do you mean calling <name of
> display object>.getWindow().setMinimumSize(..) instead?
> 
> Thanks for all your help so far.
> Dave
> -- 
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Setting-a-minimum-enforced-size-for-the-Display-tp1902028p1905463.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: Setting a minimum (enforced) size for the Display

Posted by ChesStrategy <Ch...@gmail.com>.

Greg Brown wrote:
> 
> You are setting the min. size on the display host in this example - you
> need to set it on the host window (returned by getHostWindow(), not
> getDisplayHost()). I just tried this and it seems to work fine.
> 

This is probably a very dumb/trivial question, but, I cannot seem to find
getHostWindow() in the 1.5.2 javadoc. I googled for getHostWindow(), and
found some stuff on it in the commits mailing list, suggesting that it is a
function of Display; but when I check org.apache.pivot.wtk.Display in the
1.5.2 javadoc, I don't see the function.. do you mean calling <name of
display object>.getWindow().setMinimumSize(..) instead?

Thanks for all your help so far.
Dave
-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Setting-a-minimum-enforced-size-for-the-Display-tp1902028p1905463.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Setting a minimum (enforced) size for the Display

Posted by Greg Brown <gk...@mac.com>.
You are setting the min. size on the display host in this example - you need to set it on the host window (returned by getHostWindow(), not getDisplayHost()). I just tried this and it seems to work fine.

On Nov 14, 2010, at 10:30 PM, ChesStrategy wrote:

> 
> I've tried your solution and it does not seem to have any effect; Is it
> supposed to set the size of the Display (and enclosed Window) to 800x600 on
> startup()?
> 
> I have posted the code below for reference. constructContent() simply
> returns a BoxPane filled with other stuff.
> 
> Thanks,
> Dave
> 
> 
> private Window window;
> 
> public void startup(Display arg0, Map<String, String> arg1) throws Exception 
> {
> 	window = new Window();
> 
>        window.setTitle(Constants.APPTITLE);
>        window.setContent(constructContent());
>        window.setMaximized(true);
> 
> 	arg0.getDisplayHost().setMinimumSize(new Dimension(800,600));
> 		
> 	window.open(arg0);
> 		
> }
> 
> 
> -- 
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Setting-a-minimum-enforced-size-for-the-Display-tp1902028p1902622.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: Setting a minimum (enforced) size for the Display

Posted by Greg Brown <gk...@mac.com>.
One solution would be to have the native host respect the max/min size of the display. We might be able to do this simply by having DisplayHost override getMaximumSize() and getMinimumSize(). Feel free to enter a JIRA ticket for this if you think it would be useful.
G

On Nov 14, 2010, at 11:00 PM, ChesStrategy wrote:

> 
> With regard to the original undesirable solution of the window resizing, and
> then flickering back to its resized-but-less-than-minimum size...
> 
> If there is a way to check that both the componentListener's sizeChanged()
> method was fired, as well as a mouseUp event, the sizeToFit() method could
> be called during the mouseUp event; if this was possible, the window would
> still do its flicker action, but at least the window would remain the
> minimum size of 800x600.
> 
> 
> -- 
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Setting-a-minimum-enforced-size-for-the-Display-tp1902028p1902693.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: Setting a minimum (enforced) size for the Display

Posted by ChesStrategy <Ch...@gmail.com>.
With regard to the original undesirable solution of the window resizing, and
then flickering back to its resized-but-less-than-minimum size...

If there is a way to check that both the componentListener's sizeChanged()
method was fired, as well as a mouseUp event, the sizeToFit() method could
be called during the mouseUp event; if this was possible, the window would
still do its flicker action, but at least the window would remain the
minimum size of 800x600.


-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Setting-a-minimum-enforced-size-for-the-Display-tp1902028p1902693.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Setting a minimum (enforced) size for the Display

Posted by ChesStrategy <Ch...@gmail.com>.
I've tried your solution and it does not seem to have any effect; Is it
supposed to set the size of the Display (and enclosed Window) to 800x600 on
startup()?

I have posted the code below for reference. constructContent() simply
returns a BoxPane filled with other stuff.

Thanks,
Dave


private Window window;

public void startup(Display arg0, Map<String, String> arg1) throws Exception 
{
	window = new Window();

        window.setTitle(Constants.APPTITLE);
        window.setContent(constructContent());
        window.setMaximized(true);

	arg0.getDisplayHost().setMinimumSize(new Dimension(800,600));
		
	window.open(arg0);
		
}


-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Setting-a-minimum-enforced-size-for-the-Display-tp1902028p1902622.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Setting a minimum (enforced) size for the Display

Posted by Greg Brown <gk...@mac.com>.
This isn't currently supported. However, you could simply set a minimum size on the host window. For example, call setMinimumSize() on the value returned by Display#getHostWindow().

On Nov 14, 2010, at 7:01 PM, ChesStrategy wrote:

> 
> Hi,
> 
> I've currently using Pivot for my project, after I decided to abandon Swing.
> I prematurely apologize if this is a dumb question, since I've only recently
> started using Pivot.
> 
> Basically, I was wondering if I could enforce a minimum size (width and
> height) for the display of my Pivot Desktop Application; that is: 
> 
> In the event that the user resizes the Display to something smaller than the
> minimum size and height of the child Window, that the Display will remain at
> the minimum size of the enclosed child window. 
> 
> If the user has a large monitor, and sizes the Display to anything larger,
> all the child elements and display will scale to the larger size.
> 
> Currently, I've tried to add a ComponentListener to the Display passed in
> startup(). The componentListener has the sizeChanged() function implemented
> to call DesktopApplicationContext.sizeToFit() on the child Window. However,
> doing this causes the window to "seize" and flicker everytime the Display is
> resized by the user to a size smaller than the minimum size; thus this
> solution is not ideal.
> 
> Any tips and advice would be appreciated; however, I personally prefer to do
> this completely programmatically in Java, and would not like to use WTKX
> (for now), unless using a WTKX source with my application is the only
> solution.
> 
> Thanks,
> Dave
> 
> 
> -- 
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Setting-a-minimum-enforced-size-for-the-Display-tp1902028p1902028.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.