001: package net.matuschek.jobo;
002:
003: import java.util.Vector;
004:
005: import net.matuschek.swing.JHideFrame;
006:
007: /*********************************************
008: Copyright (c) 2001 by Daniel Matuschek
009: *********************************************/
010:
011: /**
012: * Simple JFrame for Log4J logging
013: *
014: * @author Daniel Matuschek
015: * @version $Revision: 1.8 $
016: */
017: public class LogFrame extends JHideFrame {
018:
019: private static final long serialVersionUID = 3177932656317752712L;
020:
021: /**
022: * Creates new form LogFrame
023: */
024: public LogFrame() {
025: listData = new Vector<String>();
026: initComponents();
027: pack();
028: }
029:
030: /**
031: * This method is called from within the constructor to
032: * initialize the form.
033: */
034: private void initComponents() {
035: buttonPanel = new java.awt.Panel();
036: closeButton = new java.awt.Button();
037: clearButton = new java.awt.Button();
038: messagePanel = new javax.swing.JPanel();
039: jScrollPane1 = new javax.swing.JScrollPane();
040: messageList = new javax.swing.JList();
041: setName("JoBo Logging");
042: addWindowListener(new java.awt.event.WindowAdapter() {
043: public void windowClosing(java.awt.event.WindowEvent evt) {
044: exitForm();
045: }
046: });
047: closeButton.setLabel("Close");
048: closeButton
049: .addActionListener(new java.awt.event.ActionListener() {
050: public void actionPerformed(
051: java.awt.event.ActionEvent evt) {
052: exitForm();
053: }
054: });
055: clearButton.setLabel("Clear");
056: clearButton
057: .addActionListener(new java.awt.event.ActionListener() {
058: public void actionPerformed(
059: java.awt.event.ActionEvent evt) {
060: clearLog();
061: }
062: });
063: buttonPanel.add(clearButton);
064: buttonPanel.add(closeButton);
065:
066: getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH);
067:
068: messagePanel.setLayout(new javax.swing.BoxLayout(messagePanel,
069: 0));
070:
071: jScrollPane1.setViewportView(messageList);
072:
073: messagePanel.add(jScrollPane1);
074:
075: getContentPane()
076: .add(messagePanel, java.awt.BorderLayout.CENTER);
077:
078: }
079:
080: public void addMsg(String msg) {
081: listData.add(msg);
082:
083: // if there are to many messages, remove the first one ...
084: if (listData.size() > maxLog) {
085: listData.remove(0);
086: }
087:
088: messageList.setListData(listData);
089: }
090:
091: public void clearLog() {
092: listData.clear();
093: messageList.setListData(listData);
094: }
095:
096: private Vector<String> listData = null;
097: private static int maxLog = 2000;
098:
099: private java.awt.Panel buttonPanel;
100: private java.awt.Button closeButton;
101: private java.awt.Button clearButton;
102: private javax.swing.JPanel messagePanel;
103: private javax.swing.JScrollPane jScrollPane1;
104: private javax.swing.JList messageList;
105: }
|