KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > DocumentExpressionEditorTreeCellRenderer


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * DocumentExpressionEditorTreeCellRenderer.java
28  *
29  * Created on 1 giugno 2003, 16.04
30  *
31  */

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 /**
39  *
40  * @author Administrator
41  */

42 public class DocumentExpressionEditorTreeCellRenderer extends DefaultTreeCellRenderer {
43
44     //static ImageIcon fieldIcon;
45
//static ImageIcon variableIcon;
46
//static ImageIcon parameterIcon;
47
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 (fieldIcon == null) fieldIcon = new javax.swing.ImageIcon(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/field.gif"));
59
//if (variableIcon == null) variableIcon = new javax.swing.ImageIcon(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/variable.gif"));
60
//if (parameterIcon == null) parameterIcon = new javax.swing.ImageIcon(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/parameter.gif"));
61
if (folderFieldsIcon == null) folderFieldsIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/fieldsfolder.gif"));
62         if (folderVariablesIcon == null) folderVariablesIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/variablesfolder.gif"));
63         if (folderParametersIcon == null) folderParametersIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/parametersfolder.gif"));
64         if (customFolderIcon == null) customFolderIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/customfolder.gif"));
65
66         if (fieldsIcon == null) fieldsIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/field.png"));
67         if (variablesIcon == null) variablesIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/variable.gif"));
68         if (parametersIcon == null) parametersIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/parameter.gif"));
69         /*
70         this.setOpenIcon(folderOpenedIcon);
71         this.setClosedIcon(folderClosedIcon);
72         this.setLeafIcon(documentIcon);
73          */

74     }
75
76     public Component getTreeCellRendererComponent(
77                         JTree tree,
78                         Object JavaDoc 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 JavaDoc 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