KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > gui > util > ToolTipFactory


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.addressbook.gui.util;
19
20 import org.columba.addressbook.model.ContactModelPartial;
21 import org.columba.addressbook.model.GroupModelPartial;
22 import org.columba.addressbook.model.BasicModelPartial;
23
24 /**
25  * @author fdietz
26  *
27  */

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