2011-01-10 69 views
1

我有一個應用程序,在一個com.extjs.gxt.desktop.client.Desktop放置幾個Windows。我需要附加一個偵聽器,它在調整大小時記錄每個窗口的大小。我看到兩個問題:調整窗口大小時需要通知的正確方法是什麼?

  1. 而當窗口大小,它們出現之前,新的大小實際上是施加給車窗被解僱移動事件被解僱,所以我不能從請求新的大小直接窗口。

  2. 無論窗口的實際大小如何,在我的偵聽器中接收到的WindowEvent都包含大小0x0。

有什麼我在這裏失蹤?

這裏是我的代碼附加:

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); 
} 

而且監聽器類:

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); 
    } 
} 

感謝任何見解的人都有。我覺得我必須錯過簡單的東西。

回答

1

我實際上被賦予了神奇的煎茶論壇: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

證明,我可以偵聽窗口resize事件:

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()); 
     } 

    }); 
}