01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.admin.common;
05:
06: import java.awt.Component;
07:
08: import javax.swing.JTree;
09: import javax.swing.tree.TreeCellRenderer;
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 {
17: protected XTreeCellRenderer m_defaultRenderer;
18:
19: public XTreeCellRendererDelegate() {
20: m_defaultRenderer = new XTreeCellRenderer();
21: }
22:
23: protected TreeCellRenderer getNodeRenderer(Object value) {
24: TreeCellRenderer 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 getTreeCellRendererComponent(JTree tree,
34: Object value, boolean sel, boolean expanded, boolean leaf,
35: int row, boolean focused) {
36: return getNodeRenderer(value).getTreeCellRendererComponent(
37: tree, value, sel, expanded, leaf, row, focused);
38: }
39: }
|