1 package net.suberic.pooka.gui; 2 import net.suberic.pooka.*; 3 import javax.swing.tree.*; 4 import java.awt.*; 5 import javax.mail.MessagingException ; 6 import javax.swing.JTree ; 7 8 14 15 public class DefaultFolderTreeCellRenderer extends DefaultTreeCellRenderer { 16 20 21 22 24 Font specialFont = null; 25 26 Font defaultFont = null; 27 28 public DefaultFolderTreeCellRenderer() { 29 super(); 30 } 31 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { 32 super.getTreeCellRendererComponent(tree,value,sel,expanded,leaf,row,hasFocus); 33 70 71 73 TreePath tp = tree.getPathForRow(row); 74 75 if (tp != null && tp.getLastPathComponent() instanceof FolderNode) { 76 FolderNode node = (FolderNode)tp.getLastPathComponent(); 77 78 if (node.getFolderInfo().hasNewMessages()) 79 setText("* " + getText() + " *"); 80 81 if (isSpecial(node)) { 82 setFontToSpecial(); 83 } else { 84 setFontToDefault(); 85 } 86 } else { 87 setFontToDefault(); 88 } 89 90 return this; 91 } 92 93 public void setFontToDefault() { 94 if (getDefaultFont() != null) { 95 setFont(getDefaultFont()); 96 } else { 97 String fontStyle; 99 fontStyle = Pooka.getProperty("FolderTree.readStyle", ""); 100 101 Font f = null; 102 103 if (this.getFont() == null) 104 return; 105 106 if (fontStyle.equalsIgnoreCase("BOLD")) 107 f = this.getFont().deriveFont(Font.BOLD); 108 else if (fontStyle.equalsIgnoreCase("ITALIC")) 109 f = this.getFont().deriveFont(Font.ITALIC); 110 else if (fontStyle.equals("")) 111 f = this.getFont().deriveFont(Font.PLAIN); 112 113 if (f == null) 114 f = this.getFont(); 115 116 setDefaultFont(f); 117 this.setFont(f); 118 } 119 120 } 121 122 125 public void setFontToSpecial() { 126 if (getSpecialFont() != null) { 127 setFont(getSpecialFont()); 128 } else { 129 String fontStyle; 131 fontStyle = Pooka.getProperty("FolderTree.UnreadStyle", "BOLD"); 132 133 Font f = null; 134 135 Font thisFont = this.getFont(); 136 if (thisFont != null) { 137 if (fontStyle.equalsIgnoreCase("BOLD")) 138 f = thisFont.deriveFont(Font.BOLD); 139 else if (fontStyle.equalsIgnoreCase("ITALIC")) 140 f = thisFont.deriveFont(Font.ITALIC); 141 else if (fontStyle.equalsIgnoreCase("PLAIN")) 142 f = thisFont.deriveFont(Font.PLAIN); 143 144 if (f == null) 145 f = thisFont; 146 147 setSpecialFont(f); 148 this.setFont(f); 149 } 150 } 151 152 } 153 154 158 public boolean isSpecial (MailTreeNode node) { 159 if (node instanceof FolderNode) 160 return (node != null && ((FolderNode)node).getFolderInfo().hasUnread()); 161 else 162 return false; 163 } 164 165 public Font getSpecialFont() { 166 return specialFont; 167 } 168 169 public void setSpecialFont(Font newValue) { 170 specialFont = newValue; 171 } 172 173 public Font getDefaultFont() { 174 return defaultFont; 175 } 176 177 public void setDefaultFont(Font newValue) { 178 defaultFont = newValue; 179 } 180 181 182 185 public Color getTextSelectionColor() { 186 MainPanel mp = Pooka.getMainPanel(); 187 if (mp != null) { 188 FolderPanel fp = mp.getFolderPanel(); 189 190 if (fp != null) { 191 javax.swing.plaf.metal.MetalTheme currentTheme = fp .getCurrentTheme(); 192 if (currentTheme != null) { 193 return currentTheme.getHighlightedTextColor(); 194 } 195 } 196 } 197 return super.getTextSelectionColor(); 198 } 199 200 203 public Color getTextNonSelectionColor() { 204 MainPanel mp = Pooka.getMainPanel(); 205 if (mp != null) { 206 FolderPanel fp = mp.getFolderPanel(); 207 208 if (fp != null) { 209 javax.swing.plaf.metal.MetalTheme currentTheme = fp .getCurrentTheme(); 210 if (currentTheme != null) { 211 return currentTheme.getUserTextColor(); 212 } 213 } 214 } 215 return super.getTextNonSelectionColor(); 216 } 217 218 221 public Color getBackgroundSelectionColor() { 222 MainPanel mp = Pooka.getMainPanel(); 223 if (mp != null) { 224 FolderPanel fp = mp.getFolderPanel(); 225 226 if (fp != null) { 227 javax.swing.plaf.metal.MetalTheme currentTheme = fp .getCurrentTheme(); 228 if (currentTheme != null) { 229 return currentTheme.getTextHighlightColor(); 230 } 231 } 232 } 233 return super.getBackgroundSelectionColor(); 234 } 235 236 239 public Color getBackgroundNonSelectionColor() { 240 MainPanel mp = Pooka.getMainPanel(); 241 if (mp != null) { 242 FolderPanel fp = mp.getFolderPanel(); 243 244 if (fp != null) { 245 javax.swing.plaf.metal.MetalTheme currentTheme = fp .getCurrentTheme(); 246 247 if (currentTheme != null) { 248 return currentTheme.getWindowBackground(); 249 } 250 } 251 } 252 253 return super.getBackgroundNonSelectionColor(); 254 } 255 256 259 public Color getBorderSelectionColor() { 260 MainPanel mp = Pooka.getMainPanel(); 261 if (mp != null) { 262 FolderPanel fp = mp.getFolderPanel(); 263 264 if (fp != null) { 265 javax.swing.plaf.metal.MetalTheme currentTheme = fp .getCurrentTheme(); 266 if (currentTheme != null) { 267 return currentTheme.getFocusColor(); 268 } 269 } 270 } 271 272 return super.getBorderSelectionColor(); 273 } 274 275 276 } 278 | Popular Tags |