001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * JBTreeCellRenderer.java
028: *
029: * Created on 1 giugno 2003, 16.04
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: import it.businesslogic.ireport.*;
036: import javax.swing.tree.*;
037: import javax.swing.*;
038: import java.awt.*;
039:
040: /**
041: *
042: * @author Administrator
043: */
044: public class JBTreeCellRenderer extends DefaultTreeCellRenderer {
045:
046: static ImageIcon objectIcon;
047: static ImageIcon typeIcon;
048:
049: public JBTreeCellRenderer() {
050: super ();
051: if (objectIcon == null)
052: objectIcon = new javax.swing.ImageIcon(
053: getClass()
054: .getResource(
055: "/it/businesslogic/ireport/icons/tree/javabean/object.png"));
056: if (typeIcon == null)
057: typeIcon = new javax.swing.ImageIcon(
058: getClass()
059: .getResource(
060: "/it/businesslogic/ireport/icons/tree/javabean/type.png"));
061:
062: /*
063: this.setOpenIcon(folderOpenedIcon);
064: this.setClosedIcon(folderClosedIcon);
065: this.setLeafIcon(documentIcon);
066: */
067: }
068:
069: public Component getTreeCellRendererComponent(JTree tree,
070: Object value, boolean sel, boolean expanded, boolean leaf,
071: int row, boolean hasFocus) {
072:
073: super .getTreeCellRendererComponent(tree, value, sel, expanded,
074: leaf, row, hasFocus);
075: this .setForeground(Color.BLACK);
076: ImageIcon icon = getElementIcon(value);
077: setIcon(icon);
078:
079: setToolTipText(null);
080:
081: return this ;
082: }
083:
084: protected ImageIcon getElementIcon(Object value) {
085: DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
086: this .setForeground(Color.BLACK);
087:
088: if (node.getUserObject() != null
089: && node.getUserObject() instanceof TreeJRField) {
090: TreeJRField tf = (TreeJRField) node.getUserObject();
091: if (tf.getObj() == null
092: || tf.getObj().getName().startsWith("java.lang")
093: || tf.getObj().isPrimitive()) {
094: return typeIcon;
095: }
096: }
097:
098: return objectIcon;
099: }
100: }
|