01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: * Darrell Meyer <darrell@mygwt.net> - derived implementation
11: *******************************************************************************/package net.mygwt.ui.client.widget.layout;
12:
13: import net.mygwt.ui.client.MyDOM;
14: import net.mygwt.ui.client.util.Rectangle;
15: import net.mygwt.ui.client.widget.Layout;
16: import net.mygwt.ui.client.widget.WidgetContainer;
17:
18: import com.google.gwt.user.client.Element;
19: import com.google.gwt.user.client.ui.Widget;
20:
21: /**
22: * This Layout stacks all the widgets one on top of the other and resizes all
23: * widgets to have the same size and location. The widget specified in topWidget
24: * is visible and all other widgets are not visible.
25: */
26: public class StackLayout extends Layout {
27:
28: Widget topWidget;
29:
30: /**
31: * Returns the top widget.
32: *
33: * @return the top widget
34: */
35: public Widget getTopWidget() {
36: return topWidget;
37: }
38:
39: /**
40: * Sets the widget that is displayed at the top of the stack.
41: *
42: * @param topWidget the top widget
43: */
44: public void setTopWidget(Widget topWidget) {
45: this .topWidget = topWidget;
46: }
47:
48: protected void onLayout(WidgetContainer container, Element target) {
49: super .onLayout(container, target);
50:
51: if (container.getWidgetCount() == 0) {
52: return;
53: }
54:
55: Rectangle rect = MyDOM.getBounds(target, true);
56:
57: int size = container.getWidgetCount();
58: for (int i = 0; i < size; i++) {
59: Widget child = (Widget) container.getWidget(i);
60: child.setVisible(topWidget == child);
61: if (topWidget == child) {
62: setSize(child, rect.width, rect.height);
63: }
64: }
65: }
66: }
|