01: /*
02: * The contents of this file are subject to the
03: * Mozilla Public License Version 1.1 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
09: * See the License for the specific language governing rights and
10: * limitations under the License.
11: *
12: * The Initial Developer of the Original Code is Simulacra Media Ltd.
13: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14: *
15: * All Rights Reserved.
16: *
17: * Contributor(s):
18: */
19: package org.openharmonise.him.swing.resourcetree;
20:
21: import java.awt.*;
22:
23: import javax.swing.*;
24: import javax.swing.tree.*;
25:
26: import org.openharmonise.swing.FontManager;
27: import org.openharmonise.vfs.gui.*;
28:
29: /**
30: * Renders a resource in a tree.
31: *
32: * @author Matthew Large
33: * @version $Revision: 1.2 $
34: *
35: */
36: public class TreeCellRenderer extends DefaultTreeCellRenderer {
37:
38: /**
39: * The tree.
40: */
41: private ResourceTree m_displayTree = null;
42:
43: /**
44: * Constructs a new tree cell renderer.
45: *
46: */
47: public TreeCellRenderer() {
48: super ();
49: setOpenIcon(IconManager.getInstance().getIcon(
50: "16-section-open.gif"));
51: setClosedIcon(IconManager.getInstance().getIcon(
52: "16-section.gif"));
53: setLeafIcon(IconManager.getInstance()
54: .getIcon("16-document.gif"));
55: }
56:
57: /**
58: * Constructs a new tree cell renderer.
59: *
60: * @param displayTree Tree
61: */
62: public TreeCellRenderer(ResourceTree displayTree) {
63: super ();
64: m_displayTree = displayTree;
65: setOpenIcon(IconManager.getInstance().getIcon(
66: "16-section-open.gif"));
67: setClosedIcon(IconManager.getInstance().getIcon(
68: "16-section.gif"));
69: setLeafIcon(IconManager.getInstance()
70: .getIcon("16-document.gif"));
71: }
72:
73: /* (non-Javadoc)
74: * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean)
75: */
76: public Component getTreeCellRendererComponent(JTree tree,
77: Object value, boolean selected, boolean expanded,
78: boolean leaf, int row, boolean hasFocus) {
79: JLabel rtnLabel = (JLabel) super .getTreeCellRendererComponent(
80: tree, value, selected, expanded, leaf, row, hasFocus);
81:
82: if (value instanceof TreeNode) {
83:
84: rtnLabel.setText(((TreeNode) value).getDisplayName());
85: rtnLabel.setFont(FontManager.getInstance().getFont(
86: FontManager.FONT_RESOURCE_TITLE));
87: rtnLabel.setIcon(((TreeNode) value)
88: .getDisplayIcon(expanded));
89: }
90:
91: return rtnLabel;
92: }
93:
94: }
|