01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.user.client.Window;
19: import com.google.gwt.user.client.ui.AbstractImagePrototype;
20: import com.google.gwt.user.client.ui.ClickListener;
21: import com.google.gwt.user.client.ui.Composite;
22: import com.google.gwt.user.client.ui.HTML;
23: import com.google.gwt.user.client.ui.HorizontalPanel;
24: import com.google.gwt.user.client.ui.Image;
25: import com.google.gwt.user.client.ui.ImageBundle;
26: import com.google.gwt.user.client.ui.VerticalPanel;
27: import com.google.gwt.user.client.ui.Widget;
28:
29: /**
30: * The top panel, which contains the 'welcome' message and various links.
31: */
32: public class TopPanel extends Composite implements ClickListener {
33:
34: /**
35: * An image bundle for this widgets images.
36: */
37: public interface Images extends ImageBundle {
38: AbstractImagePrototype logo();
39: }
40:
41: private HTML signOutLink = new HTML(
42: "<a href='javascript:;'>Sign Out</a>");
43: private HTML aboutLink = new HTML(
44: "<a href='javascript:;'>About</a>");
45:
46: public TopPanel(Images images) {
47: HorizontalPanel outer = new HorizontalPanel();
48: VerticalPanel inner = new VerticalPanel();
49:
50: outer.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
51: inner.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
52:
53: HorizontalPanel links = new HorizontalPanel();
54: links.setSpacing(4);
55: links.add(signOutLink);
56: links.add(aboutLink);
57:
58: final Image logo = images.logo().createImage();
59: outer.add(logo);
60: outer.setCellHorizontalAlignment(logo,
61: HorizontalPanel.ALIGN_LEFT);
62:
63: outer.add(inner);
64: inner.add(new HTML("<b>Welcome back, foo@example.com</b>"));
65: inner.add(links);
66:
67: signOutLink.addClickListener(this );
68: aboutLink.addClickListener(this );
69:
70: initWidget(outer);
71: setStyleName("mail-TopPanel");
72: links.setStyleName("mail-TopPanelLinks");
73: }
74:
75: public void onClick(Widget sender) {
76: if (sender == signOutLink) {
77: Window
78: .alert("If this were implemented, you would be signed out now.");
79: } else if (sender == aboutLink) {
80: // When the 'About' item is selected, show the AboutDialog.
81: // Note that showing a dialog box does not block -- execution continues
82: // normally, and the dialog fires an event when it is closed.
83: AboutDialog dlg = new AboutDialog();
84: dlg.show();
85: dlg.center();
86: }
87: }
88: }
|