1 22 package org.jboss.console.navtree; 23 24 import java.awt.Component ; 25 import java.net.URL ; 26 import java.util.HashMap ; 27 28 import javax.swing.ImageIcon ; 29 import javax.swing.JTree ; 30 import javax.swing.tree.DefaultTreeCellRenderer ; 31 32 48 49 public class TreeCellRenderer extends DefaultTreeCellRenderer 50 { 51 protected TreeContext ctx = null; 52 protected static HashMap cache = new HashMap (); 53 54 public TreeCellRenderer (TreeContext ctx) 55 { 56 super(); 57 this.ctx = ctx; 58 } 59 60 public Component getTreeCellRendererComponent( 61 JTree tree, 62 Object value, 63 boolean sel, 64 boolean expanded, 65 boolean leaf, 66 int row, 67 boolean hasFocus) { 68 69 super.getTreeCellRendererComponent( 70 tree, value, sel, 71 expanded, leaf, row, 72 hasFocus); 73 if (value instanceof NodeWrapper) 74 { 75 NodeWrapper node = (NodeWrapper)value; 76 77 String targetUrl = node.getIconUrl (); 78 ImageIcon img = (ImageIcon )cache.get( targetUrl ); 79 80 if (img != null) 81 { 82 setIcon (img); 83 } 84 else 85 { 86 URL target = null; 87 88 try { target = new URL (this.ctx.localizeUrl(targetUrl)); } catch (Exception ignored) {} 89 90 if (target != null) 91 { 92 try 93 { 94 img = new ImageIcon (target); 95 cache.put (targetUrl, img); 96 setIcon (img); 97 } 98 catch (Exception tobad) {} 99 } 100 } 101 102 103 String desc = node.getDescription (); 104 if (desc != null) 105 { 106 setToolTipText (desc); 107 } 108 } 109 110 return this; 111 } 112 113 115 117 119 121 public TreeCellRenderer () 122 { 123 } 124 125 127 129 131 133 135 137 139 } 140 | Popular Tags |