1 package SnowMailClient.SpamFilter; 2 3 import snow.sortabletable.*; 4 import SnowMailClient.Language.*; 5 import javax.swing.table.*; 6 import java.util.*; 7 import java.text.DecimalFormat ; 8 9 public final class SpamStatTableModel extends FineGrainTableModel 10 { 11 static final private String [] COLUMN_NAMES = new String []{ 12 Language.translate("Word"), 13 Language.translate("SPAM probability"), 14 Language.translate("Ham occurences"), 15 Language.translate("SPAM occurences") 16 }; 17 18 final private Vector<Word> words = new Vector<Word>(); 19 20 final private DecimalFormat df = new DecimalFormat ("0.00000"); 21 22 public SpamStatTableModel(Map<String ,Word> wordsTable) 23 { 24 words.addAll(wordsTable.values()); 25 } 26 27 public final int getRowCount() {return words.size();} 28 public final int getColumnCount() {return 4;} 29 30 public final Word getWordAt(int pos) 31 { 32 return words.elementAt(pos); 33 } 34 35 public final Object getValueAt(int row, int column) 36 { 37 Word w = getWordAt(row); 38 if(column==0) return w.word; 39 if(column==1) return df.format(w.getSpamProb()); 40 if(column==2) return w.getHamOccurences(); 41 if(column==3) return w.getSpamOccurences(); 42 43 return "?"; 44 } 45 46 public final int compareForColumnSort(int pos1, int pos2, int col) 47 { 48 if(col==1) 49 { 50 Word w1 = getWordAt(pos1); 51 Word w2 = getWordAt(pos2); 52 return this.compareDoubles(w1.getSpamProb(), w2.getSpamProb()); 53 } 54 else 55 { 56 return super.compareForColumnSort(pos1,pos2,col); 57 } 58 } 59 60 public final String getColumnName(int col) 61 { 62 return COLUMN_NAMES[col]; 63 } 64 65 } | Popular Tags |