Removes the use of FinallyCommand in StackLayoutPanel. This works around
a Scheduler bug that's causing StackLayoutPanel to misbehave slightly.
Review: http://gwt-code-reviews.appspot.com/115804

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@7225 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/CustomButton.java b/user/src/com/google/gwt/user/client/ui/CustomButton.java
index c3d3f80..0536c47 100644
--- a/user/src/com/google/gwt/user/client/ui/CustomButton.java
+++ b/user/src/com/google/gwt/user/client/ui/CustomButton.java
@@ -20,7 +20,6 @@
 import com.google.gwt.dom.client.NativeEvent;
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.resources.client.ImageResource;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
diff --git a/user/src/com/google/gwt/user/client/ui/StackLayoutPanel.java b/user/src/com/google/gwt/user/client/ui/StackLayoutPanel.java
index 8b6b392..743d79d 100644
--- a/user/src/com/google/gwt/user/client/ui/StackLayoutPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/StackLayoutPanel.java
@@ -15,8 +15,6 @@
  */
 package com.google.gwt.user.client.ui;
 
-import com.google.gwt.core.client.Scheduler;
-import com.google.gwt.core.client.Scheduler.ScheduledCommand;
 import com.google.gwt.dom.client.Style.Unit;
 import com.google.gwt.user.client.Event;
 
@@ -132,7 +130,7 @@
    * @param header the header widget
    * @param headerSize the size of the header widget
    */
-  public void add(Widget widget, Widget header, double headerSize) {
+  public void add(final Widget widget, Widget header, double headerSize) {
     ClickWrapper wrapper = new ClickWrapper(widget, header);
     layoutPanel.add(wrapper);
     layoutPanel.add(widget);
@@ -144,8 +142,9 @@
     layoutData.add(data);
 
     if (visibleWidget == null) {
-      // Don't animate the initial widget display.
-      showWidget(widget, 0);
+      // If there's no visible widget, display the first one. The layout will
+      // be updated onLoad().
+      visibleWidget = widget;
     }
   }
 
@@ -205,6 +204,12 @@
     showWidget(widget, ANIMATION_TIME);
   }
 
+  @Override
+  protected void onLoad() {
+    // When the widget becomes attached, update its layout.
+    animate(0);
+  }
+
   private void animate(int duration) {
     int top = 0, bottom = 0;
     int i = 0, visibleIndex = -1;
@@ -241,10 +246,6 @@
 
   private void showWidget(Widget widget, final int duration) {
     visibleWidget = widget;
-    Scheduler.get().scheduleFinally(new ScheduledCommand() {
-      public void execute() {
-        animate(duration);
-      }
-    });
+    animate(duration);
   }
 }