Revision: 7444
Author: j...@google.com
Date: Fri Jan 22 05:44:27 2010
Log: http://gwt-code-reviews.appspot.com/132817
http://code.google.com/p/google-web-toolkit/source/detail?r=7444
Added:
/trunk/user/test/com/google/gwt/user/client/ui/SplitLayoutPanelTest.java
/trunk/user/test/com/google/gwt/user/client/ui/StackLayoutPanelTest.java
Modified:
/trunk/user/build.xml
/trunk/user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java
/trunk/user/src/com/google/gwt/user/client/ui/StackLayoutPanel.java
/trunk/user/test/com/google/gwt/layout/client/LayoutTest.java
/trunk/user/test/com/google/gwt/user/UISuite.java
/trunk/user/test/com/google/gwt/user/client/ui/TabLayoutPanelTest.java
=======================================
--- /dev/null
+++
/trunk/user/test/com/google/gwt/user/client/ui/SplitLayoutPanelTest.java
Fri Jan 22 05:44:27 2010
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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.gwt.user.client.ui;
+
+/**
+ * Tests for {...@link SplitLayoutPanel}.
+ */
+public class SplitLayoutPanelTest extends WidgetTestBase {
+
+ static class Adder implements HasWidgetsTester.WidgetAdder {
+ public void addChild(HasWidgets container, Widget child) {
+ ((SplitLayoutPanel) container).addNorth(child, 10);
+ }
+ }
+
+ public void testAttachDetachOrder() {
+ HasWidgetsTester.testAll(new SplitLayoutPanel(), new Adder(), true);
+ }
+
+ public void testReplaceCenterWidget() {
+ SplitLayoutPanel p = new SplitLayoutPanel();
+ Label l0 = new Label("foo");
+ Label l1 = new Label("bar");
+ Label l2 = new Label("baz");
+
+ // center: l1
+ p.addWest(l0, 64);
+ p.add(l1);
+ assertEquals(l1, p.getCenter());
+
+ // center: l2
+ p.remove(l1);
+ p.add(l2);
+ assertEquals(l2, p.getCenter());
+ }
+
+ public void testSplitterOrder() {
+ SplitLayoutPanel p = new SplitLayoutPanel();
+ WidgetCollection children = p.getChildren();
+
+ Label l0 = new Label("foo");
+ Label l1 = new Label("bar");
+ Label l2 = new Label("baz");
+ Label l3 = new Label("tintin");
+ Label l4 = new Label("toto");
+
+ p.addWest(l0, 64);
+ assertEquals(l0, children.get(0));
+ assertEquals(SplitLayoutPanel.HSplitter.class,
children.get(1).getClass());
+
+ p.addNorth(l1, 64);
+ assertEquals(l1, children.get(2));
+ assertEquals(SplitLayoutPanel.VSplitter.class,
children.get(3).getClass());
+
+ p.addEast(l2, 64);
+ assertEquals(l2, children.get(4));
+ assertEquals(SplitLayoutPanel.HSplitter.class,
children.get(5).getClass());
+
+ p.addSouth(l3, 64);
+ assertEquals(l3, children.get(6));
+ assertEquals(SplitLayoutPanel.VSplitter.class,
children.get(7).getClass());
+
+ p.add(l4);
+ assertEquals(l4, children.get(8));
+ }
+
+ public void testRemoveInsert() {
+ SplitLayoutPanel p = new SplitLayoutPanel();
+ WidgetCollection children = p.getChildren();
+
+ Label l0 = new Label("foo");
+ Label l1 = new Label("bar");
+ Label l2 = new Label("baz");
+
+ p.addWest(l0, 64);
+ p.add(l1);
+ assertEquals(l0, children.get(0));
+ assertEquals(SplitLayoutPanel.HSplitter.class,
children.get(1).getClass());
+ assertEquals(l1, children.get(2));
+
+ p.remove(l0);
+ p.insertWest(l2, 64, l1);
+ assertEquals(l2, children.get(0));
+ assertEquals(SplitLayoutPanel.HSplitter.class,
children.get(1).getClass());
+ assertEquals(l1, children.get(2));
+ }
+}
=======================================
--- /dev/null
+++
/trunk/user/test/com/google/gwt/user/client/ui/StackLayoutPanelTest.java
Fri Jan 22 05:44:27 2010
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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.gwt.user.client.ui;
+
+import com.google.gwt.dom.client.Style.Unit;
+
+/**
+ * Tests for {...@link StackLayoutPanel}.
+ */
+public class StackLayoutPanelTest extends WidgetTestBase {
+
+ static class Adder implements HasWidgetsTester.WidgetAdder {
+ public void addChild(HasWidgets container, Widget child) {
+ ((StackLayoutPanel) container).add(child, new Label("Header"), 1);
+ }
+ }
+
+ public void testAttachDetachOrder() {
+ HasWidgetsTester.testAll(new StackLayoutPanel(Unit.EM), new Adder(),
true);
+ }
+
+ public void testEmptyAdd() {
+ // Issue 4414: Attaching an empty StackLayoutPanel caused an exception.
+ StackLayoutPanel p = new StackLayoutPanel(Unit.EM);
+ RootPanel.get().add(p);
+ }
+
+ public void testVisibleWidget() {
+ StackLayoutPanel p = new StackLayoutPanel(Unit.EM);
+ assertNull(p.getVisibleWidget());
+
+ Label l0 = new Label("foo");
+ Label l1 = new Label("bar");
+ Label l2 = new Label("baz");
+
+ // Add one widget, and ensure that it's visible.
+ p.add(l0, new Label("header"), 1);
+ assertEquals(l0, p.getVisibleWidget());
+
+ // Remove the same, and ensure that there's no visible widget.
+ p.remove(l0);
+ assertNull(p.getVisibleWidget());
+
+ // Add all three.
+ p.add(l0, new Label("header"), 1);
+ p.add(l1, new Label("header"), 1);
+ p.add(l2, new Label("header"), 1);
+
+ // l0 should be visible by default.
+ assertEquals(l0, p.getVisibleWidget());
+
+ // Removing l0 (currently visible) should cause l1 to be shown.
+ p.remove(l0);
+ assertEquals(l1, p.getVisibleWidget());
+
+ // Now ensure that showing l2 works properly.
+ p.showWidget(l2);
+ assertEquals(l2, p.getVisibleWidget());
+ }
+}
=======================================
--- /trunk/user/build.xml Fri Jan 15 11:17:28 2010
+++ /trunk/user/build.xml Fri Jan 22 05:44:27 2010
@@ -45,7 +45,7 @@
<!--
Run LayoutTest in CSS standards mode
-->
- <property name="gwt.junit.testcase.standards.includes"
value="**/LayoutTest.class" />
+ <property name="gwt.junit.testcase.standards.includes"
value="**/*Layout*Test.class" />
<property name="gwt.junit.testcase.standards.excludes" value="" />
<!--
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java Wed
Nov 25 08:06:44 2009
+++ /trunk/user/src/com/google/gwt/user/client/ui/SplitLayoutPanel.java Fri
Jan 22 05:44:27 2010
@@ -53,7 +53,7 @@
*/
public class SplitLayoutPanel extends DockLayoutPanel {
- private class HSplitter extends Splitter {
+ class HSplitter extends Splitter {
public HSplitter(Widget target, boolean reverse) {
super(target, reverse);
getElement().getStyle().setPropertyPx("width", SPLITTER_SIZE);
@@ -81,7 +81,7 @@
}
}
- private abstract class Splitter extends Widget {
+ abstract class Splitter extends Widget {
protected final Widget target;
private int offset;
@@ -176,7 +176,7 @@
}
}
- private class VSplitter extends Splitter {
+ class VSplitter extends Splitter {
public VSplitter(Widget target, boolean reverse) {
super(target, reverse);
getElement().getStyle().setPropertyPx("height", SPLITTER_SIZE);
@@ -215,7 +215,7 @@
public void insert(Widget child, Direction direction, double size,
Widget before) {
super.insert(child, direction, size, before);
if (direction != Direction.CENTER) {
- insertSplitter(before);
+ insertSplitter(child, before);
}
}
@@ -227,7 +227,8 @@
// Remove the associated splitter, if any.
int idx = getWidgetIndex(child);
if (idx < getWidgetCount() - 1) {
- remove(idx + 1);
+ // Call super.remove(), or we'll end up recursing.
+ super.remove(getWidget(idx + 1));
}
return true;
}
@@ -264,30 +265,28 @@
return null;
}
- private void insertSplitter(Widget before) {
+ private void insertSplitter(Widget widget, Widget before) {
assert getChildren().size() > 0 : "Can't add a splitter before any
children";
- assert getCenter() == null : "Can't add a splitter after the CENTER
widget";
-
- Widget lastChild = getChildren().get(getChildren().size() - 1);
- LayoutData lastChildLayout = (LayoutData) lastChild.getLayoutData();
+
+ LayoutData layout = (LayoutData) widget.getLayoutData();
Splitter splitter = null;
- switch (lastChildLayout.direction) {
+ switch (layout.direction) {
case WEST:
- splitter = new HSplitter(lastChild, false);
+ splitter = new HSplitter(widget, false);
break;
case EAST:
- splitter = new HSplitter(lastChild, true);
+ splitter = new HSplitter(widget, true);
break;
case NORTH:
- splitter = new VSplitter(lastChild, false);
+ splitter = new VSplitter(widget, false);
break;
case SOUTH:
- splitter = new VSplitter(lastChild, true);
+ splitter = new VSplitter(widget, true);
break;
default:
assert false : "Unexpected direction";
}
- super.insert(splitter, lastChildLayout.direction, SPLITTER_SIZE,
before);
+ super.insert(splitter, layout.direction, SPLITTER_SIZE, before);
}
}
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/StackLayoutPanel.java Fri
Dec 4 11:09:56 2009
+++ /trunk/user/src/com/google/gwt/user/client/ui/StackLayoutPanel.java Fri
Jan 22 05:44:27 2010
@@ -150,8 +150,18 @@
public void clear() {
layoutPanel.clear();
+ layoutData.clear();
visibleWidget = null;
}
+
+ /**
+ * Gets the currently-selected widget.
+ *
+ * @return the selected widget, or <code>null</code> if none exist
+ */
+ public Widget getVisibleWidget() {
+ return visibleWidget;
+ }
public Iterator<Widget> iterator() {
return new Iterator<Widget>() {
@@ -185,14 +195,29 @@
}
public boolean remove(Widget child) {
- if (child.getParent() != this) {
+ if (child.getParent() != layoutPanel) {
return false;
}
- LayoutData data = (LayoutData) child.getLayoutData();
- layoutPanel.remove(data.header);
- layoutPanel.remove(child);
- return true;
+ // Find the layoutData associated with this widget and remove it.
+ for (int i = 0; i < layoutData.size(); ++i) {
+ LayoutData data = layoutData.get(i);
+ if (data.widget == child) {
+ layoutPanel.remove(data.header);
+ layoutPanel.remove(child);
+ layoutData.remove(i);
+
+ if (visibleWidget == child) {
+ visibleWidget = null;
+ if (layoutData.size() > 0) {
+ showWidget(layoutData.get(0).widget);
+ }
+ }
+ return true;
+ }
+ }
+
+ return false;
}
/**
@@ -211,6 +236,11 @@
}
private void animate(int duration) {
+ // Don't try to animate zero widgets.
+ if (layoutData.size() == 0) {
+ return;
+ }
+
double top = 0, bottom = 0;
int i = 0, visibleIndex = -1;
for (; i < layoutData.size(); ++i) {
=======================================
--- /trunk/user/test/com/google/gwt/layout/client/LayoutTest.java Tue Nov
10 10:16:43 2009
+++ /trunk/user/test/com/google/gwt/layout/client/LayoutTest.java Fri Jan
22 05:44:27 2010
@@ -30,6 +30,8 @@
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.junit.DoNotRunWith;
+import com.google.gwt.junit.Platform;
import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.layout.client.Layout.Alignment;
import com.google.gwt.layout.client.Layout.Layer;
@@ -42,6 +44,7 @@
* it reliably until we have a way to switch on "standards" mode in
* GWTTestCases.
*/
+...@donotrunwith(Platform.HtmlUnit)
public class LayoutTest extends GWTTestCase {
private static interface LayerInitializer {
=======================================
--- /trunk/user/test/com/google/gwt/user/UISuite.java Thu Jan 14 11:49:54
2010
+++ /trunk/user/test/com/google/gwt/user/UISuite.java Fri Jan 22 05:44:27
2010
@@ -59,7 +59,6 @@
import com.google.gwt.user.client.ui.HorizontalSplitPanelTest;
import com.google.gwt.user.client.ui.HyperlinkTest;
import com.google.gwt.user.client.ui.ImageTest;
-import com.google.gwt.user.client.ui.LayoutPanelTest;
import com.google.gwt.user.client.ui.LazyPanelTest;
import com.google.gwt.user.client.ui.LinearPanelTest;
import com.google.gwt.user.client.ui.ListBoxTest;
@@ -147,7 +146,6 @@
suite.addTestSuite(HyperlinkTest.class);
suite.addTestSuite(ImageBundleGeneratorTest.class);
suite.addTestSuite(ImageTest.class);
- suite.addTestSuite(LayoutPanelTest.class);
suite.addTestSuite(LazyPanelTest.class);
suite.addTestSuite(LinearPanelTest.class);
suite.addTestSuite(ListBoxTest.class);
=======================================
--- /trunk/user/test/com/google/gwt/user/client/ui/TabLayoutPanelTest.java
Thu Jan 14 11:09:34 2010
+++ /trunk/user/test/com/google/gwt/user/client/ui/TabLayoutPanelTest.java
Fri Jan 22 05:44:27 2010
@@ -20,6 +20,8 @@
import com.google.gwt.event.logical.shared.BeforeSelectionHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
+import com.google.gwt.junit.DoNotRunWith;
+import com.google.gwt.junit.Platform;
import com.google.gwt.junit.client.GWTTestCase;
import java.util.Iterator;
@@ -31,7 +33,7 @@
static class Adder implements HasWidgetsTester.WidgetAdder {
public void addChild(HasWidgets container, Widget child) {
- ((TabPanel) container).add(child, "foo");
+ ((TabLayoutPanel) container).add(child, "foo");
}
}
@@ -54,7 +56,7 @@
}
public void testAttachDetachOrder() {
- HasWidgetsTester.testAll(new TabPanel(), new Adder(), true);
+ HasWidgetsTester.testAll(new TabLayoutPanel(1, Unit.EM), new Adder(),
true);
}
public void testInsertMultipleTimes() {
@@ -176,6 +178,7 @@
/**
* Tests that tabs actually line up properly (see issue 4447).
*/
+ @DoNotRunWith(Platform.HtmlUnit)
public void testTabLayout() {
TabLayoutPanel p = new TabLayoutPanel(2, Unit.EM);
RootPanel.get().add(p);
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors