01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //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 createToolTip(BasicModelPartial item) {
31: StringBuffer buf = new StringBuffer();
32:
33: buf.append("<html><body> Name: " + item.getName());
34: buf.append("</body></html>");
35:
36: return buf.toString();
37: }
38:
39: public static String createToolTip(ContactModelPartial item) {
40:
41: StringBuffer buf = new StringBuffer();
42:
43: buf.append("<html><body> Name: " + item.getName());
44: if (item.getAddress() != null) {
45: buf.append("<br> eMail: "
46: + convert((String) item.getAddress()));
47: }
48: if (item.getWebsite() != null) {
49: buf.append("<br> Website: "
50: + convert((String) item.getWebsite()));
51: }
52: buf.append("</body></html>");
53:
54: return buf.toString();
55: }
56:
57: public static String createToolTip(GroupModelPartial item) {
58:
59: StringBuffer buf = new StringBuffer();
60:
61: buf.append("<html><body> Name: " + item.getName());
62: if (item.getDescription() != null) {
63: buf.append("<br> Description: "
64: + item.getDescription());
65: }
66: buf.append("</body></html>");
67:
68: return buf.toString();
69: }
70:
71: private static String convert(String str) {
72: if (str == null) {
73: return "";
74: }
75:
76: StringBuffer result = new StringBuffer();
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("<");
85: } else if (ch == '>') {
86: result.append(">");
87: } else {
88: result.append(ch);
89: }
90:
91: pos++;
92: }
93:
94: return result.toString();
95: }
96: }
|