Revision: 6070
Author: [email protected]
Date: Tue Sep  1 19:11:26 2009
Log: Fix for issue 1112 (Add InsertPanel interface)
Review: http://gwt-code-reviews.appspot.com/57808
http://code.google.com/p/google-web-toolkit/source/detail?r=6070

Modified:
  /trunk/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java
  /trunk/user/src/com/google/gwt/user/client/ui/DeckPanel.java
  /trunk/user/src/com/google/gwt/user/client/ui/FlowPanel.java
  /trunk/user/src/com/google/gwt/user/client/ui/HorizontalPanel.java
  /trunk/user/src/com/google/gwt/user/client/ui/StackPanel.java
  /trunk/user/src/com/google/gwt/user/client/ui/VerticalPanel.java
  /trunk/user/test/com/google/gwt/user/client/ui/AbsolutePanelTest.java

=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java    Thu  
Nov 20 14:17:44 2008
+++ /trunk/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java    Tue  
Sep  1 19:11:26 2009
@@ -34,7 +34,7 @@
   * the widget may be modified by the panel.
   * </p>
   */
-public class AbsolutePanel extends ComplexPanel {
+public class AbsolutePanel extends ComplexPanel implements InsertPanel {

    /**
     * Changes a DOM element's positioning to static.
@@ -70,11 +70,6 @@
      setElement(elem);
    }

-  /**
-   * Adds a child widget to this panel.
-   *
-   * @param w the child widget to be added
-   */
    @Override
    public void add(Widget w) {
      super.add(w, getElement());
@@ -95,8 +90,9 @@
      // The Widget should be removed from its parent before any positional
      // changes are made to prevent flickering.
      w.removeFromParent();
+    int beforeIndex = getWidgetCount();
      setWidgetPositionImpl(w, left, top);
-    add(w);
+    insert(w, beforeIndex);
    }

    /**
@@ -124,6 +120,33 @@
      return DOM.getAbsoluteTop(w.getElement())
          - DOM.getAbsoluteTop(getElement());
    }
+
+  public void insert(Widget w, int beforeIndex) {
+    insert(w, getElement(), beforeIndex, true);
+  }
+
+  /**
+   * Inserts a child widget at the specified position before the specified
+   * index. Setting a position of <code>(-1, -1)</code> will cause the  
child
+   * widget to be positioned statically. If the widget is already a child  
of
+   * this panel, it will be moved to the specified index.
+   *
+   * @param w the child widget to be inserted
+   * @param left the widget's left position
+   * @param top the widget's top position
+   * @param beforeIndex the index before which it will be inserted
+   * @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out  
of
+   *           range
+   */
+  public void insert(Widget w, int left, int top, int beforeIndex) {
+    // In order to avoid the potential for a flicker effect, it is  
necessary
+    // to set the position of the widget before adding it to the  
AbsolutePanel.
+    // The Widget should be removed from its parent before any positional
+    // changes are made to prevent flickering.
+    w.removeFromParent();
+    setWidgetPositionImpl(w, left, top);
+    insert(w, beforeIndex);
+  }

    /**
     * Overrides {...@link ComplexPanel#remove(Widget)} to change the removed
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/DeckPanel.java        Wed May 
13  
08:08:49 2009
+++ /trunk/user/src/com/google/gwt/user/client/ui/DeckPanel.java        Tue Sep 
 1  
19:11:26 2009
@@ -31,7 +31,7 @@
   * cleared.
   * </p>
   */
-public class DeckPanel extends ComplexPanel implements HasAnimation {
+public class DeckPanel extends ComplexPanel implements HasAnimation,  
InsertPanel {
    /**
     * The duration of the animation.
     */
@@ -244,11 +244,6 @@
      setElement(DOM.createDiv());
    }

-  /**
-   * Adds the specified widget to the deck.
-   *
-   * @param w the widget to be added
-   */
    @Override
    public void add(Widget w) {
      Element container = createWidgetContainer();
@@ -276,14 +271,6 @@
      return getWidgetIndex(visibleWidget);
    }

-  /**
-   * Inserts a widget before the specified index.
-   *
-   * @param w the widget to be inserted
-   * @param beforeIndex the index before which it will be inserted
-   * @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out  
of
-   *           range
-   */
    public void insert(Widget w, int beforeIndex) {
      Element container = createWidgetContainer();
      DOM.insertChild(getElement(), container, beforeIndex);
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/FlowPanel.java        Wed May 
13  
08:08:49 2009
+++ /trunk/user/src/com/google/gwt/user/client/ui/FlowPanel.java        Tue Sep 
 1  
19:11:26 2009
@@ -26,7 +26,7 @@
   * <img class='gallery' src='FlowPanel.png'/>
   * </p>
   */
-public class FlowPanel extends ComplexPanel {
+public class FlowPanel extends ComplexPanel implements InsertPanel {

    /**
     * Creates an empty flow panel.
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/HorizontalPanel.java  Wed  
May 13 08:08:49 2009
+++ /trunk/user/src/com/google/gwt/user/client/ui/HorizontalPanel.java  Tue  
Sep  1 19:11:26 2009
@@ -25,7 +25,8 @@
   * <img class='gallery' src='HorizontalPanel.png'/>
   * </p>
   */
-public class HorizontalPanel extends CellPanel implements HasAlignment {
+public class HorizontalPanel extends CellPanel implements HasAlignment,
+    InsertPanel {

    private HorizontalAlignmentConstant horzAlign = ALIGN_DEFAULT;
    private Element tableRow;
@@ -42,12 +43,6 @@
      DOM.setElementProperty(getTable(), "cellPadding", "0");
    }

-  /**
-   * Adds a child widget to the panel. If the Widget is already attached  
to the
-   * HorizontalPanel, it will be moved to the end of the panel.
-   *
-   * @param w the widget to be added
-   */
    @Override
    public void add(Widget w) {
      Element td = createAlignedTd();
@@ -63,15 +58,6 @@
      return vertAlign;
    }

-  /**
-   * Inserts a widget before the specified index. If the Widget is already
-   * attached to the HorizontalPanel, it will be moved to the specified  
index.
-   *
-   * @param w the widget to be inserted
-   * @param beforeIndex the index before which it will be inserted
-   * @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out  
of
-   *           range
-   */
    public void insert(Widget w, int beforeIndex) {
      checkIndexBoundsForInsertion(beforeIndex);

=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/StackPanel.java       Wed May 
 
13 08:08:49 2009
+++ /trunk/user/src/com/google/gwt/user/client/ui/StackPanel.java       Tue Sep 
  
1 19:11:26 2009
@@ -38,7 +38,7 @@
   * {...@example com.google.gwt.examples.StackPanelExample}
   * </p>
   */
-public class StackPanel extends ComplexPanel {
+public class StackPanel extends ComplexPanel implements InsertPanel {
    private static final String DEFAULT_STYLENAME = "gwt-StackPanel";
    private static final String DEFAULT_ITEM_STYLENAME = DEFAULT_STYLENAME
        + "Item";
@@ -62,11 +62,6 @@
      setStyleName(DEFAULT_STYLENAME);
    }

-  /**
-   * Adds a new child with the given widget.
-   *
-   * @param w the widget to be added
-   */
    @Override
    public void add(Widget w) {
      insert(w, getWidgetCount());
@@ -104,14 +99,6 @@
      return visibleStack;
    }

-  /**
-   * Inserts a widget before the specified index.
-   *
-   * @param w the widget to be inserted
-   * @param beforeIndex the index before which it will be inserted
-   * @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out  
of
-   *           range
-   */
    public void insert(Widget w, int beforeIndex) {
      // header
      Element trh = DOM.createTR();
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/VerticalPanel.java    Wed  
May 13 08:08:49 2009
+++ /trunk/user/src/com/google/gwt/user/client/ui/VerticalPanel.java    Tue  
Sep  1 19:11:26 2009
@@ -25,7 +25,8 @@
   * <img class='gallery' src='VerticalPanel.png'/>
   * </p>
   */
-public class VerticalPanel extends CellPanel implements HasAlignment {
+public class VerticalPanel extends CellPanel implements HasAlignment,
+    InsertPanel {

    private HorizontalAlignmentConstant horzAlign = ALIGN_DEFAULT;
    private VerticalAlignmentConstant vertAlign = ALIGN_TOP;
@@ -38,12 +39,6 @@
      DOM.setElementProperty(getTable(), "cellPadding", "0");
    }

-  /**
-   * Adds a child widget to the panel. If the Widget is already attached  
to the
-   * VerticalPanel, it will be moved to the end of the panel.
-   *
-   * @param w the widget to be added
-   */
    @Override
    public void add(Widget w) {
      Element tr = DOM.createTR();
@@ -61,21 +56,13 @@
      return vertAlign;
    }

-  /**
-   * Inserts a widget before the specified index. If the Widget is already
-   * attached to the VerticalPanel, it will be moved to the specified  
index.
-   *
-   * @param w the widget to be inserted
-   * @param beforeIndex the index before which it will be inserted
-   * @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out  
of
-   *           range
-   */
    public void insert(Widget w, int beforeIndex) {
      checkIndexBoundsForInsertion(beforeIndex);

      Element tr = DOM.createTR();
      Element td = createAlignedTd();
      DOM.appendChild(tr, td);
+
      /*
       * The case where we reinsert an already existing child is tricky.
       *
=======================================
--- /trunk/user/test/com/google/gwt/user/client/ui/AbsolutePanelTest.java       
 
Thu Jul 30 13:47:31 2009
+++ /trunk/user/test/com/google/gwt/user/client/ui/AbsolutePanelTest.java       
 
Tue Sep  1 19:11:26 2009
@@ -22,7 +22,7 @@
  import com.google.gwt.user.client.Window;

  /**
- * TODO: document me.
+ * Tests for {...@link AbsolutePanel}.
   */
  public class AbsolutePanelTest extends GWTTestCase {

@@ -34,6 +34,19 @@
      HasWidgetsTester.testAll(new AbsolutePanel());
    }

+  /**
+   * AbsolutePanel once had a bug where calling
+   * {...@link AbsolutePanel#add(Widget, int, int)} twice on the same child  
widget
+   * would throw an {...@link IndexOutOfBoundsException}.
+   */
+  public void testDoubleAdd() {
+    AbsolutePanel absolutePanel = new AbsolutePanel();
+    Label label = new Label("label");
+
+    absolutePanel.add(label, 10, 10);
+    absolutePanel.add(label, 10, 10);
+  }
+
    @DoNotRunWith(Platform.Htmlunit)
    public void testPositioning() {
      // Make an absolute panel with a label at (3, 7).

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

Reply via email to