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