Source Code Cross Referenced for StyledLogPane.java in  » Database-Client » executequery » org » underworldlabs » swing » 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 » Database Client » executequery » org.underworldlabs.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * StyledLogPane.java
003:         *
004:         * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         *
020:         */
021:
022:        package org.underworldlabs.swing;
023:
024:        import java.awt.Color;
025:        import javax.swing.JTextPane;
026:        import javax.swing.text.AttributeSet;
027:        import javax.swing.text.BadLocationException;
028:        import javax.swing.text.DefaultStyledDocument;
029:        import javax.swing.text.MutableAttributeSet;
030:        import javax.swing.text.SimpleAttributeSet;
031:        import javax.swing.text.StyleConstants;
032:
033:        /* ----------------------------------------------------------
034:         * CVS NOTE: Changes to the CVS repository prior to the 
035:         *           release of version 3.0.0beta1 has meant a 
036:         *           resetting of CVS revision numbers.
037:         * ----------------------------------------------------------
038:         */
039:
040:        /**
041:         * Appending text pane with styled (coloured) text for process logging.
042:         *
043:         * @author   Takis Diakoumis
044:         * @version  $Revision: 1.4 $
045:         * @date     $Date: 2006/05/14 06:56:07 $
046:         */
047:        public class StyledLogPane extends JTextPane {
048:
049:            /** Indicates an action message (blue) */
050:            public static final int ACTION_MESSAGE = 0;
051:
052:            /** Indicates an error message (red) */
053:            public static final int ERROR_MESSAGE = 1;
054:
055:            /** Indicates a normal output message (black) */
056:            public static final int PLAIN_MESSAGE = 2;
057:
058:            /** Indicates a normal output message (dark orange) */
059:            public static final int WARNING_MESSAGE = 3;
060:
061:            /** Indicates an action message (blue) in fixed-width font */
062:            public static final int ACTION_MESSAGE_PREFORMAT = 4;
063:
064:            /** Indicates an error message (red) in fixed-width font */
065:            public static final int ERROR_MESSAGE_PREFORMAT = 5;
066:
067:            /** Indicates a normal output message (black) in fixed-width font */
068:            public static final int PLAIN_MESSAGE_PREFORMAT = 6;
069:
070:            /** Indicates a normal output message (dark orange) in fixed-width font */
071:            public static final int WARNING_MESSAGE_PREFORMAT = 7;
072:
073:            /** the styled document for this text pane */
074:            private StyledOutputPaneDocument document;
075:
076:            public StyledLogPane() {
077:                document = new StyledOutputPaneDocument();
078:                setDocument(document);
079:            }
080:
081:            public void append(String text) {
082:                appendPlain(text);
083:            }
084:
085:            public void append(int type, String text) {
086:                switch (type) {
087:                case ACTION_MESSAGE:
088:                    appendAction(text);
089:                    break;
090:                case ERROR_MESSAGE:
091:                    appendError(text);
092:                    break;
093:                case WARNING_MESSAGE:
094:                    appendWarning(text);
095:                    break;
096:                case PLAIN_MESSAGE:
097:                    appendPlain(text);
098:                    break;
099:                case ACTION_MESSAGE_PREFORMAT:
100:                    appendActionFixedWidth(text);
101:                    break;
102:                case ERROR_MESSAGE_PREFORMAT:
103:                    appendErrorFixedWidth(text);
104:                    break;
105:                case WARNING_MESSAGE_PREFORMAT:
106:                    appendWarningFixedWidth(text);
107:                    break;
108:                case PLAIN_MESSAGE_PREFORMAT:
109:                    appendPlainFixedWidth(text);
110:                    break;
111:                default:
112:                    appendPlain(text);
113:                    break;
114:                }
115:            }
116:
117:            public void appendError(String text) {
118:                document.appendError(text);
119:            }
120:
121:            public void appendWarning(String text) {
122:                document.appendWarning(text);
123:            }
124:
125:            public void appendPlain(String text) {
126:                document.appendPlain(text);
127:            }
128:
129:            public void appendAction(String text) {
130:                document.appendAction(text);
131:            }
132:
133:            public void appendErrorFixedWidth(String text) {
134:                document.appendErrorFixedWidth(text);
135:            }
136:
137:            public void appendWarningFixedWidth(String text) {
138:                document.appendWarningFixedWidth(text);
139:            }
140:
141:            public void appendPlainFixedWidth(String text) {
142:                document.appendPlainFixedWidth(text);
143:            }
144:
145:            public void appendActionFixedWidth(String text) {
146:                document.appendActionFixedWidth(text);
147:            }
148:
149:            public boolean isEditable() {
150:                return false;
151:            }
152:
153:            class StyledOutputPaneDocument extends DefaultStyledDocument {
154:
155:                private final char NEW_LINE_CHAR = '\n';
156:
157:                /** temp text buffer */
158:                private StringBuffer textBuffer;
159:
160:                // normal font
161:                protected MutableAttributeSet plain;
162:                protected MutableAttributeSet error;
163:                protected MutableAttributeSet warning;
164:                protected MutableAttributeSet action;
165:
166:                // fixed width font
167:                protected MutableAttributeSet plainFixedWidth;
168:                protected MutableAttributeSet errorFixedWidth;
169:                protected MutableAttributeSet warningFixedWidth;
170:                protected MutableAttributeSet actionFixedWidth;
171:
172:                public StyledOutputPaneDocument() {
173:                    initStyles();
174:                    textBuffer = new StringBuffer();
175:                }
176:
177:                protected void initStyles() {
178:                    // normal font styles
179:                    plain = new SimpleAttributeSet();
180:                    StyleConstants.setForeground(plain, Color.BLACK);
181:
182:                    error = new SimpleAttributeSet();
183:                    StyleConstants.setForeground(error, Color.RED.darker());
184:
185:                    warning = new SimpleAttributeSet();
186:                    StyleConstants.setForeground(warning,
187:                            new Color(222, 136, 8));
188:
189:                    action = new SimpleAttributeSet();
190:                    StyleConstants.setForeground(action, Color.BLUE.darker());
191:
192:                    // fixed width font styles
193:                    String fixedWidthFontName = "monospaced";
194:                    plainFixedWidth = new SimpleAttributeSet(plain);
195:                    StyleConstants.setFontFamily(plainFixedWidth,
196:                            fixedWidthFontName);
197:
198:                    errorFixedWidth = new SimpleAttributeSet(error);
199:                    StyleConstants.setFontFamily(errorFixedWidth,
200:                            fixedWidthFontName);
201:
202:                    warningFixedWidth = new SimpleAttributeSet(warning);
203:                    StyleConstants.setFontFamily(warningFixedWidth,
204:                            fixedWidthFontName);
205:
206:                    actionFixedWidth = new SimpleAttributeSet(action);
207:                    StyleConstants.setFontFamily(actionFixedWidth,
208:                            fixedWidthFontName);
209:
210:                }
211:
212:                protected void appendErrorFixedWidth(String text) {
213:                    append(text, errorFixedWidth);
214:                }
215:
216:                protected void appendWarningFixedWidth(String text) {
217:                    append(text, warningFixedWidth);
218:                }
219:
220:                protected void appendPlainFixedWidth(String text) {
221:                    append(text, plainFixedWidth);
222:                }
223:
224:                protected void appendActionFixedWidth(String text) {
225:                    append(text, actionFixedWidth);
226:                }
227:
228:                protected void appendError(String text) {
229:                    append(text, error);
230:                }
231:
232:                protected void appendWarning(String text) {
233:                    append(text, warning);
234:                }
235:
236:                protected void appendPlain(String text) {
237:                    append(text, plain);
238:                }
239:
240:                protected void appendAction(String text) {
241:                    append(text, action);
242:                }
243:
244:                protected void append(String text, AttributeSet attrs) {
245:                    int length = getLength();
246:                    if (length > 0) {
247:                        textBuffer.append(NEW_LINE_CHAR);
248:                    }
249:
250:                    textBuffer.append(text);
251:
252:                    try {
253:                        insertString(length, textBuffer.toString(), attrs);
254:                        if (length > 0) {
255:                            setCaretPosition(getLength());
256:                        }
257:                    } catch (BadLocationException e) {
258:                    }
259:                    textBuffer.setLength(0);
260:                }
261:
262:            } // class OutputPaneDocument
263:
264:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.