KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > library > LibraryTreeCellRenderer


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  * LibraryTreeCellRenderer.java
28  *
29  * Created on 1 giugno 2003, 16.04
30  *
31  */

32
33 package it.businesslogic.ireport.gui.library;
34 import it.businesslogic.ireport.*;
35 import it.businesslogic.ireport.crosstab.CrosstabGroup;
36 import it.businesslogic.ireport.crosstab.CrosstabParameter;
37 import it.businesslogic.ireport.crosstab.GroupTotal;
38 import it.businesslogic.ireport.crosstab.Measure;
39 import javax.swing.tree.*;
40 import javax.swing.*;
41 import java.awt.*;
42 /**
43  *
44  * @author Administrator
45  */

46 public class LibraryTreeCellRenderer extends DefaultTreeCellRenderer {
47
48     static ImageIcon objectIcon;
49     static ImageIcon typeIcon;
50     
51     static ImageIcon folderClosedIcon;
52     static ImageIcon folderOpenedIcon;
53     
54     static ImageIcon folderFieldsIcon;
55     static ImageIcon folderVariablesIcon;
56     static ImageIcon folderParametersIcon;
57     
58     static ImageIcon fieldsIcon;
59     static ImageIcon variablesIcon;
60     static ImageIcon parametersIcon;
61     static ImageIcon expressionIcon;
62     static ImageIcon grouptotalIcon;
63     
64     static ImageIcon datasetIcon;
65     
66     public LibraryTreeCellRenderer() {
67         super();
68         if (objectIcon == null) objectIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/javabean/object.png"));
69         if (typeIcon == null) typeIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/javabean/type.png"));
70        if (folderClosedIcon == null)
71             folderClosedIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/folderClosed.gif"));
72         if (folderOpenedIcon == null)
73             folderOpenedIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/folderOpened.gif"));
74         
75         if (expressionIcon == null)
76             expressionIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/exp.png"));
77         
78         
79         if (folderFieldsIcon == null) folderFieldsIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/fieldsfolder.gif"));
80         if (folderVariablesIcon == null) folderVariablesIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/variablesfolder.gif"));
81         if (folderParametersIcon == null) folderParametersIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/parametersfolder.gif"));
82        
83         if (fieldsIcon == null) fieldsIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/field.png"));
84         if (variablesIcon == null) variablesIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/variable.png"));
85         if (parametersIcon == null) parametersIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/parameter.png"));
86         if (datasetIcon == null) datasetIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/library/datasource.png"));
87         if (grouptotalIcon == null) grouptotalIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/grouptotal.png"));
88         /*
89         this.setOpenIcon(folderOpenedIcon);
90         this.setClosedIcon(folderClosedIcon);
91         this.setLeafIcon(documentIcon);
92          */

93     }
94
95     public Component getTreeCellRendererComponent(
96                         JTree tree,
97                         Object JavaDoc value,
98                         boolean sel,
99                         boolean expanded,
100                         boolean leaf,
101                         int row,
102                         boolean hasFocus) {
103
104         super.getTreeCellRendererComponent(
105                         tree, value, sel,
106                         expanded, leaf, row,
107                         hasFocus);
108             this.setForeground( Color.BLACK);
109             ImageIcon icon = getElementIcon(value);
110             if (icon != null) setIcon(icon);
111             else
112             {
113                 if ( expanded)
114                 {
115                      setIcon(folderOpenedIcon);
116                      setToolTipText(null); //no tool tip
117
}
118                 else
119                 {
120                      setIcon(folderClosedIcon);
121                      setToolTipText(null); //no tool tip
122
}
123             }
124
125             setToolTipText(null);
126
127         return this;
128     }
129
130     protected ImageIcon getElementIcon(Object JavaDoc value) {
131         DefaultMutableTreeNode node =
132                 (DefaultMutableTreeNode)value;
133         this.setForeground( Color.BLACK);
134            
135         if (node.getUserObject() != null && node.getUserObject() instanceof AbstractLibraryObject )
136         {
137             return ((AbstractLibraryObject)node.getUserObject()).getIcon();
138         }
139         
140         if (node.getUserObject() != null && (node.getUserObject() instanceof GroupTotal)) return grouptotalIcon;
141         if (node.getUserObject() != null && (node.getUserObject() instanceof JRField || node.getUserObject() instanceof CrosstabGroup)) return fieldsIcon;
142         if (node.getUserObject() != null && (node.getUserObject() instanceof JRVariable || node.getUserObject() instanceof Measure)) return variablesIcon;
143         if (node.getUserObject() != null && (node.getUserObject() instanceof JRParameter || node.getUserObject() instanceof CrosstabParameter)) return parametersIcon;
144         if (node.getUserObject() != null && node.getUserObject() instanceof CustomExpression) return expressionIcon;
145         
146         if (node.getUserObject().toString().equals(it.businesslogic.ireport.util.I18n.getString("gui.library.fields","Fields"))) return folderFieldsIcon;
147         if (node.getUserObject().toString().equals(it.businesslogic.ireport.util.I18n.getString("gui.library.variables","Variables"))) return folderVariablesIcon;
148         if (node.getUserObject().toString().equals(it.businesslogic.ireport.util.I18n.getString("gui.library.parameters","Parameters"))) return folderParametersIcon;
149         
150         if (node.getUserObject() != null && node.getUserObject() instanceof SubDataset) return datasetIcon;
151         
152         return null;
153         
154        
155         //return objectIcon;
156
}
157     
158     
159 }
160
161
Popular Tags