KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > matuschek > jobo > LogFrame


1 package net.matuschek.jobo;
2
3 import java.util.Vector JavaDoc;
4
5 import net.matuschek.swing.JHideFrame;
6 /*********************************************
7     Copyright (c) 2001 by Daniel Matuschek
8  *********************************************/

9
10
11 /**
12  * Simple JFrame for Log4J logging
13  *
14  * @author Daniel Matuschek
15  * @version $Revision: 1.8 $
16  */

17 public class LogFrame extends JHideFrame {
18
19     private static final long serialVersionUID = 3177932656317752712L;
20
21     /**
22      * Creates new form LogFrame
23      */

24     public LogFrame() {
25         listData = new Vector JavaDoc<String JavaDoc>();
26         initComponents ();
27         pack ();
28     }
29
30     /**
31      * This method is called from within the constructor to
32      * initialize the form.
33      */

34     private void initComponents() {
35         buttonPanel = new java.awt.Panel JavaDoc();
36         closeButton = new java.awt.Button JavaDoc();
37         clearButton = new java.awt.Button JavaDoc();
38         messagePanel = new javax.swing.JPanel JavaDoc();
39         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
40         messageList = new javax.swing.JList JavaDoc();
41         setName("JoBo Logging");
42         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
43             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
44                 exitForm();
45             }
46         }
47         );
48         closeButton.setLabel("Close");
49         closeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
50             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
51                 exitForm();
52             }
53         }
54         );
55         clearButton.setLabel("Clear");
56         clearButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
57             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
58                 clearLog();
59             }
60         }
61         );
62         buttonPanel.add(clearButton);
63         buttonPanel.add(closeButton);
64
65         getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH);
66
67         messagePanel.setLayout(new javax.swing.BoxLayout JavaDoc(messagePanel, 0));
68
69         jScrollPane1.setViewportView(messageList);
70
71         messagePanel.add(jScrollPane1);
72
73         getContentPane().add(messagePanel, java.awt.BorderLayout.CENTER);
74
75     }
76
77     public void addMsg(String JavaDoc msg) {
78         listData.add(msg);
79
80         // if there are to many messages, remove the first one ...
81
if (listData.size() > maxLog) {
82             listData.remove(0);
83         }
84
85         messageList.setListData(listData);
86     }
87
88     public void clearLog() {
89         listData.clear();
90         messageList.setListData(listData);
91     }
92
93     private Vector JavaDoc<String JavaDoc> listData = null;
94     private static int maxLog = 2000;
95
96     private java.awt.Panel JavaDoc buttonPanel;
97     private java.awt.Button JavaDoc closeButton;
98     private java.awt.Button JavaDoc clearButton;
99     private javax.swing.JPanel JavaDoc messagePanel;
100     private javax.swing.JScrollPane JavaDoc jScrollPane1;
101     private javax.swing.JList JavaDoc messageList;
102 }
103
Popular Tags