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.Component;
044: import javax.swing.Icon;
045: import javax.swing.ImageIcon;
046: import javax.swing.JTree;
047: import javax.swing.tree.DefaultMutableTreeNode;
048: import javax.swing.tree.DefaultTreeCellRenderer;
049:
050: /**
051: * @author eric
052: *
053: * TODO To change the template for this generated type comment go to
054: * Window - Preferences - Java - Code Generation - Code and Comments
055: */
056: public class ChooseManyOfManyNodeDataTreeCellRenderer extends
057: DefaultTreeCellRenderer {
058: protected static Icon FOLDER_OPEN_ICON = new ImageIcon(
059: ChooseManyOfManyNodeDataTreeCellRenderer.class
060: .getResource("folder-open.gif")); //NOI18N
061: protected static Icon FOLDER_CLOSED_ICON = new ImageIcon(
062: ChooseManyOfManyNodeDataTreeCellRenderer.class
063: .getResource("folder-closed.gif")); //NOI18N
064:
065: protected String listNodePrefix;
066:
067: public ChooseManyOfManyNodeDataTreeCellRenderer(
068: String listNodePrefix) {
069:
070: super ();
071: this .listNodePrefix = listNodePrefix;
072: setOpenIcon(FOLDER_OPEN_ICON);
073: setClosedIcon(FOLDER_CLOSED_ICON);
074: }
075:
076: public Component getTreeCellRendererComponent(JTree tree,
077: Object value, boolean sel, boolean expanded, boolean leaf,
078: int row, boolean hasFocus) {
079: DefaultMutableTreeNode node;
080:
081: super .getTreeCellRendererComponent(tree, value, sel, expanded,
082: leaf, row, hasFocus);
083: if (value == null) {
084: return this ;
085: }
086: node = (DefaultMutableTreeNode) value;
087: String text;
088: if (node.getParent() == null) {
089: // dealing with root node which never shows up
090: text = "Root"; // NOI18N
091: } else if (node.getParent().getParent() == null) {
092: // dealing with child of root
093: text = listNodePrefix
094: + (node.getParent().getIndex(node) + 1);
095: setIcon(expanded ? getOpenIcon() : getClosedIcon());
096: // If I want to look at using the same ones as in Project Navigator
097: // Not doing it since I dont want to deal with different color depth issues
098: // org.openide.util.Utilities.loadImage ("org/openide/loaders/defaultFolder.gif")
099: } else {
100: // dealing with any other node
101: ChooseManyOfManyNodeData data = (ChooseManyOfManyNodeData) node
102: .getUserObject();
103: text = data.getLabel();
104: setIcon(null);
105: }
106: setText(text);
107: return this;
108: }
109:
110: }
|