1 package SnowMailClient.view; 2 3 import snow.sortabletable.*; 4 import SnowMailClient.model.MailMessage; 5 import SnowMailClient.SnowMailClientApp; 6 import SnowMailClient.SpamFilter.*; 7 import snow.lookandfeel.*; 8 9 import javax.swing.*; 10 import javax.swing.border.*; 11 import javax.swing.table.*; 12 import java.awt.*; 13 import java.beans.*; 14 15 18 public final class FolderViewTableCellRenderer extends JLabel implements TableCellRenderer 19 { 20 Font normalFont, boldFont; 21 FolderView folderView; 22 SortableTableModel sortableTableModel; 23 24 25 27 public FolderViewTableCellRenderer(FolderView folderView, SortableTableModel sortableTableModel ) { 30 super(); 31 this.folderView = folderView; 32 this.sortableTableModel = sortableTableModel; 33 34 setup(); 35 } 37 43 public void updateUI() 44 { 45 super.updateUI(); 46 setup(); 47 } 48 49 private void setup() 50 { 51 normalFont = UIManager.getFont("Table.font"); 52 int fontSize = normalFont.getSize(); 53 boldFont = normalFont.deriveFont(Font.BOLD); 55 Border emptyBorder = new EmptyBorder(fontSize/4, fontSize/2, fontSize/4, fontSize/2); 56 this.setBorder(emptyBorder); 57 58 } 59 60 public Component getTableCellRendererComponent( 61 JTable table, Object value, boolean isSelected, boolean hasFocus, 62 int row, int viewColumn) 63 { 64 String text = value.toString(); 65 this.setText(text); 66 setOpaque(false); 67 68 int ind = sortableTableModel.getIndexInUnsortedFromTablePos(row); 69 70 if(this.folderView.getMailFolder()==null) return this; 72 MailMessage mess = this.folderView.getMailFolder().getMessageAt(ind); 73 boolean newMail = mess.getIsNew(); 74 if(newMail) 75 { 76 setFont(this.boldFont); 77 } 78 else 79 { 80 this.setFont(normalFont); 81 } 82 83 int column = sortableTableModel.getColumnForViewIndex(viewColumn); 85 86 this.setForeground(UIManager.getColor("Tree.selectionForeground")); 87 88 if(isSelected) { 91 setBackground(UIManager.getColor("Tree.selectionBackground")); 92 setOpaque(true); 93 } 94 else 95 { 96 setOpaque(false); 97 } 98 99 if(true) 100 { 101 if(column==0) 102 { 103 String from = mess.getFromAddress().getMailAddress(); 105 if(SnowMailClientApp.getInstance().getAddressBook().getAddress(from)!=null) 106 { 107 if(isSelected) 108 { 109 setBackground(ThemesManager.getInstance().getGreen().darker()); 110 } 111 else 112 { 113 setBackground(ThemesManager.getInstance().getGreen()); 114 } 115 setOpaque(true); 116 } 117 else if(SnowMailClientApp.getInstance().getSpamBook().getAddress(from)!=null) 118 { 119 if(isSelected) 120 { 121 setBackground(ThemesManager.getInstance().getRed().darker()); 122 } 123 else 124 { 125 setBackground(ThemesManager.getInstance().getRed()); 126 } 127 setOpaque(true); 128 } 129 else 130 { 131 if(isSelected) 132 { 133 setBackground(UIManager.getColor("Tree.selectionBackground")); 134 setOpaque(true); 135 } 136 else 137 { 138 setOpaque(false); 139 } 140 } 141 } 142 143 else if(column==4) { 145 if(mess.getSize()>500000) 146 { 147 setForeground(ThemesManager.getInstance().getRed().darker()); 148 } 149 } 150 151 else if(column==5) { 153 this.setFont(normalFont); 154 double prob = mess.getSPAMProbability(); 155 if(WordStatistic.isSpam(prob)) 156 { 157 setText("S"); 158 } 159 else 160 { 161 setText(""); 162 } 163 164 if(mess.getIsFalsePositive()) 165 { 166 setOpaque(true); 169 setText("F"); 170 setBackground( Color.RED ); } 173 else if(mess.getIsSPAM()) 174 { 175 setOpaque(true); 176 if(isSelected) 177 { 178 setBackground(ThemesManager.getInstance().getRed().darker()); 179 } 180 else 181 { 182 setBackground(ThemesManager.getInstance().getRed()); 183 } 184 } 185 else if(mess.getIsHAM()) 186 { 187 setOpaque(true); 188 if(isSelected) 189 { 190 setBackground(ThemesManager.getInstance().getGreen().darker()); 191 } 192 else 193 { 194 setBackground(ThemesManager.getInstance().getGreen()); 195 } 196 } 197 else 198 { 199 setOpaque(false); } 201 202 } 203 } 204 205 206 return this; 207 } 208 209 210 211 } | Popular Tags |