001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.jsfcl.std.property;
042:
043: import java.awt.Color;
044: import java.awt.Component;
045: import javax.swing.Icon;
046: import javax.swing.ImageIcon;
047: import javax.swing.JTree;
048: import javax.swing.UIManager;
049: import javax.swing.tree.DefaultMutableTreeNode;
050: import javax.swing.tree.TreeCellRenderer;
051: import com.sun.jsfcl.std.reference.ReferenceDataItem;
052:
053: /**
054: * @author eric
055: *
056: * TODO To change the template for this generated type comment go to
057: * Window - Preferences - Java - Code Generation - Code and Comments
058: */
059: public class ChooseManyOfManyNodeDataTwoColumnTreeCellRenderer extends
060: ReferenceDataTwoColumnListCellRenderer implements
061: TreeCellRenderer {
062: protected static Icon FOLDER_OPEN_ICON = new ImageIcon(
063: ChooseManyOfManyNodeDataTwoColumnTreeCellRenderer.class
064: .getResource("folder-open.gif")); //NOI18N
065: protected static Icon FOLDER_CLOSED_ICON = new ImageIcon(
066: ChooseManyOfManyNodeDataTwoColumnTreeCellRenderer.class
067: .getResource("folder-closed.gif")); //NOI18N
068:
069: protected String listNodePrefix;
070: Color textSelectionColor;
071: Color textNonSelectionColor;
072: Color backgroundSelectionColor;
073: Color backgroundNonSelectionColor;
074: Color borderSelectionColor;
075: boolean drawsFocusBorderAroundIcon;
076:
077: public ChooseManyOfManyNodeDataTwoColumnTreeCellRenderer(
078: String listNodePrefix) {
079:
080: super ();
081: this .listNodePrefix = listNodePrefix;
082: textSelectionColor = UIManager
083: .getColor("Tree.selectionForeground");
084: textNonSelectionColor = UIManager
085: .getColor("Tree.textForeground");
086: backgroundSelectionColor = UIManager
087: .getColor("Tree.selectionBackground");
088: backgroundNonSelectionColor = UIManager
089: .getColor("Tree.textBackground");
090: borderSelectionColor = UIManager
091: .getColor("Tree.selectionBorderColor");
092: Object value = UIManager.get("Tree.drawsFocusBorderAroundIcon");
093: drawsFocusBorderAroundIcon = (value != null && ((Boolean) value)
094: .booleanValue());
095: }
096:
097: public Component getTreeCellRendererComponent(JTree tree,
098: Object value, boolean sel, boolean expanded, boolean leaf,
099: int row, boolean hasFocus) {
100: DefaultMutableTreeNode node;
101:
102: if (sel) {
103: setForeground(textSelectionColor);
104: leftLabel.setForeground(textSelectionColor);
105: rightLabel.setForeground(textSelectionColor);
106: setBackground(backgroundSelectionColor);
107: leftLabel.setBackground(backgroundSelectionColor);
108: rightLabel.setBackground(backgroundSelectionColor);
109: } else {
110: setForeground(textNonSelectionColor);
111: leftLabel.setForeground(textNonSelectionColor);
112: rightLabel.setForeground(textNonSelectionColor);
113: setBackground(backgroundNonSelectionColor);
114: leftLabel.setBackground(backgroundNonSelectionColor);
115: rightLabel.setBackground(backgroundNonSelectionColor);
116: }
117: setComponentOrientation(tree.getComponentOrientation());
118: node = (DefaultMutableTreeNode) value;
119: String[] labels;
120: if (node.getParent() == null) {
121: // dealing with root node which never shows up
122: labels = new String[] { "Root", "" }; // NOI18N
123: leftLabel.setIcon(expanded ? FOLDER_OPEN_ICON
124: : FOLDER_CLOSED_ICON);
125: wantsSecondLabel = false;
126: } else if (node.getParent().getParent() == null) {
127: // dealing with child of root
128: labels = new String[] {
129: listNodePrefix
130: + (node.getParent().getIndex(node) + 1), "" };
131: leftLabel.setIcon(expanded ? FOLDER_OPEN_ICON
132: : FOLDER_CLOSED_ICON);
133: wantsSecondLabel = false;
134: } else {
135: // dealing with any other node
136: ChooseManyOfManyNodeData data = (ChooseManyOfManyNodeData) node
137: .getUserObject();
138: ReferenceDataItem item = (ReferenceDataItem) data.getData();
139: labels = getLabels(item);
140: leftLabel.setIcon(null);
141: wantsSecondLabel = true;
142: }
143: leftLabel.setText(labels[0]);
144: rightLabel.setText(labels[1]);
145: invalidate();
146: return this;
147: }
148:
149: }
|