KickJava   Java API By Example, From Geeks To Geeks.

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


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.ui.AbstractImagePrototype;
19 import com.google.gwt.user.client.ui.Composite;
20 import com.google.gwt.user.client.ui.ImageBundle;
21 import com.google.gwt.user.client.ui.Tree;
22 import com.google.gwt.user.client.ui.TreeImages;
23 import com.google.gwt.user.client.ui.TreeItem;
24
25 /**
26  * A tree displaying a set of email folders.
27  */

28 public class Mailboxes extends Composite {
29
30   /**
31    * Specifies the images that will be bundled for this Composite and specify
32    * that tree's images should also be included in the same bundle.
33    */

34   public interface Images extends ImageBundle, TreeImages {
35     AbstractImagePrototype drafts();
36
37     AbstractImagePrototype home();
38
39     AbstractImagePrototype inbox();
40
41     AbstractImagePrototype sent();
42
43     AbstractImagePrototype templates();
44
45     AbstractImagePrototype trash();
46   }
47
48   private Tree tree;
49
50   /**
51    * Constructs a new mailboxes widget with a bundle of images.
52    *
53    * @param images a bundle that provides the images for this widget
54    */

55   public Mailboxes(Images images) {
56     tree = new Tree(images);
57     TreeItem root = new TreeItem(
58         imageItemHTML(images.home(), "foo@example.com"));
59     tree.addItem(root);
60
61     addImageItem(root, "Inbox", images.inbox());
62     addImageItem(root, "Drafts", images.drafts());
63     addImageItem(root, "Templates", images.templates());
64     addImageItem(root, "Sent", images.sent());
65     addImageItem(root, "Trash", images.trash());
66
67     root.setState(true);
68     initWidget(tree);
69   }
70
71   /**
72    * A helper method to simplify adding tree items that have attached images.
73    * {@link #addImageItem(TreeItem, String) code}
74    *
75    * @param root the tree item to which the new item will be added.
76    * @param title the text associated with this item.
77    */

78   private TreeItem addImageItem(TreeItem root, String JavaDoc title,
79       AbstractImagePrototype imageProto) {
80     TreeItem item = new TreeItem(imageItemHTML(imageProto, title));
81     root.addItem(item);
82     return item;
83   }
84
85   /**
86    * Generates HTML for a tree item with an attached icon.
87    *
88    * @param imageUrl the url of the icon image
89    * @param title the title of the item
90    * @return the resultant HTML
91    */

92   private String JavaDoc imageItemHTML(AbstractImagePrototype imageProto, String JavaDoc title) {
93     return "<span>" + imageProto.getHTML() + title + "</span>";
94   }
95 }
96
Popular Tags