001    package log.swing;
002    
003    import log.*;
004    
005    import util.swing.*;
006    
007    import java.util.*;
008    
009    /**
010     * TableEntryDescriptor that can be used to display {@link LogEntry LogEntries}.
011     *
012     * <p>LogEntries will be displayed using two columns. The first column will have the heading &quot;Date&quot;
013     * and will show the LogEntry's {@link LogEntry#getLogDate log date}. The second column will show the return
014     * of the LogEntry's {@link Object#toString} method under the heading &quot;Description&quot;. Both columns
015     * are not editable.</p>
016     *
017     * @author Steffen Zschaler
018     * @version 2.0 14/07/1999
019     * @since v2.0
020     */
021    public class DefaultLogEntryTED extends AbstractTableEntryDescriptor {
022    
023        /**
024             * ID for serialization.
025             */
026            private static final long serialVersionUID = 3964287940745797692L;
027    
028            /**
029         * There are two columns.
030         */
031        public int getColumnCount() {
032            return 2;
033        }
034    
035        /**
036         * The column name of the first column is &quot;Date&quot;, that of the second column is
037         * &quot;Description&quot;.
038         */
039        public String getColumnName(int nIdx) {
040            String[] asNames = {
041                    "Date", "Description"};
042    
043            return asNames[nIdx];
044        }
045    
046        /**
047         * The column class of the first column is <code>Date.class</code>, that of the second column is
048         * <code>String.class</code>.
049         */
050        public Class<?> getColumnClass(int nIdx) {
051            Class[] acClasses = {
052                    Date.class, String.class};
053    
054            return acClasses[nIdx];
055        }
056    
057        /**
058         * The object is assumed to be a {@link LogEntry}; the value of the first column is the
059         * {@link LogEntry#getLogDate log date} that of the second column is the result of the object's
060         * {@link Object#toString} method.
061         */
062        public Object getValueAt(Object oData, int nIdx) {
063            switch (nIdx) {
064                case 0:
065                    return ((LogEntry)oData).getLogDate();
066                default:
067                    return oData.toString();
068            }
069        }
070    }