Revision: 5882
Author: [email protected]
Date: Wed Aug  5 07:51:26 2009
Log: Minor tweaks to Layout code in response to post-TBR review.
Review: http://gwt-code-reviews.appspot.com/55804

http://code.google.com/p/google-web-toolkit/source/detail?r=5882

Modified:
  /trunk/user/javadoc/com/google/gwt/examples/LayoutPanelExample.java
  /trunk/user/src/com/google/gwt/layout/client/Layout.java
  /trunk/user/src/com/google/gwt/layout/client/LayoutImpl.java
  /trunk/user/src/com/google/gwt/layout/client/LayoutImplIE6.java
  /trunk/user/src/com/google/gwt/user/client/ui/LayoutPanel.java
  /trunk/user/src/com/google/gwt/user/client/ui/RootLayoutPanel.java
  /trunk/user/test/com/google/gwt/layout/client/LayoutTest.java

=======================================
--- /trunk/user/javadoc/com/google/gwt/examples/LayoutPanelExample.java Tue  
Aug  4 14:08:06 2009
+++ /trunk/user/javadoc/com/google/gwt/examples/LayoutPanelExample.java Wed  
Aug  5 07:51:26 2009
@@ -29,7 +29,7 @@
    public void onModuleLoad() {
      // Attach two child widgets to a LayoutPanel, laying them out  
horizontally,
      // splitting at 50%.
-    Widget childOne = new HTML(), childTwo = new HTML();
+    Widget childOne = new HTML("left"), childTwo = new HTML("right");
      LayoutPanel p = new LayoutPanel();
      p.add(childOne);
      p.add(childTwo);
=======================================
--- /trunk/user/src/com/google/gwt/layout/client/Layout.java    Tue Aug  4  
14:08:06 2009
+++ /trunk/user/src/com/google/gwt/layout/client/Layout.java    Wed Aug  5  
07:51:26 2009
@@ -50,7 +50,7 @@
   * element. There is a set of methods available on this class to  
manipulate the
   * child element's position and size. In order for changes to a layer to  
take
   * effect, you must finally call one of {...@link #layout()} or
- * {...@link #animate(int)}. This allows many changes to different layers to  
be
+ * {...@link #layout(int)}. This allows many changes to different layers to be
   * applied efficiently, and to be animated.
   * </p>
   *
@@ -78,7 +78,7 @@
  public class Layout {

    /**
-   * Callback interface used by {...@link Layout#animate(int,  
AnimationCallback)}
+   * Callback interface used by {...@link Layout#layout(int,  
AnimationCallback)}
     * to provide updates on animation progress.
     */
    public interface AnimationCallback {
@@ -294,107 +294,13 @@
    }

    /**
-   * Updates the layout by animating it over time.
-   *
-   * @param duration the duration of the animation
-   * @see #animate(int, AnimationCallback)
-   */
-  public void animate(int duration) {
-    animate(duration, null);
-  }
-
-  /**
-   * Updates the layout by animating it over time, with a callback on each  
frame
-   * of the animation, and upon completion.
-   *
-   * @param duration the duration of the animation
-   * @param callback the animation callback
-   */
-  public void animate(int duration, final AnimationCallback callback) {
-    // Deal with constraint changes (e.g. left-width => right-width, etc)
-    int parentWidth = parentElem.getClientWidth();
-    int parentHeight = parentElem.getClientHeight();
-    for (Layer l : layers) {
-      adjustHorizontalConstraints(parentWidth, l);
-      adjustVerticalConstraints(parentHeight, l);
-    }
-
-    // Cancel the old animation, if there is one.
-    if (animation != null) {
-      animation.cancel();
-    }
-
-    animation = new Animation() {
-      @Override
-      protected void onCancel() {
-        onComplete();
-      }
-
-      @Override
-      protected void onComplete() {
-        layout();
-        if (callback != null) {
-          callback.onAnimationComplete();
-        }
-        animation = null;
-      }
-
-      @Override
-      protected void onUpdate(double progress) {
-        for (Layer l : layers) {
-          if (l.setTargetLeft) {
-            l.left = l.sourceLeft + (l.targetLeft - l.sourceLeft) *  
progress;
-          }
-          if (l.setTargetRight) {
-            l.right = l.sourceRight + (l.targetRight - l.sourceRight)
-                * progress;
-          }
-          if (l.setTargetTop) {
-            l.top = l.sourceTop + (l.targetTop - l.sourceTop) * progress;
-          }
-          if (l.setTargetBottom) {
-            l.bottom = l.sourceBottom + (l.targetBottom - l.sourceBottom)
-                * progress;
-          }
-          if (l.setTargetWidth) {
-            l.width = l.sourceWidth + (l.targetWidth - l.sourceWidth)
-                * progress;
-          }
-          if (l.setTargetHeight) {
-            l.height = l.sourceHeight + (l.targetHeight - l.sourceHeight)
-                * progress;
-          }
-
-          impl.layout(l);
-          if (callback != null) {
-            callback.onLayout(l, progress);
-          }
-        }
-        impl.finalizeLayout(parentElem);
-      }
-    };
-
-    animation.run(duration);
-  }
-
-  /**
-   * Asserts that the given child element is managed by this layout
+   * Asserts that the given child element is managed by this layout.
     *
     * @param elem the element to be tested
     */
    public void assertIsChild(Element elem) {
      assert elem.getParentElement().getParentElement() ==  
this.parentElem : "Element is not a child of this layout";
    }
-
-  /**
-   * This method must be called when the parent element becomes attached  
to the
-   * document.
-   *
-   * @see #detach()
-   */
-  public void attach() {
-    impl.attach(parentElem);
-  }

    /**
     * Attaches a child element to this layout.
@@ -431,16 +337,6 @@
      layers.add(layer);
      return layer;
    }
-
-  /**
-   * This method must be called when the parent element becomes detached  
from
-   * the document.
-   *
-   * @see #attach()
-   */
-  public void detach() {
-    impl.detach(parentElem);
-  }

    /**
     * Causes the parent element to fill its own parent.
@@ -505,6 +401,110 @@

      impl.finalizeLayout(parentElem);
    }
+
+  /**
+   * Updates the layout by animating it over time.
+   *
+   * @param duration the duration of the animation
+   * @see #layout(int, AnimationCallback)
+   */
+  public void layout(int duration) {
+    layout(duration, null);
+  }
+
+  /**
+   * Updates the layout by animating it over time, with a callback on each  
frame
+   * of the animation, and upon completion.
+   *
+   * @param duration the duration of the animation
+   * @param callback the animation callback
+   */
+  public void layout(int duration, final AnimationCallback callback) {
+    // Deal with constraint changes (e.g. left-width => right-width, etc)
+    int parentWidth = parentElem.getClientWidth();
+    int parentHeight = parentElem.getClientHeight();
+    for (Layer l : layers) {
+      adjustHorizontalConstraints(parentWidth, l);
+      adjustVerticalConstraints(parentHeight, l);
+    }
+
+    // Cancel the old animation, if there is one.
+    if (animation != null) {
+      animation.cancel();
+    }
+
+    animation = new Animation() {
+      @Override
+      protected void onCancel() {
+        onComplete();
+      }
+
+      @Override
+      protected void onComplete() {
+        layout();
+        if (callback != null) {
+          callback.onAnimationComplete();
+        }
+        animation = null;
+      }
+
+      @Override
+      protected void onUpdate(double progress) {
+        for (Layer l : layers) {
+          if (l.setTargetLeft) {
+            l.left = l.sourceLeft + (l.targetLeft - l.sourceLeft) *  
progress;
+          }
+          if (l.setTargetRight) {
+            l.right = l.sourceRight + (l.targetRight - l.sourceRight)
+                * progress;
+          }
+          if (l.setTargetTop) {
+            l.top = l.sourceTop + (l.targetTop - l.sourceTop) * progress;
+          }
+          if (l.setTargetBottom) {
+            l.bottom = l.sourceBottom + (l.targetBottom - l.sourceBottom)
+                * progress;
+          }
+          if (l.setTargetWidth) {
+            l.width = l.sourceWidth + (l.targetWidth - l.sourceWidth)
+                * progress;
+          }
+          if (l.setTargetHeight) {
+            l.height = l.sourceHeight + (l.targetHeight - l.sourceHeight)
+                * progress;
+          }
+
+          impl.layout(l);
+          if (callback != null) {
+            callback.onLayout(l, progress);
+          }
+        }
+        impl.finalizeLayout(parentElem);
+      }
+    };
+
+    animation.run(duration);
+  }
+
+  /**
+   * This method must be called when the parent element becomes attached  
to the
+   * document.
+   *
+   * @see #onDetach()
+   */
+  public void onAttach() {
+    impl.onAttach(parentElem);
+  }
+
+  /**
+   * This method must be called when the parent element becomes detached  
from
+   * the document.
+   *
+   * @see #onAttach()
+   */
+  public void onDetach() {
+    impl.onDetach(parentElem);
+  }

    /**
     * Removes a child element from this layout.
=======================================
--- /trunk/user/src/com/google/gwt/layout/client/LayoutImpl.java        Tue Aug 
 4  
15:41:45 2009
+++ /trunk/user/src/com/google/gwt/layout/client/LayoutImpl.java        Wed Aug 
 5  
07:51:26 2009
@@ -60,10 +60,6 @@

    protected DivElement relativeRuler;

-  public void attach(Element parent) {
-    // Do nothing. This exists only to help LayoutImplIE6 avoid memory  
leaks.
-  }
-
    public Element attachChild(Element parent, Element child) {
      DivElement container = Document.get().createDivElement();
      container.appendChild(child);
@@ -80,10 +76,6 @@
      parent.appendChild(container);
      return container;
    }
-
-  public void detach(Element parent) {
-    // Do nothing. This exists only to help LayoutImplIE6 avoid memory  
leaks.
-  }

    public void fillParent(Element elem) {
      Style style = elem.getStyle();
@@ -146,6 +138,14 @@
      style.setProperty("height", layer.setHeight
          ? (layer.height + layer.heightUnit.getType()) : "");
    }
+
+  public void onAttach(Element parent) {
+    // Do nothing. This exists only to help LayoutImplIE6 avoid memory  
leaks.
+  }
+
+  public void onDetach(Element parent) {
+    // Do nothing. This exists only to help LayoutImplIE6 avoid memory  
leaks.
+  }

    public void removeChild(Element container, Element child) {
      container.removeFromParent();
=======================================
--- /trunk/user/src/com/google/gwt/layout/client/LayoutImplIE6.java     Tue  
Aug  4 14:08:06 2009
+++ /trunk/user/src/com/google/gwt/layout/client/LayoutImplIE6.java     Wed  
Aug  5 07:51:26 2009
@@ -110,16 +110,6 @@
        Element value) /*-{
      elem[name] = value;
    }-*/;
-
-  @Override
-  public void attach(Element parent) {
-    if (UserAgent.isIE6()) {
-      // No need to re-connect layer refs. This will be taken care of
-      // automatically in layout().
-      initResizeHandler(parent);
-      initUnitChangeHandler(parent, relativeRuler);
-    }
-  }

    public Element attachChild(Element parent, Element child) {
      if (!UserAgent.isIE6()) {
@@ -140,15 +130,6 @@
      parent.appendChild(container);
      return container;
    }
-
-  @Override
-  public void detach(Element parent) {
-    if (UserAgent.isIE6()) {
-      removeLayerRefs(parent);
-      removeResizeHandler(parent);
-      removeUnitChangeHandler(relativeRuler);
-    }
-  }

    @Override
    public void fillParent(Element elem) {
@@ -189,6 +170,25 @@
      Element elem = layer.getContainerElement();
      setLayer(elem, layer);
    }
+
+  @Override
+  public void onAttach(Element parent) {
+    if (UserAgent.isIE6()) {
+      // No need to re-connect layer refs. This will be taken care of
+      // automatically in layout().
+      initResizeHandler(parent);
+      initUnitChangeHandler(parent, relativeRuler);
+    }
+  }
+
+  @Override
+  public void onDetach(Element parent) {
+    if (UserAgent.isIE6()) {
+      removeLayerRefs(parent);
+      removeResizeHandler(parent);
+      removeUnitChangeHandler(relativeRuler);
+    }
+  }

    private native void fillParentImpl(Element elem) /*-{
      // Hook the parent element's onresize event. If the parent is the  
<body>,
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/LayoutPanel.java      Tue Aug 
  
4 15:41:45 2009
+++ /trunk/user/src/com/google/gwt/user/client/ui/LayoutPanel.java      Wed Aug 
  
5 07:51:26 2009
@@ -122,7 +122,7 @@
     * @see #layout(int,  
com.google.gwt.layout.client.Layout.AnimationCallback)
     */
    public void layout(int duration) {
-    layout.animate(duration);
+    layout.layout(duration);
    }

    /**
@@ -143,7 +143,7 @@
     * @see #layout(int,  
com.google.gwt.layout.client.Layout.AnimationCallback)
     */
    public void layout(int duration, final Layout.AnimationCallback  
callback) {
-    layout.animate(duration, new Layout.AnimationCallback() {
+    layout.layout(duration, new Layout.AnimationCallback() {
        public void onAnimationComplete() {
          // Chain to the passed callback.
          if (callback != null) {
@@ -195,11 +195,11 @@

    @Override
    protected void onLoad() {
-    layout.attach();
+    layout.onAttach();
    }

    @Override
    protected void onUnload() {
-    layout.detach();
+    layout.onDetach();
    }
  }
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/RootLayoutPanel.java  Tue  
Aug  4 14:08:06 2009
+++ /trunk/user/src/com/google/gwt/user/client/ui/RootLayoutPanel.java  Wed  
Aug  5 07:51:26 2009
@@ -81,7 +81,7 @@

    @Override
    protected void onLoad() {
-    getLayout().attach();
+    getLayout().onAttach();
      getLayout().fillParent();
    }
  }
=======================================
--- /trunk/user/test/com/google/gwt/layout/client/LayoutTest.java       Tue Aug 
  
4 14:08:06 2009
+++ /trunk/user/test/com/google/gwt/layout/client/LayoutTest.java       Wed Aug 
  
5 07:51:26 2009
@@ -54,7 +54,7 @@

    @Override
    public String getModuleName() {
-    return "com.google.gwt.layout.Layout";
+    return "com.google.gwt.layout.LayoutTest";
    }

    /**
@@ -164,7 +164,7 @@
      container.getStyle().setHeight(256, PX);

      Layout layout = new Layout(parent);
-    layout.attach();
+    layout.onAttach();
      Layer layer = layout.attachChild(child);
      layer.setTopBottom(0, PX, 0, PX);
      layer.setLeftRight(0, PX, 0, PX);
@@ -187,7 +187,7 @@
      assertEquals(256, parent.getOffsetWidth());
      assertEquals(256, child.getOffsetWidth());

-    layout.detach();
+    layout.onDetach();
    }

    /**
@@ -379,7 +379,7 @@
      doc.getBody().appendChild(parent);

      layout = new Layout(parent);
-    layout.attach();
+    layout.onAttach();
      layout.fillParent();

      layer0 = layout.attachChild(child0);
@@ -393,7 +393,7 @@
    protected void gwtTearDown() throws Exception {
      Window.enableScrolling(true);
      Document.get().getBody().removeChild(parent);
-    layout.detach();
+    layout.onDetach();
    }

    private void assertLeftRightTopBottomUnitsMakeSense(Element elem) {
@@ -500,7 +500,7 @@

      after.setupLayers(layer0, layer1);
      delayTestFinish(200);
-    layout.animate(100, new Layout.AnimationCallback() {
+    layout.layout(100, new Layout.AnimationCallback() {
        public void onAnimationComplete() {
          // Assert that the two layers have swapped positions.
          assertEquals(l0, wrapper1.getOffsetLeft());

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to