001 package log.swing; 002 003 import log.*; 004 import java.io.*; 005 import util.swing.*; 006 007 import java.util.*; 008 009 import java.text.*; 010 011 import javax.swing.*; 012 import javax.swing.table.*; 013 014 /** 015 * A JTable that can display log file contents. 016 * 017 * <p>The contents of the table is read at creation time and does not change, even if the log file contents 018 * change.</p> 019 * 020 * @author Steffen Zschaler 021 * @version 2.0 14/07/1999 022 * @since v2.0 023 */ 024 public class JLogTable extends JAbstractTable { 025 026 /** 027 * A TableCellRenderer that takes a Date and prints it with the standard date and time format for the 028 * default locale. 029 */ 030 public static final TableCellRenderer DATE_TIME_CELL_RENDERER = new 031 DefaultTableCellRenderer() { 032 private final DateFormat s_dfFormatter = DateFormat.getDateTimeInstance(); 033 034 { 035 setHorizontalAlignment(RIGHT); 036 } 037 038 public java.awt.Component getTableCellRendererComponent(JTable table, 039 Object value, 040 boolean isSelected, boolean hasFocus, int row, int column) { 041 super.getTableCellRendererComponent(table, value, isSelected, 042 hasFocus, row, column); 043 044 setText(s_dfFormatter.format((Date)value)); 045 046 return this; 047 } 048 }; 049 050 /** 051 * Create a new JLogTable. LogEntries are ordered by their log dates and displayed using the 052 * {@link DefaultLogEntryTED}. 053 * 054 * @param lis the LogInputStream that contains the LogEntries to be displayed. May be filtered. 055 */ 056 public JLogTable(LogFileContent lfc) { 057 this(lfc, null, new DefaultLogEntryTED()); 058 } 059 060 /** 061 * Create a new JLogTable. LogEntries are ordered by their log dates. 062 * 063 * @param lis the LogInputStream that contains the LogEntries to be displayed. May be filtered. 064 * @param ted a TableEntryDescriptor defining how LogEntries are to be displayed with respect to rows and 065 * columns in a table. 066 */ 067 public JLogTable(LogFileContent lfc, TableEntryDescriptor ted) { 068 this(lfc, null, ted); 069 } 070 071 /** 072 * Create a new JLogTable. LogEntries are displayed using the {@link DefaultLogEntryTED}. 073 * 074 * @param lis the LogInputStream that contains the LogEntries to be displayed. May be filtered. 075 * @param cmp a Comparator that defines the order the LogEntries appear in. May be <code>null</code> in 076 * which case LogEntries will be sorted by the {@link LogEntry#getLogDate log date}. 077 */ 078 public JLogTable(LogFileContent lfc, Comparator cmp) { 079 this(lfc, cmp, new DefaultLogEntryTED()); 080 } 081 082 /** 083 * Create a new JLogTable. 084 * 085 * @param lis the LogInputStream that contains the LogEntries to be displayed. May be filtered. 086 * @param cmp a Comparator that defines the order the LogEntries appear in. May be <code>null</code> in 087 * which case LogEntries will be sorted by the {@link LogEntry#getLogDate log date}. 088 * @param ted a TableEntryDescriptor defining how LogEntries are to be displayed with respect to rows and 089 * columns in a table. 090 */ 091 public JLogTable(LogFileContent lfc, Comparator cmp, 092 TableEntryDescriptor ted) { 093 super(new LogTableModel(lfc, cmp, ted)); 094 setDefaultRenderer(Date.class, DATE_TIME_CELL_RENDERER); 095 } 096 }