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.ui.Composite;
19: import com.google.gwt.user.client.ui.DockPanel;
20: import com.google.gwt.user.client.ui.HTML;
21: import com.google.gwt.user.client.ui.ScrollPanel;
22: import com.google.gwt.user.client.ui.VerticalPanel;
23:
24: /**
25: * A composite for displaying the details of an email message.
26: */
27: public class MailDetail extends Composite {
28:
29: private VerticalPanel panel = new VerticalPanel();
30: private VerticalPanel headerPanel = new VerticalPanel();
31: private HTML subject = new HTML();
32: private HTML sender = new HTML();
33: private HTML recipient = new HTML();
34: private HTML body = new HTML();
35: private ScrollPanel scroller = new ScrollPanel(body);
36:
37: public MailDetail() {
38: body.setWordWrap(true);
39:
40: headerPanel.add(subject);
41: headerPanel.add(sender);
42: headerPanel.add(recipient);
43: headerPanel.setWidth("100%");
44:
45: DockPanel innerPanel = new DockPanel();
46: innerPanel.add(headerPanel, DockPanel.NORTH);
47: innerPanel.add(scroller, DockPanel.CENTER);
48:
49: innerPanel.setCellHeight(scroller, "100%");
50: panel.add(innerPanel);
51: innerPanel.setSize("100%", "100%");
52: scroller.setSize("100%", "100%");
53: initWidget(panel);
54:
55: setStyleName("mail-Detail");
56: headerPanel.setStyleName("mail-DetailHeader");
57: innerPanel.setStyleName("mail-DetailInner");
58: subject.setStyleName("mail-DetailSubject");
59: sender.setStyleName("mail-DetailSender");
60: recipient.setStyleName("mail-DetailRecipient");
61: body.setStyleName("mail-DetailBody");
62: }
63:
64: /**
65: * Adjusts the widget's size such that it fits within the window's client
66: * area.
67: */
68: public void adjustSize(int windowWidth, int windowHeight) {
69: int scrollWidth = windowWidth - scroller.getAbsoluteLeft() - 9;
70: if (scrollWidth < 1) {
71: scrollWidth = 1;
72: }
73:
74: int scrollHeight = windowHeight - scroller.getAbsoluteTop() - 9;
75: if (scrollHeight < 1) {
76: scrollHeight = 1;
77: }
78:
79: scroller.setSize("" + scrollWidth, "" + scrollHeight);
80: }
81:
82: public void setItem(MailItem item) {
83: subject.setHTML(item.subject);
84: sender.setHTML("<b>From:</b> " + item.sender);
85: recipient.setHTML("<b>To:</b> foo@example.com");
86: body.setHTML(item.body);
87: }
88: }
|