Adding new SimpleLayoutPanel widget, which is a subclass of SimplePanel that ProvidesResize to its child. This is useful when an application needs a content container to hold a Widget that RequiresResize.
Issue: 5501
Review at http://gwt-code-reviews.appspot.com/1291801
Review by: rjrjr@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9548 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/SimpleLayoutPanel.java b/user/src/com/google/gwt/user/client/ui/SimpleLayoutPanel.java
new file mode 100644
index 0000000..66bd402
--- /dev/null
+++ b/user/src/com/google/gwt/user/client/ui/SimpleLayoutPanel.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2011 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;
+import com.google.gwt.layout.client.Layout;
+import com.google.gwt.layout.client.Layout.Layer;
+
+/**
+ * A simple panel that {@link ProvidesResize} to its one child.
+ */
+public class SimpleLayoutPanel extends SimplePanel implements RequiresResize,
+ ProvidesResize {
+
+ private Layer layer;
+ private final Layout layout;
+
+ public SimpleLayoutPanel() {
+ layout = new Layout(getElement());
+ }
+
+ public void onResize() {
+ if (widget instanceof RequiresResize) {
+ ((RequiresResize) widget).onResize();
+ }
+ }
+
+ @Override
+ public boolean remove(Widget w) {
+ // Validate.
+ if (widget != w) {
+ return false;
+ }
+
+ // Orphan.
+ try {
+ orphan(w);
+ } finally {
+ // Physical detach.
+ layout.removeChild(layer);
+ layer = null;
+
+ // Logical detach.
+ widget = null;
+ }
+ return true;
+ }
+
+ @Override
+ public void setWidget(Widget w) {
+ // Validate
+ if (w == widget) {
+ return;
+ }
+
+ // Detach new child.
+ if (w != null) {
+ w.removeFromParent();
+ }
+
+ // Remove old child.
+ if (widget != null) {
+ remove(widget);
+ }
+
+ // Logical attach.
+ widget = w;
+
+ if (w != null) {
+ // Physical attach.
+ layer = layout.attachChild(widget.getElement(), widget);
+ layer.setTopHeight(0.0, Unit.PX, 100.0, Unit.PCT);
+ layer.setLeftWidth(0.0, Unit.PX, 100.0, Unit.PCT);
+
+ adopt(w);
+
+ // Update the layout.
+ layout.layout();
+ onResize();
+ }
+ }
+
+ @Override
+ protected void onLoad() {
+ layout.onAttach();
+ }
+
+ @Override
+ protected void onUnload() {
+ layout.onDetach();
+ }
+}
diff --git a/user/src/com/google/gwt/user/client/ui/SimplePanel.java b/user/src/com/google/gwt/user/client/ui/SimplePanel.java
index 651fe47..98a482e 100644
--- a/user/src/com/google/gwt/user/client/ui/SimplePanel.java
+++ b/user/src/com/google/gwt/user/client/ui/SimplePanel.java
@@ -26,7 +26,7 @@
*/
public class SimplePanel extends Panel implements HasOneWidget {
- private Widget widget;
+ Widget widget;
/**
* Creates an empty panel that uses a DIV for its contents.
diff --git a/user/test/com/google/gwt/user/UISuite.java b/user/test/com/google/gwt/user/UISuite.java
index 7f5a403..0befacf 100644
--- a/user/test/com/google/gwt/user/UISuite.java
+++ b/user/test/com/google/gwt/user/UISuite.java
@@ -86,6 +86,7 @@
import com.google.gwt.user.client.ui.RootPanelTest;
import com.google.gwt.user.client.ui.ScrollPanelTest;
import com.google.gwt.user.client.ui.SimpleCheckBoxTest;
+import com.google.gwt.user.client.ui.SimpleLayoutPanelTest;
import com.google.gwt.user.client.ui.SimplePanelTest;
import com.google.gwt.user.client.ui.SimpleRadioButtonTest;
import com.google.gwt.user.client.ui.SplitLayoutPanelTest;
@@ -199,6 +200,7 @@
suite.addTestSuite(SimpleCheckBoxTest.class);
suite.addTestSuite(SimpleRadioButtonTest.class);
suite.addTestSuite(SimplePanelTest.class);
+ suite.addTestSuite(SimpleLayoutPanelTest.class);
suite.addTestSuite(SplitLayoutPanelTest.class);
suite.addTestSuite(StackLayoutPanelTest.class);
suite.addTestSuite(StackPanelTest.class);
diff --git a/user/test/com/google/gwt/user/client/ui/SimpleLayoutPanelTest.java b/user/test/com/google/gwt/user/client/ui/SimpleLayoutPanelTest.java
new file mode 100644
index 0000000..273f3bc
--- /dev/null
+++ b/user/test/com/google/gwt/user/client/ui/SimpleLayoutPanelTest.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2011 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 SimpleLayoutPanel}.
+ */
+public class SimpleLayoutPanelTest extends
+ SimplePanelTestBase<SimpleLayoutPanel> {
+
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.user.User";
+ }
+
+ @Override
+ protected SimpleLayoutPanel createPanel() {
+ return new SimpleLayoutPanel();
+ }
+}