KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > sample > mail > client > Mail


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.sample.mail.client;
17
18 import com.google.gwt.core.client.EntryPoint;
19 import com.google.gwt.core.client.GWT;
20 import com.google.gwt.user.client.Command;
21 import com.google.gwt.user.client.DeferredCommand;
22 import com.google.gwt.user.client.Window;
23 import com.google.gwt.user.client.WindowResizeListener;
24 import com.google.gwt.user.client.ui.DockPanel;
25 import com.google.gwt.user.client.ui.RootPanel;
26 import com.google.gwt.user.client.ui.VerticalPanel;
27
28 /**
29  * This application demonstrates how to construct a relatively complex user
30  * interface, similar to many common email readers. It has no back-end,
31  * populating its components with hard-coded data.
32  */

33 public class Mail implements EntryPoint, WindowResizeListener {
34
35   private static Mail singleton;
36
37   /**
38    * Instantiate an application-level image bundle. This object will provide
39    * programmatic access to all the images needed by widgets.
40    */

41   private static final Images images = (Images) GWT.create(Images.class);
42
43   /**
44    * An aggragate image bundle that pulls together all the images for this
45    * application into a single bundle.
46    */

47   public interface Images extends Shortcuts.Images, TopPanel.Images {
48   }
49
50   /**
51    * Gets the singleton Mail instance.
52    */

53   public static Mail get() {
54     return singleton;
55   }
56
57   private TopPanel topPanel = new TopPanel(images);
58   private VerticalPanel rightPanel = new VerticalPanel();
59   private MailList mailList;
60   private MailDetail mailDetail = new MailDetail();
61   private Shortcuts shortcuts = new Shortcuts(images);
62
63   /**
64    * Displays the specified item.
65    *
66    * @param item
67    */

68   public void displayItem(MailItem item) {
69     mailDetail.setItem(item);
70   }
71
72   /**
73    * This method constructs the application user interface by instantiating
74    * controls and hooking up event listeners.
75    */

76   public void onModuleLoad() {
77     singleton = this;
78
79     topPanel.setWidth("100%");
80
81     // MailList uses Mail.get() in its constructor, so initialize it after
82
// 'singleton'.
83
mailList = new MailList();
84     mailList.setWidth("100%");
85
86     // Create the right panel, containing the email list & details.
87
rightPanel.add(mailList);
88     rightPanel.add(mailDetail);
89     mailList.setWidth("100%");
90     mailDetail.setWidth("100%");
91
92     // Create a dock panel that will contain the menu bar at the top,
93
// the shortcuts to the left, and the mail list & details taking the rest.
94
DockPanel outer = new DockPanel();
95     outer.add(topPanel, DockPanel.NORTH);
96     outer.add(shortcuts, DockPanel.WEST);
97     outer.add(rightPanel, DockPanel.CENTER);
98     outer.setWidth("100%");
99
100     outer.setSpacing(4);
101     outer.setCellWidth(rightPanel, "100%");
102
103     // Hook the window resize event, so that we can adjust the UI.
104
Window.addWindowResizeListener(this);
105
106     // Get rid of scrollbars, and clear out the window's built-in margin,
107
// because we want to take advantage of the entire client area.
108
Window.enableScrolling(false);
109     Window.setMargin("0px");
110
111     // Finally, add the outer panel to the RootPanel, so that it will be
112
// displayed.
113
RootPanel.get().add(outer);
114
115     // Call the window resized handler to get the initial sizes setup. Doing
116
// this in a deferred command causes it to occur after all widgets' sizes
117
// have been computed by the browser.
118
DeferredCommand.addCommand(new Command() {
119       public void execute() {
120         onWindowResized(Window.getClientWidth(), Window.getClientHeight());
121       }
122     });
123
124     onWindowResized(Window.getClientWidth(), Window.getClientHeight());
125   }
126
127   public void onWindowResized(int width, int height) {
128     // Adjust the shortcut panel and detail area to take up the available room
129
// in the window.
130
int shortcutHeight = height - shortcuts.getAbsoluteTop() - 8;
131     if (shortcutHeight < 1) {
132       shortcutHeight = 1;
133     }
134     shortcuts.setHeight("" + shortcutHeight);
135
136     // Give the mail detail widget a chance to resize itself as well.
137
mailDetail.adjustSize(width, height);
138   }
139 }
140
Popular Tags