001 package log.swing;
002
003 import log.*;
004
005 import util.swing.*;
006
007 import java.util.*;
008
009 import java.io.*;
010
011 import data.Catalog;
012
013 /**
014 * Swing model for tables that can display log file contents. This model is static and cannot be changed.
015 *
016 * @see log.LogInputStream
017 * @see JLogTable
018 * @see DefaultLogEntryTED
019 *
020 * @author Steffen Zschaler
021 * @version 2.0 14/07/1999
022 * @since v2.0
023 */
024 public class LogTableModel extends AbstractTableModel {
025
026 /**
027 * The LogEntries in the same order in which they appear in the table.
028 *
029 * @serial
030 */
031 protected List m_lEntries;
032
033 /**
034 * Set the table's data. This actually has no effect here.
035 */
036 public void setData(Object n_lModel) {
037 }
038
039 /**
040 * Create a new LogTableModel. Usually you do not create a new model directly, but rather instantiate a
041 * new {@link JLogTable}.
042 *
043 * @param lfc the LogFileContent that contains the LogEntries to be displayed.
044 * @param cmp a Comparator that defines the order the LogEntries appear in. May be <code>null</code> in
045 * which case LogEntries will be sorted by the {@link LogEntry#getLogDate log date}.
046 * @param ted a TableEntryDescriptor defining how LogEntries are to be displayed with respect to rows and
047 * columns in a table.
048 *
049 * @see DefaultLogEntryTED
050 */
051 public LogTableModel(LogFileContent lfc, Comparator cmp, TableEntryDescriptor ted) {
052 super(ted);
053
054 m_lEntries = lfc.getContentList();
055
056 if (cmp == null) {
057 cmp = new Comparator() {
058 public int compare(Object o1, Object o2) {
059 LogEntry le1 = (LogEntry)o1;
060 LogEntry le2 = (LogEntry)o2;
061
062 return le1.getLogDate().compareTo(le2.getLogDate());
063 }
064 };
065 }
066
067 Collections.sort(m_lEntries, cmp);
068 }
069
070 /**
071 * Return the LogEntry at row <code>nRow</code>.
072 */
073 public Object getRecord(int nRow) {
074 if ((nRow >= 0) && (nRow < m_lEntries.size())) {
075 return m_lEntries.get(nRow);
076 } else {
077 return null;
078 }
079 }
080
081 /**
082 * Return the total amount of LogEntries in the model.
083 */
084 public int getRowCount() {
085 return m_lEntries.size();
086 }
087 }