KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > view > traceView > TraceModel


1 package SnowMailClient.view.traceView;
2
3 import SnowMailClient.utils.MailMessageUtils;
4 import javax.swing.table.*;
5 import java.util.*;
6 import java.text.SimpleDateFormat JavaDoc;
7
8 /** structured infos of the trace of a single message parsed from Received fields in the header
9 */

10 public class TraceModel extends AbstractTableModel
11 {
12   static final String JavaDoc[] COLUMN_NAMES = new String JavaDoc[]{ "From", "By", "For", "Date" };
13
14   public final Vector<TraceItem> traceItems = new Vector<TraceItem>();
15   SimpleDateFormat JavaDoc dateFormat = new SimpleDateFormat JavaDoc(" dd MM yyyy hh:mm:ss");
16
17   public TraceModel()
18   {
19
20   } // Constructor
21

22   public void addItem(TraceItem ti)
23   {
24      traceItems.addElement(ti);
25   }
26
27   public TraceItem getItemAt(int pos)
28   {
29     return traceItems.elementAt(pos);
30   }
31
32   // Table model
33
//
34

35   public int getRowCount() { return traceItems.size(); }
36   public int getColumnCount() { return COLUMN_NAMES.length; }
37   public Object JavaDoc getValueAt(int row, int column)
38   {
39      TraceItem ti = getItemAt(row);
40      if(column==0)
41      {
42        return ti.getFrom();
43      }
44      else if(column==1)
45      {
46        return ti.getBy();
47      }
48      else if(column==2)
49      {
50        return ti.getFor();
51      }
52      else if(column==3)
53      {
54        try
55        {
56           Date date = MailMessageUtils.parseDateFromString(ti.getDate());
57           return dateFormat.format(date);
58        }
59        catch(Exception JavaDoc e){}
60
61        return ti.getDate();
62      }
63
64      return "?";
65   }
66
67
68
69
70   public boolean isCellEditable(int rowIndex, int columnIndex)
71   {
72     return false;
73   }
74
75   public Class JavaDoc getColumnClass(int col)
76   {
77     return Object JavaDoc.class;
78   }
79
80   public String JavaDoc getColumnName(int column)
81   {
82     return this.COLUMN_NAMES[column];
83   }
84
85
86
87 } // TraceModel
Popular Tags