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 DocumentExpressionEditorTreeCellRenderer extends DefaultTreeCellRenderer { 43 44 static ImageIcon folderFieldsIcon; 48 static ImageIcon folderVariablesIcon; 49 static ImageIcon folderParametersIcon; 50 static ImageIcon customFolderIcon; 51 52 static ImageIcon fieldsIcon; 53 static ImageIcon variablesIcon; 54 static ImageIcon parametersIcon; 55 56 public DocumentExpressionEditorTreeCellRenderer() { 57 super(); 58 if (folderFieldsIcon == null) folderFieldsIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/fieldsfolder.gif")); 62 if (folderVariablesIcon == null) folderVariablesIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/variablesfolder.gif")); 63 if (folderParametersIcon == null) folderParametersIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/parametersfolder.gif")); 64 if (customFolderIcon == null) customFolderIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/customfolder.gif")); 65 66 if (fieldsIcon == null) fieldsIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/field.png")); 67 if (variablesIcon == null) variablesIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/variable.gif")); 68 if (parametersIcon == null) parametersIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/parameter.gif")); 69 74 } 75 76 public Component getTreeCellRendererComponent( 77 JTree tree, 78 Object value, 79 boolean sel, 80 boolean expanded, 81 boolean leaf, 82 int row, 83 boolean hasFocus) { 84 85 super.getTreeCellRendererComponent( 86 tree, value, sel, 87 expanded, leaf, row, 88 hasFocus); 89 this.setForeground( Color.BLACK); 90 ImageIcon icon = getElementIcon(value); 91 setIcon(icon); 92 93 setToolTipText(null); 94 95 return this; 96 } 97 98 protected ImageIcon getElementIcon(Object value) { 99 100 if (!(value instanceof DefaultMutableTreeNode)) return customFolderIcon; 101 DefaultMutableTreeNode node = 102 (DefaultMutableTreeNode)value; 103 this.setForeground( Color.BLACK); 104 105 if (node.getUserObject() instanceof IconedString) 106 { 107 IconedString iconedString = (IconedString)node.getUserObject(); 108 setText( iconedString.getStr() ); 109 return iconedString.getIcon(); 110 } 111 112 if (node.getUserObject().toString().equalsIgnoreCase("Variables")) return folderVariablesIcon; 113 if (node.getUserObject().toString().equalsIgnoreCase("Fields")) return folderFieldsIcon; 114 if (node.getUserObject().toString().equalsIgnoreCase("Parameters")) return folderParametersIcon; 115 116 if (node.getParent() != null && node.getParent() instanceof DefaultMutableTreeNode) 117 { 118 DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)node.getParent(); 119 if (parentNode.getUserObject().toString().equalsIgnoreCase("Variables")) return variablesIcon; 120 if (parentNode.getUserObject().toString().equalsIgnoreCase("Fields")) return fieldsIcon; 121 if (parentNode.getUserObject().toString().equalsIgnoreCase("Parameters")) return parametersIcon; 122 } 123 return customFolderIcon; 124 } 125 } 126 127 | Popular Tags |