KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > admin > common > XTreeCellRendererDelegate


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.admin.common;
5
6 import java.awt.Component JavaDoc;
7
8 import javax.swing.JTree JavaDoc;
9 import javax.swing.tree.TreeCellRenderer JavaDoc;
10
11 /**
12  * This is a TreeCellRenderer that can delegate to either a node-specific
13  * renderer or to the default TreeCellRenderer.
14  */

15
16 public class XTreeCellRendererDelegate implements TreeCellRenderer JavaDoc {
17   protected XTreeCellRenderer m_defaultRenderer;
18   
19   public XTreeCellRendererDelegate() {
20     m_defaultRenderer = new XTreeCellRenderer();
21   }
22   
23   protected TreeCellRenderer JavaDoc getNodeRenderer(Object JavaDoc value) {
24     TreeCellRenderer JavaDoc nodeRenderer = null;
25     
26     if(value instanceof XTreeNode) {
27       nodeRenderer = ((XTreeNode)value).getRenderer();
28     }
29     
30     return nodeRenderer != null ? nodeRenderer : m_defaultRenderer;
31   }
32   
33   public Component JavaDoc getTreeCellRendererComponent(
34     JTree JavaDoc tree,
35     Object JavaDoc value,
36     boolean sel,
37     boolean expanded,
38     boolean leaf,
39     int row,
40     boolean focused)
41   {
42     return
43       getNodeRenderer(value).getTreeCellRendererComponent(
44         tree, value, sel, expanded, leaf, row, focused);
45   }
46 }
47
Popular Tags