Search code examples
gxt

What's the right way to be notified when a Window is resized?


I have an application that places several Windows within a com.extjs.gxt.desktop.client.Desktop. I need to attach a listener which records the size of each window when it is resized. I'm seeing two issues:

  1. While Move Events are fired when the window is resized, they appear to be fired BEFORE the new size is actually applied to the window, so I cannot request the new size from the window directly.

  2. The WindowEvent I receive in my Listener contains a size of 0x0, regardless of the actual size of the window.

Is there something I'm missing here?

Here's my attach code:

protected void addWindowListeners( Window w,
        String uid, WindowData windowData )
{
    WindowChangeListener l = new WindowChangeListener( uid, windowData );
    w.addWindowListener( l );
    // Add this again since the default WindowListener doesn't support the Move event.
    w.addListener( Events.Move, l );
}

And the listener class:

protected class WindowChangeListener 
    extends WindowListener
    implements Listener<WindowEvent>
{

    @Override
    public void windowHide( WindowEvent we )
    {
        updateWindowData( we );
    }

    @Override
    public void windowShow( WindowEvent we )
    {
        updateWindowData( we );
    }

    public void windowMove( WindowEvent we )
    {
        updateWindowData( we );
    }

    protected void updateWindowData( WindowEvent we )
    {
        // Here's the part that needs to get notified with the new size.
    }

    @Override
    public void handleEvent( WindowEvent we )
    {
        if( we.getType() == Events.Move )
            windowMove( we );
        else
            super.handleEvent( we );
    }
}

Thanks for any insight anyone has. I feel like I've got to be missing something simple.


Solution

  • I actually was given the magic on the Sencha forums: http://www.sencha.com/forum/showthread.php?121249-What-s-the-right-way-to-be-notified-when-a-Window-is-resized&p=561340&posted=1#post561340

    Turns out that I can listen for a resize event on Window:

    protected void addWindowListeners( Window w,
            String uid, WindowData windowData )
    {
        w.addListener( Events.Resize, new Listener<WindowEvent>() {
    
            @Override
            public void handleEvent( WindowEvent we )
            {
                System.out.println( "Resize event: " + we );
                System.out.println( "   Size in event: " + we.getWidth() + "x" + we.getHeight() );
                System.out.println( "   Size of window: " + we.getWindow().getSize() );
            }
    
        });
    }