Smartclient resize listener

Questions, answers, tips and ideas on Servoy Client

Smartclient resize listener

Postby mboegem » Wed Mar 18, 2009 11:38 am

Does anyone know of a possibility to add a listener in order to dynamicaly handle resizing of the smart client?

What we actually want to do is equally tile/resize 16 small tabpanels in 1 form.
Anchoring can't be used as it will create overlap, so I was thinking of adding this listener to call a 'resize' method when the smart client gets resized.

Thnkx for any input!
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image

Partner of Tower - The most powerful Git client for Mac and Windows
User avatar
mboegem
 
Posts: 1743
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: Smartclient resize listener

Postby IT2Be » Wed Mar 18, 2009 12:29 pm

That is going to be quite a job marc :)

What you might be able to do (not sure if Servoy 'allows' you to use it though) is attach a java component listener to the window and listen to the resize event.

Maybe this will get you started: http://java.sun.com/docs/books/tutorial ... tener.html
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Re: Smartclient resize listener

Postby ROCLASI » Wed Mar 18, 2009 12:30 pm

Hi Marc,

I actually have filed this as a feature request: #175965 "onWindowResize (form) event"
Status is still set as 'New'.

But yeah, if we can do it with a method (and java) that would be great.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Smartclient resize listener

Postby ptalbot » Fri Mar 20, 2009 5:28 am

ROCLASI wrote:I actually have filed this as a feature request: #175965 "onWindowResize (form) event"
Status is still set as 'New'.

But yeah, if we can do it with a method (and java) that would be great.

Hi Robert,

in the meantime, you can use this (works in 4.1.1 - developer and smart client - not web client):
Code: Select all
// a form variable to test our listener:
var frmSize = null;

function resizeListener()
{
   /**
    * Listener callback function (called by the Servoy's frame when it is resized)
    */
   
   // The only argument is a java.awt.event.ComponentEvent:
   var e = arguments[0];
   if (e) {
      // get the component that fired this event (our frame):
      var frm = e.getComponent();
      // do whatever we need with its properties, here we set our variable to the frame size:
      frmSize = ""+frm.getWidth()+"x"+frm.getHeight();
   }
}

function onLoad_setFrameListener()
{
   /**
    * This function initializes and sets the frame component listener
    * it should only be called once (typically on an onLoad event)
    */

   // first, get a list of all frames:
   var frames = Packages.java.awt.Frame.getFrames();
   // then get the top most frame: first in the array
   var frm = frames[0];
   
   /*
    * Next is a workaround to avoid adding the same listener more than once
    * this is necessary in developer when you stop and start the solution again
    * to avoid having the listener being fired more than once
    *
    * NB: it might be dangerous if Servoy itself is registering a listener
    * From my tests, it is not the case yet
   */
   
   // get a list of all previous listeners
   var listeners = frm.getComponentListeners();
   // remove them
   for(i=0; i < listeners.length; i++) {
      var tmp = listeners[i];
      frm.removeComponentListener(tmp);
   }

   // now create an object implementing the ComponentListener interface (thanks to Rhino):
   // we can pass a function name to any event, here we pass
   // our resizeListener function
   var frmListener = new Packages.java.awt.event.ComponentListener({
      componentMoved: {},
      componentHidden: {},
      componentResized: resizeListener,
      componentShown: {}
   });
   
   // now add the component listener to the Servoy's frame:
   frm.addComponentListener(frmListener);
   // while we have the frame reference, get its size and assign to our variable:
   frmSize = ""+frm.getWidth()+"x"+frm.getHeight();
}


To test, paste in a form's script, assign the onLoad event to the "onLoad_setFrameListener", and put a field on your form pointing to the "frmSize" form variable...

Enjoy!
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Smartclient resize listener

Postby ROCLASI » Fri Mar 20, 2009 9:02 am

Hi Ptalbot,

Quick test shows that this does exactly what I want :D
Thank you !
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Smartclient resize listener

Postby mboegem » Fri Mar 20, 2009 9:28 pm

Thanks to all for the input!

@ptalbot: I think Robert tested it already, so I will go ahead and implement this pretty soon as well!
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image

Partner of Tower - The most powerful Git client for Mac and Windows
User avatar
mboegem
 
Posts: 1743
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: Smartclient resize listener

Postby erdione » Fri Nov 06, 2009 7:25 pm

Thank you very for this very useful tip

With Servoy 5 we can now use anchoring in webclient
How can i have a the same kind of listener ?
Fabrice
erdione
 
Posts: 112
Joined: Thu Feb 01, 2007 1:19 pm


Return to Servoy Client

Who is online

Users browsing this forum: No registered users and 10 guests