1 package net.suberic.pooka.gui; 2 import net.suberic.pooka.*; 3 import net.suberic.util.gui.IconManager; 4 import javax.swing.tree.*; 5 import java.awt.*; 6 import javax.swing.Icon ; 7 import javax.swing.ImageIcon ; 8 import javax.swing.JTree ; 9 10 14 public class EnhancedFolderTreeCellRenderer extends DefaultFolderTreeCellRenderer { 15 16 protected boolean hasFocus; 17 18 Icon rootIcon; 19 Icon connectedIcon; 20 Icon disconnectedIcon; 21 Icon closedFolderIcon; 22 Icon unavailableIcon; 23 Icon connectedStoreIcon; 24 Icon disconnectedStoreIcon; 25 Icon closedStoreIcon; 26 Icon subfolderIcon; 27 Icon subfolderWithNewIcon; 28 Icon subfolderClosedIcon; 29 Icon connectedWithNewIcon; 30 Icon disconnectedWithNewIcon; 31 32 35 public EnhancedFolderTreeCellRenderer() { 36 super(); 37 } 38 39 42 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { 43 super.getTreeCellRendererComponent(tree,value,sel,expanded,leaf,row,hasFocus); 44 TreePath tp = tree.getPathForRow(row); 45 46 if (tp != null) { 47 Object lastPath = tp.getLastPathComponent(); 48 if (lastPath instanceof FolderNode) { 49 FolderNode node = (FolderNode)lastPath; 50 51 FolderInfo fi = node.getFolderInfo(); 52 53 if (isSpecial(node)) { 54 setFontToSpecial(); 55 } else { 56 setFontToDefault(); 57 } 58 59 FolderInfo folderInfo = ((FolderNode)node).getFolderInfo(); 60 61 if (folderInfo == null){ 62 setIconToClosedFolder(); 63 } else { 64 if (!((FolderNode)node).isLeaf()) { 66 if (folderInfo.hasNewMessages() && folderInfo.notifyNewMessagesNode()) 68 setIconToSubfolderWithNew(); 69 else if ((folderInfo.getType() & javax.mail.Folder.HOLDS_MESSAGES) != 0) { 70 if ( folderInfo.isConnected()) { 73 setIconToSubfolder(); 74 } else { 75 setIconToSubfolderClosed(); 76 } 77 } else { 78 if ( folderInfo.getParentStore().isConnected()) { 79 setIconToSubfolder(); 80 } else { 81 setIconToSubfolderClosed(); 82 } 83 } 84 } else if (folderInfo.isConnected()) { 85 if (folderInfo.notifyNewMessagesNode() && folderInfo.hasNewMessages()) { 86 setIconToOpenWithNew(); 87 } else 88 setIconToOpen(); 89 } else if (folderInfo.isSortaOpen()) { 90 if (folderInfo.notifyNewMessagesNode() && folderInfo.hasNewMessages()) { 91 setIconToDisconnectedWithNew(); 92 } else 93 setIconToDisconnected(); 94 } else if (!folderInfo.isValid()) { 95 setIconToUnavailable(); 96 } else { 97 setIconToClosedFolder(); 98 } 99 } 100 } else if (lastPath instanceof StoreNode) { 101 StoreInfo storeInfo = ((StoreNode)lastPath).getStoreInfo(); 102 if (storeInfo.isConnected()) 103 setIconToConnectedStore(); 104 else 105 setIconToDisconnectedStore(); 106 107 setFontToDefault(); 108 } else { 109 setIconToRoot(); 110 } 111 } else { 112 setIconToDisconnected(); 113 } 114 115 String stringValue = tree.convertValueToText(value, sel, expanded, leaf, row, hasFocus); 116 setText(stringValue); 117 return this; 118 } 119 120 123 public void setIconToUnavailable() { 124 if (getUnavailableIcon() != null) 125 setIcon(getUnavailableIcon()); 126 else { 127 ImageIcon icon = Pooka.getUIFactory().getIconManager().getIcon("FolderTree.Unavailable"); 129 130 if (icon != null) { 131 setUnavailableIcon(icon); 132 setIcon(getUnavailableIcon()); 133 } 134 } 135 } 136 137 140 public void setIconToOpen() { 141 if (getConnectedIcon() != null) 142 setIcon(getConnectedIcon()); 143 else { 144 ImageIcon icon = Pooka.getUIFactory().getIconManager().getIcon("FolderTree.Connected"); 146 147 if (icon != null) { 148 setConnectedIcon(icon); 149 setIcon(getConnectedIcon()); 150 } 151 } 152 } 153 154 157 public void setIconToOpenWithNew() { 158 if (getConnectedWithNewIcon() != null) 159 setIcon(getConnectedWithNewIcon()); 160 else { 161 ImageIcon icon = Pooka.getUIFactory().getIconManager().getIcon("FolderTree.ConnectedNew"); 163 164 if (icon != null) { 165 setConnectedWithNewIcon(icon); 166 setIcon(getConnectedWithNewIcon()); 167 } 168 } 169 } 170 171 174 public void setIconToDisconnected() { 175 if (getDisconnectedIcon() != null) 176 setIcon(getDisconnectedIcon()); 177 else { 178 ImageIcon icon = Pooka.getUIFactory().getIconManager().getIcon("FolderTree.Disconnected"); 180 181 if (icon != null) { 182 setDisconnectedIcon(icon); 183 setIcon(getDisconnectedIcon()); 184 } 185 } 186 } 187 188 191 public void setIconToDisconnectedWithNew() { 192 if (getDisconnectedWithNewIcon() != null) 193 setIcon(getDisconnectedWithNewIcon()); 194 else { 195 ImageIcon icon = Pooka.getUIFactory().getIconManager().getIcon("FolderTree.DisconnectedNew"); 197 198 if (icon != null) { 199 setDisconnectedWithNewIcon(icon); 200 setIcon(getDisconnectedWithNewIcon()); 201 } 202 } 203 } 204 205 public void setIconToClosedFolder() { 206 if (getClosedFolderIcon() != null) 207 setIcon(getClosedFolderIcon()); 208 else { 209 ImageIcon icon = Pooka.getUIFactory().getIconManager().getIcon("FolderTree.Closed"); 211 212 if (icon != null) { 213 setClosedFolderIcon(icon); 214 setIcon(getClosedFolderIcon()); 215 } 216 } 217 } 218 219 public void setIconToDisconnectedStore() { 220 if (getDisconnectedStoreIcon() != null) 221 setIcon(getDisconnectedStoreIcon()); 222 else { 223 ImageIcon icon = Pooka.getUIFactory().getIconManager().getIcon("FolderTree.StoreDisconnected"); 225 226 if (icon != null) { 227 setDisconnectedStoreIcon(icon); 228 setIcon(getDisconnectedStoreIcon()); 229 } 230 } 231 } 232 233 public void setIconToConnectedStore() { 234 if (getConnectedStoreIcon() != null) 235 setIcon(getConnectedStoreIcon()); 236 else { 237 ImageIcon icon = Pooka.getUIFactory().getIconManager().getIcon("FolderTree.StoreConnected"); 239 240 if (icon != null) { 241 setConnectedStoreIcon(icon); 243 setIcon(getConnectedStoreIcon()); 244 } 245 } 246 } 247 248 public void setIconToSubfolderClosed() { 249 if (getSubfolderClosedIcon() != null) 250 setIcon(getSubfolderClosedIcon()); 251 else { 252 ImageIcon icon = Pooka.getUIFactory().getIconManager().getIcon("FolderTree.SubFolderClosed"); 254 255 if (icon != null) { 256 setSubfolderClosedIcon(icon); 257 setIcon(getSubfolderClosedIcon()); 258 } 259 } 260 } 261 262 public void setIconToSubfolder() { 263 if (getSubfolderIcon() != null) 264 setIcon(getSubfolderIcon()); 265 else { 266 ImageIcon icon = Pooka.getUIFactory().getIconManager().getIcon("FolderTree.SubFolder"); 268 269 if (icon != null) { 270 setSubfolderIcon(icon); 271 setIcon(getSubfolderIcon()); 272 } 273 } 274 } 275 276 public void setIconToSubfolderWithNew() { 277 if (getSubfolderWithNewIcon() != null) 278 setIcon(getSubfolderWithNewIcon()); 279 else { 280 ImageIcon icon = Pooka.getUIFactory().getIconManager().getIcon("FolderTree.SubFolderNew"); 282 283 if (icon != null) { 284 setSubfolderWithNewIcon(icon); 285 setIcon(getSubfolderWithNewIcon()); 286 } 287 } 288 } 289 290 public void setIconToRoot() { 291 if (getRootIcon() != null) 292 setIcon(getRootIcon()); 293 else { 294 ImageIcon icon = Pooka.getUIFactory().getIconManager().getIcon("FolderTree.Root"); 296 297 if (icon != null) { 298 setRootIcon(icon); 299 setIcon(getRootIcon()); 300 } 301 } 302 } 303 304 public Icon getConnectedIcon() { 305 return connectedIcon; 306 } 307 308 public void setConnectedIcon(Icon newIcon) { 309 connectedIcon = newIcon; 310 } 311 312 public Icon getConnectedWithNewIcon() { 313 return connectedWithNewIcon; 314 } 315 316 public void setConnectedWithNewIcon(Icon newIcon) { 317 connectedWithNewIcon = newIcon; 318 } 319 320 public void setDisconnectedIcon(Icon newIcon) { 321 disconnectedIcon = newIcon; 322 } 323 324 public Icon getDisconnectedIcon() { 325 return disconnectedIcon; 326 } 327 public Icon getDisconnectedWithNewIcon() { 328 return disconnectedWithNewIcon; 329 } 330 331 public Icon getSubfolderWithNewIcon() { 332 return subfolderWithNewIcon; 333 } 334 335 public void setSubfolderWithNewIcon(Icon newIcon) { 336 subfolderWithNewIcon = newIcon; 337 } 338 339 public void setDisconnectedWithNewIcon(Icon newIcon) { 340 disconnectedWithNewIcon = newIcon; 341 } 342 343 public Icon getClosedFolderIcon() { 344 return closedFolderIcon; 345 } 346 347 public void setClosedFolderIcon(Icon newIcon) { 348 closedFolderIcon = newIcon; 349 } 350 351 public Icon getUnavailableIcon() { 352 return unavailableIcon; 353 } 354 355 public void setUnavailableIcon(Icon newIcon) { 356 unavailableIcon = newIcon; 357 } 358 359 public Icon getConnectedStoreIcon() { 360 return connectedStoreIcon; 361 } 362 363 public void setConnectedStoreIcon(Icon newIcon) { 364 connectedStoreIcon = newIcon; 365 } 366 367 public Icon getDisconnectedStoreIcon() { 368 return disconnectedStoreIcon; 369 } 370 371 public void setDisconnectedStoreIcon(Icon newIcon) { 372 disconnectedStoreIcon = newIcon; 373 } 374 375 public Icon getSubfolderIcon() { 376 return subfolderIcon; 377 } 378 379 public void setSubfolderIcon(Icon newIcon) { 380 subfolderIcon = newIcon; 381 } 382 383 public Icon getSubfolderClosedIcon() { 384 return subfolderClosedIcon; 385 } 386 387 public void setSubfolderClosedIcon(Icon newIcon) { 388 subfolderClosedIcon = newIcon; 389 } 390 391 public Icon getRootIcon() { 392 return rootIcon; 393 } 394 395 public void setRootIcon(Icon newIcon) { 396 rootIcon = newIcon; 397 } 398 } 399 400 401 | Popular Tags |