1 19 package org.lucane.applications.reunion; 20 21 import java.io.Serializable ; 22 import java.text.DateFormat ; 23 import java.util.Date ; 24 25 30 public class ReunionMessage implements Serializable { 31 32 private int type; 33 34 private Object data; 35 36 39 public static final int TYPE_TEXT = 1; 40 41 45 public static final int TYPE_JOIN = 2; 46 47 51 public static final int TYPE_END = 3; 52 53 57 public static final int TYPE_LEAVE = 4; 58 59 60 63 public static final int TYPE_USERLIST = 5; 64 65 72 protected ReunionMessage(int type, Object data) { 73 this.type = type; 74 this.data = data; 75 } 76 77 86 public static ReunionMessage createTextInstance(String user, String text) { 87 String [] dt = { user, text }; 88 return new ReunionMessage(TYPE_TEXT, dt); 89 } 90 91 98 public static ReunionMessage createJoinInstance(String user) { 99 return new ReunionMessage(TYPE_JOIN, user); 100 } 101 102 109 public static ReunionMessage createLeaveInstance(String user) { 110 return new ReunionMessage(TYPE_LEAVE, user); 111 } 112 113 118 public static ReunionMessage createEndInstance() { 119 return new ReunionMessage(TYPE_END, null); 120 } 121 122 127 public static ReunionMessage createUserListInstance(ReunionUsersProperties props) { 128 return new ReunionMessage(TYPE_USERLIST, props); 129 } 130 131 136 public Object getData() { 137 return data; 138 } 139 140 145 public void setData(Object object) { 146 data = object; 147 } 148 149 154 public int getType() { 155 return type; 156 } 157 158 163 public void setType(int i) { 164 type = i; 165 } 166 167 172 public String toString(Reunion reunion) { 173 if (type == TYPE_TEXT) 174 return createHTMLTextMessage( 175 reunion, 176 ((String []) data)[0], 177 ((String []) data)[1]); 178 else if (type == TYPE_END) 179 return createHTMLInfoMessage(reunion, reunion.tr("endMsg")); 180 else if (type == TYPE_JOIN) 181 return createHTMLInfoMessage( 182 reunion, 183 reunion.tr("joinMsg") + (String ) data); 184 else if (type == TYPE_LEAVE) 185 return createHTMLInfoMessage( 186 reunion, 187 reunion.tr("leaveMsg") + (String ) data); 188 return null; 189 } 190 191 198 public static String createHTMLTextMessage( 199 Reunion reunion, 200 String user, 201 String message) { 202 String res = null; 203 ReunionUserProperties rup = reunion.getUsersProperties().getUserProperties(user); 204 res = 205 "<DIV " 206 + "STYLE=\"padding:0px;margin-bottom:2px;" 207 + "border-width:1px;border-style:solid;border-color:"+rup.getFgColor()+";" 208 + "background-color:"+rup.getBgColor()+";width:100%;\">" 209 + "<font size=2>" 210 + DateFormat.getTimeInstance(DateFormat.SHORT).format(new Date ()) 211 + "</font> <b><font size=4 color=\""+rup.getFgColor()+"\">" 212 + user 213 + "</font><font size=4> > </font></b>" 214 + "<font size=4>" 215 + message 216 + "</font></DIV>"; 217 return res; 218 } 219 220 226 public static String createHTMLInfoMessage(Reunion reunion, String message) { 227 String res; 228 res = "<DIV><FONT SIZE=4 COLOR=#888888>" + message + "</FONT></DIV>"; 229 return res; 230 } 231 } 232 | Popular Tags |