// Copyright (C) 2008 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gwtexpui.user.client;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.WindowResizeListener;

/** A DialogBox that automatically re-centers itself if the window changes */
public class AutoCenterDialogBox extends PluginSafeDialogBox {
  private WindowResizeListener recenter;

  public AutoCenterDialogBox() {
    this(false);
  }

  public AutoCenterDialogBox(final boolean autoHide) {
    this(autoHide, true);
  }

  public AutoCenterDialogBox(final boolean autoHide, final boolean modal) {
    super(autoHide, modal);
  }

  @Override
  public void show() {
    if (recenter == null) {
      recenter = new WindowResizeListener() {
        public void onWindowResized(final int width, final int height) {
          onResize(width, height);
        }
      };
      Window.addWindowResizeListener(recenter);
    }
    super.show();
  }

  @Override
  protected void onUnload() {
    if (recenter != null) {
      Window.removeWindowResizeListener(recenter);
      recenter = null;
    }
    super.onUnload();
  }

  /**
   * Invoked when the outer browser window resizes.
   * <p>
   * Subclasses may override (but should ensure they still call super.onResize)
   * to implement custom logic when a window resize occurs.
   * 
   * @param width new browser window width
   * @param height new browser window height
   */
  protected void onResize(final int width, final int height) {
    if (isAttached()) {
      center();
    }
  }
}

@@ -666,34 +666,162 @@
 gle.gwt.
-user.client.Window
+event.logical.shared.ResizeEvent;%0Aimport com.google.gwt.event.logical.shared.ResizeHandler;%0Aimport com.google.gwt.event.shared.HandlerRegistration
 ;%0Aimport
@@ -854,30 +854,16 @@
 t.Window
-ResizeListener
 ;%0A%0A/** A
@@ -1008,36 +1008,35 @@
 private 
-WindowResizeListener
+HandlerRegistration
  recente
@@ -1372,110 +1372,213 @@
 er =
- new
  Window
+.add
 Resize
-Listener() %7B%0A        public void onWindowResized(final int width, final int h
+Handler(new ResizeHandler() %7B%0A        @Override%0A        public void onResize(final ResizeEvent event) %7B%0A          final int w = event.getWidth();%0A          final int h = event.getH
 eight
-) %7B
+();
 %0A   
@@ -1588,97 +1588,66 @@
     
-onResize(width, height);%0A        %7D%0A      %7D;%0A      Window.addWindowResizeListener(recenter
+AutoCenterDialogBox.this.onResize(w, h);%0A        %7D%0A      %7D
 );%0A 
@@ -1754,50 +1754,31 @@
     
-Window.removeWindowResizeListener(recenter
+recenter.removeHandler(
 );%0A 

Replace deprecated WindowListener with ResizeHandler