KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > contact > list > HeaderItemToolTipFactory


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.gui.contact.list;
19
20 import org.columba.addressbook.facade.IContactItem;
21 import org.columba.addressbook.facade.IGroupItem;
22 import org.columba.addressbook.facade.IHeaderItem;
23
24 /**
25  * @author fdietz
26  *
27  */

28 public final class HeaderItemToolTipFactory {
29
30     public static String JavaDoc createToolTip(IHeaderItem item) {
31         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
32
33         buf.append("<html><body>&nbsp;Name: " + item.getName());
34         buf.append("</body></html>");
35
36         return buf.toString();
37     }
38
39     public static String JavaDoc createToolTip(IContactItem item) {
40
41         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
42
43         buf.append("<html><body>&nbsp;Name: " + item.getName());
44         if (item.getEmailAddress() != null) {
45             buf.append("<br>&nbsp;eMail: "
46                     + convert((String JavaDoc) item.getEmailAddress()));
47         }
48         // TODO
49
// if (item.getWebsite() != null) {
50
// buf.append("<br>&nbsp;Website: "
51
// + convert((String) item.getWebsite()));
52
// }
53
buf.append("</body></html>");
54
55         return buf.toString();
56     }
57
58     public static String JavaDoc createToolTip(IGroupItem item) {
59
60         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
61
62         buf.append("<html><body>&nbsp;Name: " + item.getName());
63         if (item.getDescription() != null) {
64             buf.append("<br>&nbsp;Description: " + item.getDescription());
65         }
66         buf.append("</body></html>");
67
68         return buf.toString();
69     }
70
71     private static String JavaDoc convert(String JavaDoc str) {
72         if (str == null) {
73             return "";
74         }
75
76         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
77         int pos = 0;
78         char ch;
79
80         while (pos < str.length()) {
81             ch = str.charAt(pos);
82
83             if (ch == '<') {
84                 result.append("&lt;");
85             } else if (ch == '>') {
86                 result.append("&gt;");
87             } else {
88                 result.append(ch);
89             }
90
91             pos++;
92         }
93
94         return result.toString();
95     }
96 }
Popular Tags