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