01: /*
02: * MyGWT Widget Library
03: * Copyright(c) 2007, MyGWT.
04: * licensing@mygwt.net
05: *
06: * http://mygwt.net/license
07: */
08: package net.mygwt.ui.client.widget;
09:
10: import net.mygwt.ui.client.MyGWT;
11: import net.mygwt.ui.client.event.BaseEvent;
12: import net.mygwt.ui.client.event.Listener;
13: import net.mygwt.ui.client.util.DelayedTask;
14:
15: import com.google.gwt.user.client.Window;
16: import com.google.gwt.user.client.WindowResizeListener;
17: import com.google.gwt.user.client.ui.RootPanel;
18:
19: /**
20: * A container that fills the viewport and monitors window resizing. The
21: * container is automatically added to the root panel.
22: */
23: public class Viewport extends WidgetContainer {
24:
25: private DelayedTask task = new DelayedTask(new Listener() {
26: public void handleEvent(BaseEvent be) {
27: setBounds(0, 0, Window.getClientWidth(), Window
28: .getClientHeight());
29: }
30: });
31:
32: private boolean initialized;
33:
34: /**
35: * Creates a new viewport.
36: */
37: public Viewport() {
38: Window.addWindowResizeListener(new WindowResizeListener() {
39: public void onWindowResized(int width, int height) {
40: task.delay(400);
41: }
42: });
43:
44: Window.enableScrolling(false);
45: RootPanel.get().add(this );
46: }
47:
48: protected void onLayout() {
49: if (!initialized) {
50: initialized = true;
51: setBounds(0, 0, Window.getClientWidth(), Window
52: .getClientHeight());
53: }
54: lastSize = null;
55: super .onLayout();
56: }
57:
58: /**
59: * Hides the loading panel.
60: *
61: * @param id the loading panel id
62: */
63: public void hideLoadingPanel(String id) {
64: MyGWT.hideLoadingPanel(id);
65: }
66:
67: protected void onRender() {
68: super .onRender();
69: setStyleAttribute("position", "absolute");
70: }
71:
72: }
|