ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/core/loggers/SimpleSwingLogger.java
Revision: 1.7
Committed: Sun Feb 25 20:49:20 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.6: +23 -14 lines
Log Message:
Sorted out the javadoc comments.

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2 ajm 1.4 package uk.ac.ukc.iscream.core.loggers;
3 ajm 1.1
4     //---IMPORTS---
5 ajm 1.5 import uk.ac.ukc.iscream.util.*;
6     import uk.ac.ukc.iscream.core.*;
7 ajm 1.1 import java.util.Date;
8     import java.text.DateFormat;
9     import java.util.Locale;
10     import javax.swing.*;
11 ajm 1.2 import javax.swing.border.*;
12     import java.awt.Color;
13 ajm 1.1
14     /**
15 ajm 1.5 * The SimpleSwingLogger is an implementation of the LoggerImpl defined
16 ajm 1.1 * in the associated interface. It's only purpose is to simply print
17     * all the logging information it receives to a window frame.
18     *
19     * All very simple really...
20     *
21 ajm 1.5 * This class does have the problem that if too many messages are
22     * entered into the text area, then it will fill the memory of
23     * the JVM. This MAY have been fixed by adding the setRows(int)
24     * in the write(string) method, however the Java API does not
25     * specify if this enforces the max rows, but I THINK it does.
26     *
27 tdb 1.7 * @author $Author: tdb1 $
28     * @version $Id: SimpleSwingLogger.java,v 1.6 2001/02/25 20:34:17 tdb1 Exp $
29 ajm 1.1 */
30 ajm 1.4 public class SimpleSwingLogger extends JFrame implements LoggerImpl {
31 ajm 1.1
32     //---FINAL ATTRIBUTES---
33    
34     /**
35     * The current CVS revision of this class
36     */
37 tdb 1.7 public final String REVISION = "$Revision: 1.6 $";
38 ajm 1.1
39 ajm 1.2 private final int width = 700;
40     private final int height = 400;
41    
42 ajm 1.1 //---STATIC METHODS---
43    
44     //---CONSTRUCTORS---
45    
46     /**
47 ajm 1.2 * Creates a new Simple Swing Logger.
48 ajm 1.1 */
49 ajm 1.2 public SimpleSwingLogger() {
50 ajm 1.5 _maxMessages = Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.LoggerClass.SimpleSwingLogger.maxMessages"));
51 ajm 1.2 System.out.println(this.toString() + ": opening window");
52    
53     // set up the Frame
54     setTitle("I-Scream Logger");
55     setSize(width, height);
56     getContentPane().setBackground(Color.white);
57     setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
58     Box box = Box.createVerticalBox();
59    
60     // create the i-scream logo at the top
61 ajm 1.4 JLabel iscream = new JLabel(new ImageIcon("./uk/ac/ukc/iscream/core/loggers/i-scream.gif"));
62 ajm 1.3 JLabel comment = new JLabel(" I-Scream System Logging Console");
63     comment.setForeground( new Color(0, 0, 102));
64 ajm 1.2 iscream.setBackground(Color.white);
65 ajm 1.3 comment.setBackground(Color.white);
66 ajm 1.2 Box header = Box.createHorizontalBox();
67 ajm 1.3 header.add(comment);
68 ajm 1.2 header.add(Box.createHorizontalGlue());
69     header.add(iscream);
70    
71     // set up the text area
72     _textArea.setEditable(false);
73     JScrollPane text = new JScrollPane(_textArea);
74     text.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
75     text.setBackground(Color.white);
76    
77     // build the frame
78     box.add(header);
79     box.add(text);
80     getContentPane().add(box);
81    
82     // show the window
83     show();
84 ajm 1.5 write(toString(), Logger.SYSINIT, "started");
85 ajm 1.1 }
86    
87     //---PUBLIC METHODS---
88    
89     /**
90 tdb 1.7 * The write() method takes a line of text, pre-formatted
91     * and outputs it using a method defined by the actual
92     * implementation. The verbosity is given in case the
93     * implementation wishes to utilise it in the layout -
94     * eg. a different colour or font.
95     *
96     * This instance writes the line to a Swing based GUI
97     * logger.
98     *
99     * @param line A line of formatted text to be logged
100     * @param verbosity the verbosity of this message
101     */
102 tdb 1.6 public synchronized void write(String line, int verbosity) {
103     _textArea.insert(line + "\n",0);
104     _textArea.setRows(_maxMessages);
105 ajm 1.1 }
106    
107     /**
108     * Overrides the {@link java.lang.Object#toString() Object.toString()}
109     * method to provide clean logging (every class should have this).
110     *
111 ajm 1.5 * This uses the uk.ac.ukc.iscream.util.FormatName class
112     * to format the toString()
113     *
114 ajm 1.1 * @return the name of this class and its CVS revision
115     */
116     public String toString() {
117 ajm 1.5 return FormatName.getName(
118     _name,
119     getClass().getName(),
120     REVISION);
121 ajm 1.1 }
122 ajm 1.5
123 ajm 1.1 //---PRIVATE METHODS---
124    
125 tdb 1.7 /**
126     * This method is provided if this class wishes to log
127     * a message itself.
128     *
129     * @param source A String representation of the source
130     * @param verbosity the verbosity of this message
131     * @param message The message to log
132     */
133 tdb 1.6 private void write(String source, int verbosity, String message) {
134     write(FormatName.formatLogLine(source, verbosity, message), verbosity);
135 ajm 1.1 }
136    
137     //---ACCESSOR/MUTATOR METHODS---
138    
139 ajm 1.2 //---ATTRIBUTES---
140 ajm 1.1
141 ajm 1.2 /**
142     * A text area to write log messages to
143     */
144 ajm 1.1 private JTextArea _textArea = new JTextArea();
145 ajm 1.5
146     /**
147     * The maximum number of messages that can
148     * be displayed before bottom items are removed.
149     * This is needed to fix the memory overload problem
150     * that was seen when the GUI got too full!
151     */
152     private int _maxMessages;
153    
154     /**
155     * This is the friendly identifier of the
156     * component this class is running in.
157     * eg, a Filter may be called "filter1",
158     * If this class does not have an owning
159     * component, a name from the configuration
160     * can be placed here. This name could also
161     * be changed to null for utility classes.
162     */
163     private String _name = Core.NAME;
164 ajm 1.1
165     //---STATIC ATTRIBUTES---
166    
167     }