1 package SnowMailClient.view.MessagesPreview; 2 3 import snow.sortabletable.*; 4 import snow.lookandfeel.*; 5 import SnowMailClient.model.*; 6 import SnowMailClient.SpamFilter.WordStatistic; 7 8 import javax.swing.*; 9 import javax.swing.border.*; 10 import javax.swing.table.*; 11 import java.awt.*; 12 import java.beans.*; 13 14 17 public class PreviewCellRenderer extends JLabel implements TableCellRenderer 18 { 19 PreviewModel previewModel; 20 SortableTableModel sortableTableModel; 21 22 public PreviewCellRenderer( PreviewModel previewModel, 23 SortableTableModel sortableTableModel ) 24 { 25 super(); 26 this.previewModel = previewModel; 27 this.sortableTableModel = sortableTableModel; 28 29 setup(); 30 } 31 32 38 public void updateUI() 39 { 40 super.updateUI(); 41 setup(); 42 } 43 44 private void setup() 45 { 46 int fontSize = UIManager.getFont("Label.font").getSize(); 47 Border emptyBorder = new EmptyBorder(fontSize/4, fontSize/2, fontSize/4, fontSize/2); 48 this.setBorder(emptyBorder); 49 } 50 51 public Component getTableCellRendererComponent( 52 JTable table, Object value, boolean isSelected, boolean hasFocus, 53 int row, int column) 54 { 55 this.setText(value.toString()); 56 57 int ind = sortableTableModel.getIndexInUnsortedFromTablePos(row); 58 PreviewHeader header = previewModel.getMessageHeaderAt(ind); 59 60 this.setForeground(UIManager.getColor("Tree.selectionForeground")); 61 62 if(isSelected) { 65 setBackground(UIManager.getColor("Tree.selectionBackground")); 66 setOpaque(true); 67 } 68 else 69 { 70 setOpaque(false); 71 } 72 73 if(true) 74 { 75 if(column==1) { 77 boolean knownForm = header.getEntryValue("PreviewModel_known_from", "false").equals("true"); 78 boolean spamFrom = header.getEntryValue("PreviewModel_spam_from", "false").equals("true"); 79 if(knownForm) 80 { 81 setGreenCell(isSelected); 82 } 83 else if(spamFrom) 84 { 85 setRedCell(isSelected); 86 } 87 else 88 { 89 if(isSelected) 90 { 91 setBackground(UIManager.getColor("Tree.selectionBackground")); 92 setOpaque(true); 93 } 94 else 95 { 96 setOpaque(false); 97 } 98 } 99 } 100 else if(column==2) { 102 boolean invalidTo = header.getEntryValue("PreviewModel_invalid_to", "false").equals("true"); 103 if(invalidTo) 104 { 105 setRedCell(isSelected); 106 } 107 else 108 { 109 if(isSelected) 110 { 111 setBackground(UIManager.getColor("Tree.selectionBackground")); 112 setOpaque(true); 113 } 114 else 115 { 116 setOpaque(false); 117 } 118 } 119 } 120 else if(column==3) { 122 123 } 124 else if(column==4) { 126 127 } 128 else if (column==6) 129 { 130 if(header.getSizeInBytes()>400000) 131 { 132 this.setForeground(ThemesManager.getInstance().getRed().darker()); 133 } 135 else 136 { 137 this.setForeground(UIManager.getColor("Tree.selectionForeground")); 138 } 140 } 141 else if (column==7 && header.hasEntry("PreviewModel_spam_prob")) 142 { 143 double p = Double.parseDouble(header.getEntryValue("PreviewModel_spam_prob", "0.0")); 144 if(WordStatistic.isSpam(p)) 145 { 146 setRedCell(isSelected); 147 } 148 else 149 { 150 setOpaque(false); 151 } 152 } 153 else 154 { 155 } 157 } 158 159 return this; 160 } 161 162 163 private void setGreenCell(boolean isSelected) 164 { 165 if(isSelected) 166 { 167 setBackground(ThemesManager.getInstance().getGreen().darker()); 168 } 169 else 170 { 171 setBackground(ThemesManager.getInstance().getGreen()); 172 } 173 setOpaque(true); 174 } 175 176 private void setRedCell(boolean isSelected) 177 { 178 if(isSelected) 179 { 180 setBackground(ThemesManager.getInstance().getRed().darker()); 181 } 182 else 183 { 184 setBackground(ThemesManager.getInstance().getRed()); 185 } 186 setOpaque(true); 187 } 188 189 190 } | Popular Tags |