1 package zirc.msg ; 2 3 import java.util.* ; 4 5 import zirc.base.* ; 6 import zirc.gui.* ; 7 8 16 17 21 40 41 public abstract class AbstractMessage 42 { 43 44 49 protected AbstractChatFrame frm ; 50 51 56 public static String [] vectColors = 57 { 58 "#FFFFFF", "#000000", "#00007F", "#009300", "#FF0000", "#7F0000", "#7F007F", "#FFA500", "#FFFF00", "#00FF00", "#007F7F", "#00FFFF", "#0000FF", "#FF00FF", "#7F7F7F", "#C0C0C0"} ; 75 public static char mircColorCode = '\u0003' ; 77 public static char mircBoldCode = '\u0002' ; 78 public static char mircUnderlineCode = '\u001F' ; 79 public static char mircEraseCode = '\u000F' ; 80 81 protected IRCconnexion ircChan ; 83 84 protected String Message ; 86 87 90 public AbstractMessage() 91 { 92 93 } 94 95 103 public AbstractMessage(IRCconnexion _ircChan, AbstractChatFrame _frm, String _message) 104 { 105 this.ircChan = _ircChan ; 106 this.frm = _frm ; 107 this.Message = _message ; 108 } 109 110 public AbstractMessage(IRCconnexion _ircChan, String _message) 111 { 112 this.ircChan = _ircChan ; 113 this.frm = _ircChan.GetStatusFrm() ; 114 this.Message = _message ; 115 } 116 117 127 public void affiche() 128 { 129 if (frm != null) 130 { 131 String txtAffiche = parseMessagePourAffichage(Message) ; 133 134 int longApprox = txtAffiche.length() + 1 ; 136 137 StringBuffer htmlMsg = toHtml(txtAffiche) ; 139 140 if (hasSeparator()) 142 { 143 htmlMsg.insert(0, "-<BR>") ; 144 longApprox++ ; 145 } 146 147 try 149 { 150 frm.displayTxt(htmlMsg, longApprox, informeUser()) ; 151 } 152 catch (Exception e) 153 { 154 } 155 } 156 } 157 158 164 protected void envoiCommande(String _com) 165 { 166 ircChan.sendCommand(_com) ; 167 } 168 169 174 public void reagit() 175 { 176 177 } 178 179 188 189 protected static void StringColors(StringBuffer _message) 190 { 191 192 195 int ind ; int backGrnd = 0 ; int foreGrnd = 1 ; 199 char digit ; boolean backDefini = false ; 202 StringBuffer msg = _message ; 204 String rech = mircColorCode + "" ; 206 String htmlCode1 ; String htmlCode2 ; 209 int base ; 211 ind = msg.indexOf(rech) ; 215 while (ind > -1) 216 { 217 base = 0 ; 219 foreGrnd = 1 ; 221 try 222 { 223 base = 1 ; 224 digit = msg.charAt(ind + base) ; 225 if (Character.isDigit(digit)) 226 { 227 base++ ; 228 foreGrnd = Character.getNumericValue(digit) ; 229 230 digit = msg.charAt(ind + base) ; 232 if (Character.isDigit(digit)) 233 { 234 base++ ; 235 foreGrnd = foreGrnd * 10 + Character.getNumericValue(digit) ; 236 } 237 238 digit = msg.charAt(ind + base) ; 240 if (digit == ',') 241 { 242 backDefini = true ; 244 base++ ; 245 digit = msg.charAt(ind + base) ; 246 if (Character.isDigit(digit)) 247 { 248 base++ ; 249 backGrnd = Character.getNumericValue(digit) ; 250 251 digit = msg.charAt(ind + base) ; 253 if (Character.isDigit(digit)) 254 { 255 base++ ; 256 backGrnd = backGrnd * 10 + Character.getNumericValue(digit) ; 257 } 258 } 259 } 260 } 261 } 262 catch (StringIndexOutOfBoundsException e) 263 { 264 } 266 267 foreGrnd %= 16 ; 270 backGrnd %= 16 ; 271 272 htmlCode1 = "<font color='" + vectColors[foreGrnd] + "' " ; 274 275 if (backDefini = true) 277 { 278 htmlCode2 = " style='background:" + vectColors[backGrnd] + ";'>" ; 282 } 283 else 284 { 285 htmlCode2 = ">" ; 287 } 288 289 msg.replace(ind, ind + base, htmlCode1 + htmlCode2) ; 290 291 msg.append("</font>") ; 293 294 ind = msg.indexOf(rech, ind - 1) ; 296 297 } 298 } 299 300 313 protected static void StringReplacer(char _token, String _baliseO, String _baliseF, 314 StringBuffer _message) 315 { 316 int num = 0 ; 318 int ind = 0 ; 320 String rech = _token + "" ; 321 322 boolean complete = true ; 324 325 ind = _message.indexOf(rech) ; 326 while (ind > -1) 327 { 328 329 if (num % 2 == 0) 331 { 332 _message.replace(ind, ind + 1, _baliseO) ; 334 complete = false ; 335 } 336 else 337 { 338 _message.replace(ind, ind + 1, _baliseO) ; 340 complete = true ; 341 } 342 343 ind = _message.indexOf(rech) ; 344 num++ ; 345 } 346 347 if (!complete) 349 { 350 _message.append(_baliseF) ; 351 } 352 353 } 354 355 364 protected StringBuffer toHtml(String _txtAffich) 365 { 366 367 StringBuffer HtmlMsg = new StringBuffer () ; 368 String tmp ; 369 StringBuffer temp ; 370 371 StringTokenizer stk = new StringTokenizer(_txtAffich, mircEraseCode + "") ; 373 374 while (stk.hasMoreTokens()) 376 { 377 378 tmp = stk.nextToken() ; 379 380 if (tmp.indexOf(" ") > 0) 383 { 384 temp = new StringBuffer (tmp.replaceAll(" ", " ")) ; 385 } 386 else 387 { 388 temp = new StringBuffer (tmp) ; 389 } 390 391 StringReplacer('\u0002', "<b>", "</b>", temp) ; StringReplacer('\u001F', "<u>", "</u>", temp) ; StringReplacer('\u0016', 394 "<font style='background:#000000;color:white'>", "</font>", 395 temp) ; 396 397 StringColors(temp) ; 399 400 HtmlMsg.append(temp) ; 401 } 402 403 setColor(HtmlMsg) ; 404 405 return HtmlMsg ; 406 } 407 408 416 protected String parseMessagePourAffichage(String _txtAffiche) 417 { 418 return _txtAffiche ; 419 } 420 421 protected void setColor(StringBuffer _htmlMsg) 422 { 423 424 } 425 426 protected boolean hasSeparator() 427 { 428 if (frm == ircChan.GetStatusFrm()) 429 { 430 return true ; 431 } 432 433 return false ; 434 } 435 436 protected boolean informeUser() 437 { 438 return true ; 439 } 440 441 } 442 | Popular Tags |