Revision: 9548
Author: gwt.mirror...@gmail.com
Date: Fri Jan 14 09:22:31 2011
Log: 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: rj...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=9548
Added:
/trunk/user/src/com/google/gwt/user/client/ui/SimpleLayoutPanel.java
/trunk/user/test/com/google/gwt/user/client/ui/SimpleLayoutPanelTest.java
Modified:
/trunk/user/src/com/google/gwt/user/client/ui/SimplePanel.java
/trunk/user/test/com/google/gwt/user/UISuite.java
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/user/client/ui/SimpleLayoutPanel.java
Fri Jan 14 09:22:31 2011
@@ -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();
+ }
+}
=======================================
--- /dev/null
+++
/trunk/user/test/com/google/gwt/user/client/ui/SimpleLayoutPanelTest.java
Fri Jan 14 09:22:31 2011
@@ -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();
+ }
+}
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/SimplePanel.java Mon Sep
13 10:28:49 2010
+++ /trunk/user/src/com/google/gwt/user/client/ui/SimplePanel.java Fri Jan
14 05:54:41 2011
@@ -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.
=======================================
--- /trunk/user/test/com/google/gwt/user/UISuite.java Tue Nov 23 11:35:12
2010
+++ /trunk/user/test/com/google/gwt/user/UISuite.java Fri Jan 14 05:54:41
2011
@@ -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);
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors