1 32 33 package it.businesslogic.ireport.gui; 34 import it.businesslogic.ireport.*; 35 import javax.swing.tree.*; 36 import javax.swing.*; 37 import java.awt.*; 38 42 public class JBTreeCellRenderer extends DefaultTreeCellRenderer { 43 44 static ImageIcon objectIcon; 45 static ImageIcon typeIcon; 46 47 public JBTreeCellRenderer() { 48 super(); 49 if (objectIcon == null) objectIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/javabean/object.png")); 50 if (typeIcon == null) typeIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/javabean/type.png")); 51 52 57 } 58 59 public Component getTreeCellRendererComponent( 60 JTree tree, 61 Object value, 62 boolean sel, 63 boolean expanded, 64 boolean leaf, 65 int row, 66 boolean hasFocus) { 67 68 super.getTreeCellRendererComponent( 69 tree, value, sel, 70 expanded, leaf, row, 71 hasFocus); 72 this.setForeground( Color.BLACK); 73 ImageIcon icon = getElementIcon(value); 74 setIcon(icon); 75 76 setToolTipText(null); 77 78 return this; 79 } 80 81 protected ImageIcon getElementIcon(Object value) { 82 DefaultMutableTreeNode node = 83 (DefaultMutableTreeNode)value; 84 this.setForeground( Color.BLACK); 85 86 if (node.getUserObject() != null && 87 node.getUserObject() instanceof TreeJRField ) 88 { 89 TreeJRField tf = (TreeJRField)node.getUserObject(); 90 if (tf.getObj() == null || tf.getObj().getName().startsWith("java.lang") || tf.getObj().isPrimitive()) 91 { 92 return typeIcon; 93 } 94 } 95 96 return objectIcon; 97 } 98 } 99 100 | Popular Tags |