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 ; 7 8 10 public class TraceModel extends AbstractTableModel 11 { 12 static final String [] COLUMN_NAMES = new String []{ "From", "By", "For", "Date" }; 13 14 public final Vector<TraceItem> traceItems = new Vector<TraceItem>(); 15 SimpleDateFormat dateFormat = new SimpleDateFormat (" dd MM yyyy hh:mm:ss"); 16 17 public TraceModel() 18 { 19 20 } 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 35 public int getRowCount() { return traceItems.size(); } 36 public int getColumnCount() { return COLUMN_NAMES.length; } 37 public Object 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 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 getColumnClass(int col) 76 { 77 return Object .class; 78 } 79 80 public String getColumnName(int column) 81 { 82 return this.COLUMN_NAMES[column]; 83 } 84 85 86 87 } | Popular Tags |