FileDocCategorySizeDatePackage
TreeCellRenderer.javaAPI DocJBoss 4.2.14243Fri Jul 13 21:02:14 BST 2007org.jboss.console.navtree

TreeCellRenderer

public class TreeCellRenderer extends DefaultTreeCellRenderer
Tree cell rendered. Can display another icon if available in the plugin description.
see
org.jboss.console.navtree.AdminTreeBrowser
author
Sacha Labourey.
version
$Revision: 57191 $

Revisions:

20 decembre 2002 Sacha Labourey:

  • First implementation

Fields Summary
protected TreeContext
ctx
protected static HashMap
cache
Constructors Summary
public TreeCellRenderer(TreeContext ctx)

   
      
   
      super();
      this.ctx = ctx;
   
public TreeCellRenderer()

   
Methods Summary
public java.awt.ComponentgetTreeCellRendererComponent(javax.swing.JTree tree, java.lang.Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)


      super.getTreeCellRendererComponent(
                     tree, value, sel,
                     expanded, leaf, row,
                     hasFocus);
      if (value instanceof NodeWrapper)
      {
         NodeWrapper node = (NodeWrapper)value;
         
         String targetUrl = node.getIconUrl ();
         ImageIcon img = (ImageIcon)cache.get( targetUrl );
         
         if (img != null)
         {
            setIcon (img);
         }
         else
         {
            URL target = null;                                    
            
            try { target = new URL(this.ctx.localizeUrl(targetUrl)); } catch (Exception ignored) {}
            
            if (target != null)
            {
               try
               {
                  img = new ImageIcon(target);
                  cache.put (targetUrl, img);
                  setIcon (img);                  
               }
               catch (Exception tobad) {}
            }
         }
         
         
         String desc = node.getDescription ();
         if (desc != null)
         {
            setToolTipText (desc);
         }
      }

      return this;