001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.swing.resourcetree.formresourcetree;
020:
021: import java.awt.Component;
022:
023: import javax.swing.JCheckBox;
024: import javax.swing.JRadioButton;
025: import javax.swing.JTree;
026: import javax.swing.tree.DefaultTreeCellRenderer;
027:
028: import org.openharmonise.him.swing.resourcetree.*;
029:
030: /**
031: * Cell renderer for a {@link org.openharmonise.him.swing.resourcetree.formresourcetree.FormResourceTree}.
032: *
033: * @author Matthew Large
034: * @version $Revision: 1.1 $
035: *
036: */
037: public class FormTreeCellRenderer extends DefaultTreeCellRenderer {
038:
039: /**
040: * Tree this renderer is for.
041: */
042: private FormResourceTree m_tree = null;
043:
044: /**
045: * Constructs a new form tree cell renderer.
046: *
047: * @param tree tree this renderer is for.
048: */
049: public FormTreeCellRenderer(FormResourceTree tree) {
050: super ();
051: this .m_tree = tree;
052: }
053:
054: /* (non-Javadoc)
055: * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean)
056: */
057: public Component getTreeCellRendererComponent(JTree tree,
058: Object value, boolean selected, boolean expanded,
059: boolean leaf, int row, boolean hasFocus) {
060:
061: if (value instanceof TreeNode) {
062: if (((TreeNode) value).isLeaf()) {
063: if (this .m_tree.isMultiSelect()) {
064: FormTreeCell cell = new FormTreeCell(
065: this .m_tree,
066: ((TreeNode) value).getFilePath(),
067: ((TreeNode) value).getDisplayIcon(expanded),
068: ((TreeNode) value).getDisplayName(),
069: new JCheckBox(), true, ((TreeNode) value)
070: .isChildrenPopulated());
071: return cell;
072: } else {
073: FormTreeCell cell = new FormTreeCell(
074: this .m_tree,
075: ((TreeNode) value).getFilePath(),
076: ((TreeNode) value).getDisplayIcon(expanded),
077: ((TreeNode) value).getDisplayName(),
078: new JRadioButton(), true,
079: ((TreeNode) value).isChildrenPopulated());
080: return cell;
081: }
082: } else {
083: if (!this .m_tree.isShowLeafNodes()) {
084: FormTreeCell cell = new FormTreeCell(
085: this .m_tree,
086: ((TreeNode) value).getFilePath(),
087: ((TreeNode) value).getDisplayIcon(expanded),
088: ((TreeNode) value).getDisplayName(),
089: new JCheckBox(), false, ((TreeNode) value)
090: .isChildrenPopulated());
091: return cell;
092: } else {
093: FormTreeCell cell = new FormTreeCell(
094: this .m_tree,
095: ((TreeNode) value).getFilePath(),
096: ((TreeNode) value).getDisplayIcon(expanded),
097: ((TreeNode) value).getDisplayName(), null,
098: false, ((TreeNode) value)
099: .isChildrenPopulated());
100: return cell;
101: }
102: }
103: } else {
104: return super.getTreeCellRendererComponent(tree, value,
105: selected, expanded, leaf, row, hasFocus);
106: }
107: }
108: }
|