KickJava   Java API By Example, From Geeks To Geeks.

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


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.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("<a HREF='javascript:;'>Sign Out</a>");
42   private HTML aboutLink = new HTML("<a HREF='javascript:;'>About</a>");
43
44   public TopPanel(Images images) {
45     HorizontalPanel outer = new HorizontalPanel();
46     VerticalPanel inner = new VerticalPanel();
47
48     outer.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
49     inner.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
50
51     HorizontalPanel links = new HorizontalPanel();
52     links.setSpacing(4);
53     links.add(signOutLink);
54     links.add(aboutLink);
55
56     final Image logo = images.logo().createImage();
57     outer.add(logo);
58     outer.setCellHorizontalAlignment(logo, HorizontalPanel.ALIGN_LEFT);
59
60     outer.add(inner);
61     inner.add(new HTML("<b>Welcome back, foo@example.com</b>"));
62     inner.add(links);
63
64     signOutLink.addClickListener(this);
65     aboutLink.addClickListener(this);
66
67     initWidget(outer);
68     setStyleName("mail-TopPanel");
69     links.setStyleName("mail-TopPanelLinks");
70   }
71
72   public void onClick(Widget sender) {
73     if (sender == signOutLink) {
74       Window.alert("If this were implemented, you would be signed out now.");
75     } else if (sender == aboutLink) {
76       // When the 'About' item is selected, show the AboutDialog.
77
// Note that showing a dialog box does not block -- execution continues
78
// normally, and the dialog fires an event when it is closed.
79
AboutDialog dlg = new AboutDialog();
80       dlg.show();
81       dlg.center();
82     }
83   }
84 }
85
Popular Tags