1 package zirc.gui ; 2 3 import java.io.* ; 4 import java.net.* ; 5 import java.util.* ; 6 7 import java.awt.* ; 8 import java.awt.event.* ; 9 import javax.swing.* ; 10 import javax.swing.border.* ; 11 import javax.swing.event.* ; 12 import javax.swing.text.html.* ; 13 14 import zirc.base.* ; 15 import zirc.gui.smiliesWindow.* ; 16 import zirc.msg.* ; 17 18 31 38 39 public class AbstractChatFrame extends JInternalFrame 40 { 41 protected IRCconnexion IRCchat ; 43 protected ToolBarItem toolBarIcone ; 44 private SmiliesCollection smilies ; 45 private String workingDir ; 46 47 protected final int MAXLINES = 300 ; 49 private final int MAXDOCLENGTH = 6000 ; protected ArrayList pos = new ArrayList() ; 51 private boolean display = true ; 53 protected BorderLayout borderLayout1 = new BorderLayout() ; 54 protected JPanel jPanel1 = new JPanel() ; 55 protected BorderLayout borderLayout2 = new BorderLayout() ; 56 protected JPanel jPanel2 = new JPanel() ; 57 protected JPanel jPanel3 = new JPanel() ; 58 protected JScrollPane jScrollPane1 = new JScrollPane() ; 59 protected BorderLayout borderLayout3 = new BorderLayout() ; 60 61 protected JTextPane jTextPane1 = new JTextPane() ; 63 protected HTMLDocument doc = new HTMLDocument() ; 64 protected HTMLEditorKit htk = new HTMLEditorKit() ; 65 private StringBuffer message ; 66 67 protected BorderLayout borderLayout4 = new BorderLayout() ; 68 protected JTextField jTextField1 = new JTextField() ; 69 Border border1 ; 70 private JButton jButton_Display = new JButton() ; 71 72 public AbstractChatFrame() 73 { 74 75 super() ; 76 try 77 { 78 jbInit() ; 79 } 80 catch (Exception e) 81 { 82 e.printStackTrace() ; 83 } 84 setResizable(true) ; 85 } 86 87 public AbstractChatFrame(IRCconnexion _IRCchat) 88 { 89 IRCchat = _IRCchat ; 90 smilies = IRCchat.getSmiliesCollection() ; 91 pos.ensureCapacity(MAXLINES) ; 92 setSize(IRCchat.getMainDesktopPane().getWidth() - 40, IRCchat.getMainDesktopPane().getHeight() - 40) ; 93 setResizable(true) ; 94 95 File f = new File("") ; 97 workingDir = f.getAbsolutePath() ; 98 99 try 100 { 101 jbInit() ; 102 } 103 catch (Exception e) 104 { 105 e.printStackTrace() ; 106 } 107 108 toolBarIcone = new ToolBarItem(IRCchat.GetMainFrm().getFrameToolBar(), this) ; 110 } 111 112 protected void jbInit() throws Exception 113 { 114 115 border1 = BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(SystemColor.control, 2), 116 BorderFactory.createEmptyBorder(2, 0, 0, 0)) ; 117 setClosable(true) ; 118 setIcon(false) ; 119 setIconifiable(true) ; 120 setLayer(1) ; 121 setMaximizable(true) ; 122 setResizable(true) ; 123 getContentPane().setBackground(SystemColor.controlText) ; 124 setFont(new java.awt.Font ("Arial Narrow", 0, 12)) ; 125 this.setBorder(BorderFactory.createLineBorder(Color.gray)) ; 126 setDoubleBuffered(true) ; 127 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter () 128 { 129 public void internalFrameClosed(InternalFrameEvent e) 130 { 131 this_internalFrameClosed(e) ; 132 } 133 134 public void internalFrameActivated(InternalFrameEvent e) 135 { 136 this_internalFrameActivated(e) ; 137 } 138 }) ; 139 jPanel1.setLayout(borderLayout2) ; 141 jPanel3.setLayout(borderLayout3) ; 142 jPanel2.setLayout(borderLayout4) ; 143 jTextPane1.setBorder(BorderFactory.createLineBorder(Color.gray)) ; 145 jTextPane1.setMaximumSize(new Dimension(2147483647, 2147483647)) ; 146 jTextPane1.setPreferredSize(new Dimension(6, 6)) ; 147 jTextPane1.setCaretColor(Color.black) ; 148 jTextPane1.setCaretPosition(0) ; 149 jTextPane1.setEditable(false) ; 150 jTextPane1.setText("") ; 151 jTextPane1.setContentType("text/plain") ; 152 153 jTextField1.addActionListener(new java.awt.event.ActionListener () 154 { 155 public void actionPerformed(ActionEvent e) 156 { 157 jTextField1_actionPerformed(e) ; 158 } 159 }) ; 160 jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane. 161 HORIZONTAL_SCROLLBAR_NEVER) ; 162 jScrollPane1.setBorder(null) ; 163 jScrollPane1.setPreferredSize(new Dimension(0, 0)) ; 164 165 jPanel1.setBackground(Color.white) ; 166 jPanel1.setBorder(null) ; 167 jTextField1.setBorder(BorderFactory.createLineBorder(Color.gray)) ; 168 jTextField1.setMinimumSize(new Dimension(4, 26)) ; 169 jTextField1.setPreferredSize(new Dimension(4, 26)) ; 170 jTextField1.addKeyListener(new java.awt.event.KeyAdapter () 171 { 172 public void keyTyped(KeyEvent e) 173 { 174 jTextField1_keyTyped(e) ; 175 } 176 }) ; 177 jPanel3.setBorder(null) ; 178 jButton_Display.setBorder(BorderFactory.createLineBorder(Color.gray)) ; 179 jButton_Display.setMinimumSize(new Dimension(40, 17)) ; 180 jButton_Display.setPreferredSize(new Dimension(40, 17)) ; 181 jButton_Display.setActionCommand("jButton_Run") ; 182 jButton_Display.setFocusPainted(false) ; 183 jButton_Display.setText("Stop") ; 184 jButton_Display.addActionListener(new java.awt.event.ActionListener () 185 { 186 public void actionPerformed(ActionEvent e) 187 { 188 jButton_Display_actionPerformed(e) ; 189 } 190 }) ; 191 getContentPane().add(jPanel1, BorderLayout.CENTER) ; 192 jPanel1.add(jPanel2, BorderLayout.SOUTH) ; 193 jPanel2.add(jTextField1, BorderLayout.CENTER) ; 194 jPanel2.add(jButton_Display, BorderLayout.EAST) ; 195 jPanel1.add(jPanel3, BorderLayout.CENTER) ; 196 jPanel3.add(jScrollPane1, BorderLayout.CENTER) ; 197 jScrollPane1.getViewport().add(jTextPane1, null) ; 198 199 StyleSheet ss = new StyleSheet() ; 201 ss.addRule("body {font-size:15pt;}") ; 202 ss.addRule("body {text-align:left;}") ; 203 ss.addRule("body {font-family:" + IRCconnexion.FIXEDSYS.getFontName() + ";}") ; 205 206 doc = new HTMLDocument(ss) ; 208 209 jTextPane1.setEditorKit(htk) ; 211 jTextPane1.setDocument(doc) ; 212 213 jTextField1.setFont(new Font(IRCconnexion.FIXEDSYS.getName(), 0, 15)) ; 215 216 jTextPane1.addHyperlinkListener(new HyperlinkListener() 218 { 219 224 public void hyperlinkUpdate(HyperlinkEvent e) 225 { 226 hyperlink_Activated(e) ; 227 } 228 229 }) ; 230 231 } 232 233 void this_internalFrameClosed(InternalFrameEvent e) 234 { 235 toolBarIcone.destroy() ; 237 } 238 239 public void displayTxt(StringBuffer _message, int initalLength, boolean _info) throws Exception 241 { 242 if (display) { 244 message = _message ; 245 246 pos.add(new Integer (initalLength)) ; 248 249 if (pos.size() > MAXLINES && doc.getLength() > MAXDOCLENGTH) 252 { 253 doc.remove(0, ((Integer )(pos.get(0))).intValue()) ; 254 pos.remove(0) ; 255 } 256 257 int index = 0 ; 263 int pos = 0 ; 264 URL url ; 265 String tag1 = "<a HREF=\"" ; 266 String tag2 = "\">" ; 267 String tag3 = "</a>" ; 268 269 while ((index = message.indexOf("http://", pos)) >= 0) 270 { 271 if (message.indexOf("<", index + 1) > 0) 272 { 273 url = new URL(message.substring(index, message.indexOf("<", index + 1))) ; message.delete(index, message.indexOf("<", index + 1)) ; 275 } 276 else 277 { 278 if (message.indexOf(" ", index + 1) > 0) 279 { 280 url = new URL(message.substring(index, message.indexOf(" ", index + 1))) ; message.delete(index, message.indexOf(" ", index + 1)) ; 282 } 283 else 284 { 285 message.insert(message.length(), " ") ; 286 url = new URL(message.substring(index, message.indexOf(" ", index + 1)).trim()) ; message.delete(index, message.indexOf(" ", index + 1)) ; 288 } 289 } 290 message.insert(index, " " + tag1 + url + tag2 + url + tag3) ; 291 pos += index + tag1.length() + url.toString().length() + tag2.length() + url.toString().length() + tag3.length() ; 292 } 293 294 pos = 0 ; 295 while ((index = message.indexOf("www.", pos)) >= 0) 296 { 297 if (!message.substring(index - 1, index).equals("/")) 299 { 300 if (message.indexOf("<", index + 2) > 0) 301 { 302 url = new URL("http://www." + message.substring(index + 4, message.indexOf("<", index + 2))) ; message.delete(index, message.indexOf("<", index + 2)) ; 304 } 305 else 306 { 307 if (message.indexOf(" ", index + 2) > 0) 308 { 309 url = new URL("http://www." + message.substring(index + 4, message.indexOf(" ", index + 2))) ; message.delete(index, message.indexOf(" ", index + 2)) ; 311 } 312 else 313 { 314 message.insert(message.length(), " ") ; 315 url = new URL("http://www." + message.substring(index + 4, message.indexOf(" ", index + 2))) ; message.delete(index, message.indexOf(" ", index + 2)) ; 317 } 318 } 319 message.insert(index, tag1 + url.toString() + tag2 + url.toString() + tag3) ; 320 pos += index + tag1.length() + url.toString().length() + tag2.length() + url.toString().length() + tag3.length() ; 321 } 322 else 323 { 324 pos += index + 1 ; 325 } 326 } 327 328 tag1 = "<img SRC=\"file:///" + workingDir + "/" ; 332 tag2 = "\"></img>" ; 333 for (int i = 0 ; i < smilies.getRowsCount() ; i++) 334 { 335 for (int j = 0 ; j < smilies.getColumnsCount() ; j++) 336 { String tmp = smilies.getValueAt(i, j, 1).toString() ; 338 while ((index = message.indexOf(tmp)) >= 0) 339 { 340 message.insert(index + tmp.length(), (tag1 + smilies.getValueAt(i, j, 0).toString() + tag2)) ; 341 for (int k = 0 ; k < tmp.length() ; k++) { 343 message.deleteCharAt(index) ; 344 } 345 } 346 } 347 } 348 349 htk.insertHTML(doc, doc.getLength(), message.toString(), 0, 0, null) ; 350 if (jTextPane1.getCaretPosition() > doc.getLength() - 300) 353 { 354 jTextPane1.setCaretPosition(doc.getLength() - 1) ; } 356 357 if (_info) 360 { 361 toolBarIcone.setRouge() ; 362 } 363 } 364 } 365 366 public JTextPane GetTextPane() 368 { 369 return this.jTextPane1 ; 370 } 371 372 public JTextField getTextBox() 374 { 375 return this.jTextField1 ; 376 } 377 378 void jTextField1_actionPerformed(ActionEvent e) 379 { 380 String txt = jTextField1.getText() ; 381 382 if (txt.length() > 0) 383 { 384 if (txt.charAt(0) == '/') 385 { 386 if (txt.length() > 3 && txt.substring(0, 4).equalsIgnoreCase("/msg")) 387 { 388 IRCchat.sendCommand("PRIV" + txt.substring(1)) ; 389 } 390 else 391 { 392 if (txt.length() > 3 && txt.substring(0, 5).equalsIgnoreCase("/ctcp")) 393 { 394 IRCchat.sendCommand("PRIVMSG " + txt.substring(5)) ; 395 } 396 else 397 { 398 IRCchat.sendCommand(txt.substring(1)) ; 399 } 400 } 401 402 } 403 else 404 { 405 MSGinfoPlus msg = new MSGinfoPlus(IRCchat, this, "Vous n'etes pas sur un channel") ; 407 msg.reagit() ; 408 msg.affiche() ; 409 } 410 jTextField1.setText("") ; 411 } 412 } 413 414 public void setTitle(String title) 416 { 417 super.setTitle(title) ; 418 toolBarIcone.setLibelle(this.getTitle()) ; 419 } 420 421 void this_internalFrameActivated(InternalFrameEvent e) 422 { 423 toolBarIcone.setPressed() ; 424 IRCchat.setChatFrameWithFocus(this) ; 425 } 426 427 void jTextField1_keyTyped(KeyEvent e) 428 { 429 436 437 if (e.isControlDown()) 438 { 439 if (e.getKeyChar() == '\u000B') { jTextField1.setText(jTextField1.getText() + '\u0003') ; 442 } 443 if (e.getKeyChar() == '\u0002') { 445 jTextField1.setText(jTextField1.getText() + '\u0002') ; 446 } 447 if (e.getKeyChar() == '\u0015') { 449 jTextField1.setText(jTextField1.getText() + '\u001F') ; 450 } 451 if (e.getKeyChar() == '\u0012') { 453 jTextField1.setText(jTextField1.getText() + '\u000F') ; 454 } 455 } 456 } 457 458 void hyperlink_Activated(HyperlinkEvent e) 460 { 461 if (e.getEventType() == e.getEventType().ACTIVATED) 462 { 463 BrowserLauncher browser = new BrowserLauncher() ; 464 browser.launchBrowserForInternet(e.getURL().toString()) ; 465 } 466 } 467 468 void jButton_Display_actionPerformed(ActionEvent e) 469 { 470 if (jButton_Display.getText().equalsIgnoreCase("stop")) 471 { 472 jButton_Display.setText("Go") ; 473 display = false ; 474 } 475 else 476 { 477 jButton_Display.setText("Stop") ; 478 display = true ; 479 } 480 } 481 } 482 | Popular Tags |