package log.swing;

import log.*;

import util.swing.*;

import java.util.*;

/**
  * TableEntryDescriptor that can be used to display {@link LogEntry LogEntries}.
  *
  * <p>LogEntries will be displayed using two columns. The first column will have the heading &quot;Date&quot;
  * and will show the LogEntry's {@link LogEntry#getLogDate log date}. The second column will show the return
  * of the LogEntry's {@link Object#toString} method under the heading &quot;Description&quot;. Both columns
  * are not editable.</p>
  *
  * @author Steffen Zschaler
  * @version 2.0 14/07/1999
  * @since v2.0
  */
public class DefaultLogEntryTED extends AbstractTableEntryDescriptor {

  /**
    * There are two columns.
    */
  public int getColumnCount() {
    return 2;
  }

  /**
    * The column name of the first column is &quot;Date&quot;, that of the second column is
    * &quot;Description&quot;.
    */
  public String getColumnName (int nIdx) {
    String[] asNames = {"Date", "Description"};

    return asNames[nIdx];
  }

  /**
    * The column class of the first column is <code>Date.class</code>, that of the second column is
    * <code>String.class</code>.
    */
  public Class getColumnClass (int nIdx) {
    Class[] acClasses = {Date.class, String.class};

    return acClasses[nIdx];
  }

  /**
    * The object is assumed to be a {@link LogEntry}; the value of the first column is the
    * {@link LogEntry#getLogDate log date} that of the second column is the result of the object's
    * {@link Object#toString} method.
    */
  public Object getValueAt (Object oData, int nIdx) {
    switch (nIdx) {
    case 0:
      return ((LogEntry) oData).getLogDate();
    default:
      return oData.toString();
    }
  }
}