Source Code Cross Referenced for ChatPane.java in  » Chat » LlamaChat » client » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Chat » LlamaChat » client 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*- ChatPane.java -------------------------------------------------+
002:         |                                                                 |
003:         |  Copyright (C) 2002-2003 Joseph Monti, LlamaChat                |
004:         |                     countjoe@users.sourceforge.net              |
005:         |                     http://www.42llamas.com/LlamaChat/          |
006:         |                                                                 |
007:         | This program is free software; you can redistribute it and/or   |
008:         | modify it under the terms of the GNU General Public License     |
009:         | as published by the Free Software Foundation; either version 2  |
010:         | of the License, or (at your option) any later version           |
011:         |                                                                 |
012:         | This program is distributed in the hope that it will be useful, |
013:         | but WITHOUT ANY WARRANTY; without even the implied warranty of  |
014:         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   |
015:         | GNU General Public License for more details.                    |
016:         |                                                                 |
017:         | A copy of the GNU General Public License may be found in the    |
018:         | installation directory named "GNUGPL.txt"                       |
019:         |                                                                 |
020:         +-----------------------------------------------------------------+
021:         */
022:
023:        package client;
024:
025:        import javax.swing.JTextPane;
026:        import javax.swing.text.html.HTMLEditorKit;
027:        import javax.swing.text.html.StyleSheet;
028:        import javax.swing.text.html.HTMLDocument;
029:        import javax.swing.text.html.HTML;
030:        import java.lang.String;
031:        import java.lang.StringBuffer;
032:        import java.nio.CharBuffer;
033:        import java.util.regex.Pattern;
034:        import java.awt.Color;
035:
036:        /* -------------------- JavaDoc Information ----------------------*/
037:        /**
038:         * This represents the chat pane where chat dialoge takes place
039:         * @author Joseph Monti <a href="mailto:countjoe@users.sourceforge.net">countjoe@users.sourceforge.net</a>
040:         * @version 0.8
041:         */
042:        public class ChatPane extends JTextPane {
043:
044:            String icoSad;
045:            String icoSmily;
046:            String icoTongue;
047:            String icoWinking;
048:            String icoOh;
049:            LlamaChat llamaChat;
050:
051:            ChatPane(LlamaChat lc) {
052:                super ();
053:
054:                llamaChat = lc;
055:
056:                setEditable(false);
057:                setContentType("text/html");
058:                HTMLEditorKit kit = new HTMLEditorKit();
059:                StyleSheet css = new StyleSheet();
060:                css.addRule("BODY{ margin : 0;}");
061:                css.addRule("P{ margin : 0;}");
062:                css.addRule("A{ color:#0000FF; text-decoration:underline;}");
063:                kit.setStyleSheet(css);
064:                setEditorKit(kit);
065:                setBackground(new Color(249, 249, 250));
066:
067:                icoSad = "<img src=\"" + lc.locationURL
068:                        + "images/sad.gif\" height=\"14\" width=\"14\">";
069:                icoSmily = "<img src=\"" + lc.locationURL
070:                        + "images/smiley.gif\" height=\"14\" width=\"14\">";
071:                icoOh = "<img src=\"" + lc.locationURL
072:                        + "images/oh.gif\" height=\"14\" width=\"14\">";
073:                icoTongue = "<img src=\"" + lc.locationURL
074:                        + "images/tongue.gif\" height=\"14\" width=\"14\">";
075:                icoWinking = "<img src=\"" + lc.locationURL
076:                        + "images/winking.gif\" height=\"14\" width=\"14\">";
077:
078:                addHyperlinkListener(lc.myHyperlinkListener);
079:            }
080:
081:            /**
082:             * Sends a text to the chat window. Parses the message to pick
083:             * out emoticons and links.
084:             * @param un	the name of the user sending the message
085:             * @param message	the message to be sent
086:             * @param whisper	indicates the message was a wisper and makes the 
087:             *					message italic
088:             */
089:            public void sendText(String un, String message) {
090:                sendText(un, message, false);
091:            }
092:
093:            /**
094:             * Sends a text to the chat window. Parses the message to pick
095:             * out emoticons and links.
096:             * @param un	the name of the user sending the message
097:             * @param message	the message to be sent
098:             */
099:            public void sendText(String un, String message, boolean whisper) {
100:                StringBuffer buff = new StringBuffer();
101:                HTMLDocument doc = (HTMLDocument) getDocument();
102:                HTMLEditorKit kit = (HTMLEditorKit) getEditorKit();
103:
104:                if (un == null || llamaChat.username == null) {
105:                    return;
106:                }
107:
108:                if (!"server".equals(un)) {
109:                    message = message.replaceAll("<", "&lt;");
110:                    message = message.replaceAll(">", "&gt;");
111:                }
112:                message = message.replaceAll("\n", "<br>");
113:
114:                if (llamaChat.username.equals(un)) {
115:                    buff.append("<font color=#009900><b>");
116:                } else if (un.equals("server")) {
117:                    buff.append("<font color=#990000><b>");
118:                } else {
119:                    buff.append("<font color=#000099><b>");
120:                }
121:                buff.append(un);
122:                buff.append("</b></font>");
123:
124:                buff.append("&nbsp;&nbsp;:&nbsp;");
125:                if (whisper) {
126:                    buff.append("<i>");
127:                }
128:                char[] tmp = message.toCharArray();
129:                int start, end;
130:                for (start = 0, end = 0; end < (tmp.length - 1); ++end) {
131:                    if (tmp[end] == ';') {
132:                        if (tmp[end + 1] == ')') {
133:                            if (end - start > 0) {
134:                                buff.append(tmp, start, end - start);
135:                            }
136:                            buff.append(icoWinking);
137:                            start = end += 2;
138:                            end--;
139:                        }
140:                    } else if (tmp[end] == ':') {
141:                        switch (tmp[end + 1]) {
142:                        case ')':
143:                            if (end - start > 0) {
144:                                buff.append(tmp, start, end - start);
145:                            }
146:                            buff.append(icoSmily);
147:                            start = end += 2;
148:                            end--;
149:                            break;
150:                        case '(':
151:                            if (end - start > 0) {
152:                                buff.append(tmp, start, end - start);
153:                            }
154:                            buff.append(icoSad);
155:                            start = end += 2;
156:                            end--;
157:                            break;
158:                        case 'P':
159:                            if (end - start > 0) {
160:                                buff.append(tmp, start, end - start);
161:                            }
162:                            buff.append(icoTongue);
163:                            start = end += 2;
164:                            end--;
165:                            break;
166:                        case 'o':
167:                            if (end - start > 0) {
168:                                buff.append(tmp, start, end - start);
169:                            }
170:                            buff.append(icoOh);
171:                            start = end += 2;
172:                            end--;
173:                            break;
174:                        }
175:                    } else if (end + 10 < tmp.length && tmp[end] == 'h'
176:                            && tmp[end + 1] == 't' && tmp[end + 2] == 't'
177:                            && tmp[end + 3] == 'p' && tmp[end + 4] == ':'
178:                            && tmp[end + 5] == '/' && tmp[end + 6] == '/') {
179:                        if (end - start > 0) {
180:                            buff.append(tmp, start, end - start);
181:                        }
182:                        int index;
183:                        for (index = 7; index < tmp.length
184:                                && Pattern.matches("[\\w.:/\\?\\=&%_\\-~]",
185:                                        CharBuffer.wrap(tmp, end + index, 1)); index++) {
186:                        }
187:
188:                        buff.append("<a href=\"");
189:                        buff.append(tmp, end, index);
190:                        buff.append("\">");
191:                        buff.append(tmp, end, index);
192:                        buff.append("</a>");
193:                        start = end += index;
194:                        end--;
195:                    }
196:                }
197:                if (start < tmp.length) {
198:                    buff.append(tmp, start, tmp.length - start);
199:                }
200:                if (whisper) {
201:                    buff.append("</i>");
202:                }
203:                if (buff.length() > 0) {
204:                    try {
205:                        buff.append("<br>");
206:                        kit.insertHTML(doc, doc.getLength(), buff.toString(),
207:                                0, 0, HTML.Tag.FONT);
208:                        setCaretPosition(doc.getLength());
209:                    } catch (Throwable t) {
210:                        t.printStackTrace();
211:                    }
212:                }
213:                if (message.startsWith("afk") || message.startsWith("brb")) {
214:                    llamaChat.afks.add(un);
215:                    llamaChat.updateList();
216:                } else {
217:                    if (llamaChat.afks.contains(un)) {
218:                        llamaChat.afks.remove(un);
219:                        llamaChat.updateList();
220:                    }
221:                }
222:            }
223:
224:            /**
225:             * signifies an error and reports it to the user
226:             * @param s	the error message
227:             */
228:            public void error(String s) {
229:                HTMLDocument doc = (HTMLDocument) getDocument();
230:                HTMLEditorKit kit = (HTMLEditorKit) getEditorKit();
231:                try {
232:                    kit.insertHTML(doc, doc.getLength(),
233:                            "<font color=#CC0000><b>ERROR  : " + s
234:                                    + "<b><br></font>", 0, 0, HTML.Tag.FONT);
235:                    setCaretPosition(doc.getLength());
236:                } catch (Throwable t) {
237:                }
238:            }
239:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.