1 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 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: " + item.getDescription()); 64 } 65 buf.append("</body></html>"); 66 67 return buf.toString(); 68 } 69 70 private static String convert(String str) { 71 if (str == null) { 72 return ""; 73 } 74 75 StringBuffer result = new StringBuffer (); 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("<"); 84 } else if (ch == '>') { 85 result.append(">"); 86 } else { 87 result.append(ch); 88 } 89 90 pos++; 91 } 92 93 return result.toString(); 94 } 95 } | Popular Tags |