Source Code Cross Referenced for ConsoleLogger.java in  » J2EE » jag » com » finalist » jaggenerator » 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 » J2EE » jag » com.finalist.jaggenerator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*   Copyright (C) 2003 Finalist IT Group
002:         *
003:         *   This file is part of JAG - the Java J2EE Application Generator
004:         *
005:         *   JAG is free software; you can redistribute it and/or modify
006:         *   it under the terms of the GNU General Public License as published by
007:         *   the Free Software Foundation; either version 2 of the License, or
008:         *   (at your option) any later version.
009:         *   JAG is distributed in the hope that it will be useful,
010:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         *   GNU General Public License for more details.
013:         *   You should have received a copy of the GNU General Public License
014:         *   along with JAG; if not, write to the Free Software
015:         *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
016:         */
017:
018:        package com.finalist.jaggenerator;
019:
020:        import java.awt.Color;
021:        import java.util.HashMap;
022:
023:        import javax.swing.JTextArea;
024:        import javax.swing.JTextPane;
025:        import javax.swing.text.AttributeSet;
026:        import javax.swing.text.BadLocationException;
027:        import javax.swing.text.JTextComponent;
028:        import javax.swing.text.SimpleAttributeSet;
029:        import javax.swing.text.StyleConstants;
030:
031:        import org.apache.log4j.lf5.LogLevel;
032:
033:        /**
034:         * Yet another logger implementation... ;) This logger logs to the JTextArea in
035:         * the JAG gui.
036:         * 
037:         * @author Michael O'Connor - Finalist IT Group
038:         */
039:        public class ConsoleLogger {
040:
041:            public static final HashMap styleMap = new HashMap();
042:
043:            static SimpleAttributeSet BLACK = new SimpleAttributeSet();
044:            static SimpleAttributeSet YELLOW = new SimpleAttributeSet();
045:            static SimpleAttributeSet RED = new SimpleAttributeSet();
046:
047:            static {
048:                styleMap.put(LogLevel.INFO, BLACK);
049:                styleMap.put(LogLevel.DEBUG, YELLOW);
050:                styleMap.put(LogLevel.ERROR, RED);
051:
052:                StyleConstants.setForeground(BLACK, Color.BLACK);
053:                StyleConstants.setFontFamily(BLACK, "Lucida");
054:                StyleConstants.setFontSize(BLACK, 10);
055:
056:                StyleConstants.setForeground(YELLOW, Color.YELLOW);
057:                StyleConstants.setFontFamily(YELLOW, "Lucida");
058:                StyleConstants.setFontSize(YELLOW, 10);
059:
060:                StyleConstants.setForeground(RED, Color.RED);
061:                StyleConstants.setFontFamily(RED, "Lucida");
062:                StyleConstants.setFontSize(RED, 10);
063:            }
064:
065:            private boolean colored;
066:
067:            private JTextComponent genericConsole;
068:
069:            /**
070:             * Creates a ConsoleLogger.
071:             * 
072:             * @param console
073:             */
074:            public ConsoleLogger(JTextArea console) {
075:                setGenericConsole(console);
076:                setColored(false);
077:            }
078:
079:            /**
080:             * Creates a ConsoleLogger with color support.
081:             * 
082:             * @param console
083:             */
084:            public ConsoleLogger(JTextPane console) {
085:                setGenericConsole(console);
086:                setColored(true);
087:            }
088:
089:            /**
090:             * Appends a log to the end of the console.
091:             * 
092:             * @param message
093:             *            the log message.
094:             */
095:            public void log(String message) {
096:                log(message, LogLevel.INFO);
097:            }
098:
099:            /**
100:             * Appends a log to the end of the console.
101:             * 
102:             * @param message
103:             *            the log message.
104:             * @param level
105:             *            the level, log4j style. 
106:             */
107:            public void log(String message, LogLevel level) {
108:                if (isColored()) {
109:                    insertText(message, getSyle4Level(level));
110:                } else
111:                    insertText(message, BLACK);
112:                insertText("\n", BLACK);
113:                setEndSelection();
114:            }
115:
116:            private SimpleAttributeSet getSyle4Level(LogLevel level) {
117:                SimpleAttributeSet c = (SimpleAttributeSet) ConsoleLogger.styleMap
118:                        .get(level);
119:                SimpleAttributeSet ret = BLACK;
120:                if (c != null)
121:                    ret = c;
122:
123:                return ret;
124:            }
125:
126:            public boolean isColored() {
127:                return colored;
128:            }
129:
130:            public void setColored(boolean colored) {
131:                this .colored = colored;
132:            }
133:
134:            public JTextComponent getGenericConsole() {
135:                return genericConsole;
136:            }
137:
138:            public void setGenericConsole(JTextComponent genericConsole) {
139:                this .genericConsole = genericConsole;
140:            }
141:
142:            protected void insertText(String text, AttributeSet set) {
143:                try {
144:                    genericConsole.getDocument()
145:                            .insertString(
146:                                    genericConsole.getDocument().getLength(),
147:                                    text, set);
148:                } catch (BadLocationException e) {
149:                    e.printStackTrace();
150:                }
151:            }
152:
153:            // Needed for inserting icons in the right places
154:            protected void setEndSelection() {
155:                genericConsole.setSelectionStart(genericConsole.getDocument()
156:                        .getLength());
157:                genericConsole.setSelectionEnd(genericConsole.getDocument()
158:                        .getLength());
159:            }
160:
161:            /**
162:             * Appends an red error log to the end of the console. 
163:             * 
164:             * @param message
165:             *            the log message.
166:             */
167:            public void error(String message) {
168:                log(message, LogLevel.ERROR);
169:            }
170:
171:            /**
172:             * Appends an yellow debug log to the end of the console. 
173:             * 
174:             * @param message
175:             *            the log message.
176:             */
177:            public void debug(String message) {
178:                log(message, LogLevel.DEBUG);
179:            }
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.