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: * LibraryTreeCellRenderer.java
028: *
029: * Created on 1 giugno 2003, 16.04
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.library;
034:
035: import it.businesslogic.ireport.*;
036: import it.businesslogic.ireport.crosstab.CrosstabGroup;
037: import it.businesslogic.ireport.crosstab.CrosstabParameter;
038: import it.businesslogic.ireport.crosstab.GroupTotal;
039: import it.businesslogic.ireport.crosstab.Measure;
040: import javax.swing.tree.*;
041: import javax.swing.*;
042: import java.awt.*;
043:
044: /**
045: *
046: * @author Administrator
047: */
048: public class LibraryTreeCellRenderer extends DefaultTreeCellRenderer {
049:
050: static ImageIcon objectIcon;
051: static ImageIcon typeIcon;
052:
053: static ImageIcon folderClosedIcon;
054: static ImageIcon folderOpenedIcon;
055:
056: static ImageIcon folderFieldsIcon;
057: static ImageIcon folderVariablesIcon;
058: static ImageIcon folderParametersIcon;
059:
060: static ImageIcon fieldsIcon;
061: static ImageIcon variablesIcon;
062: static ImageIcon parametersIcon;
063: static ImageIcon expressionIcon;
064: static ImageIcon grouptotalIcon;
065:
066: static ImageIcon datasetIcon;
067:
068: public LibraryTreeCellRenderer() {
069: super ();
070: if (objectIcon == null)
071: objectIcon = new javax.swing.ImageIcon(
072: getClass()
073: .getResource(
074: "/it/businesslogic/ireport/icons/tree/javabean/object.png"));
075: if (typeIcon == null)
076: typeIcon = new javax.swing.ImageIcon(
077: getClass()
078: .getResource(
079: "/it/businesslogic/ireport/icons/tree/javabean/type.png"));
080: if (folderClosedIcon == null)
081: folderClosedIcon = new javax.swing.ImageIcon(
082: getClass()
083: .getResource(
084: "/it/businesslogic/ireport/icons/tree/folderClosed.gif"));
085: if (folderOpenedIcon == null)
086: folderOpenedIcon = new javax.swing.ImageIcon(
087: getClass()
088: .getResource(
089: "/it/businesslogic/ireport/icons/tree/folderOpened.gif"));
090:
091: if (expressionIcon == null)
092: expressionIcon = new javax.swing.ImageIcon(
093: getClass()
094: .getResource(
095: "/it/businesslogic/ireport/icons/tree/elements/exp.png"));
096:
097: if (folderFieldsIcon == null)
098: folderFieldsIcon = new javax.swing.ImageIcon(
099: getClass()
100: .getResource(
101: "/it/businesslogic/ireport/icons/tree/editor/fieldsfolder.gif"));
102: if (folderVariablesIcon == null)
103: folderVariablesIcon = new javax.swing.ImageIcon(
104: getClass()
105: .getResource(
106: "/it/businesslogic/ireport/icons/tree/editor/variablesfolder.gif"));
107: if (folderParametersIcon == null)
108: folderParametersIcon = new javax.swing.ImageIcon(
109: getClass()
110: .getResource(
111: "/it/businesslogic/ireport/icons/tree/editor/parametersfolder.gif"));
112:
113: if (fieldsIcon == null)
114: fieldsIcon = new javax.swing.ImageIcon(
115: getClass()
116: .getResource(
117: "/it/businesslogic/ireport/icons/tree/editor/field.png"));
118: if (variablesIcon == null)
119: variablesIcon = new javax.swing.ImageIcon(
120: getClass()
121: .getResource(
122: "/it/businesslogic/ireport/icons/tree/editor/variable.png"));
123: if (parametersIcon == null)
124: parametersIcon = new javax.swing.ImageIcon(
125: getClass()
126: .getResource(
127: "/it/businesslogic/ireport/icons/tree/editor/parameter.png"));
128: if (datasetIcon == null)
129: datasetIcon = new javax.swing.ImageIcon(
130: getClass()
131: .getResource(
132: "/it/businesslogic/ireport/icons/library/datasource.png"));
133: if (grouptotalIcon == null)
134: grouptotalIcon = new javax.swing.ImageIcon(
135: getClass()
136: .getResource(
137: "/it/businesslogic/ireport/icons/tree/editor/grouptotal.png"));
138: /*
139: this.setOpenIcon(folderOpenedIcon);
140: this.setClosedIcon(folderClosedIcon);
141: this.setLeafIcon(documentIcon);
142: */
143: }
144:
145: public Component getTreeCellRendererComponent(JTree tree,
146: Object value, boolean sel, boolean expanded, boolean leaf,
147: int row, boolean hasFocus) {
148:
149: super .getTreeCellRendererComponent(tree, value, sel, expanded,
150: leaf, row, hasFocus);
151: this .setForeground(Color.BLACK);
152: ImageIcon icon = getElementIcon(value);
153: if (icon != null)
154: setIcon(icon);
155: else {
156: if (expanded) {
157: setIcon(folderOpenedIcon);
158: setToolTipText(null); //no tool tip
159: } else {
160: setIcon(folderClosedIcon);
161: setToolTipText(null); //no tool tip
162: }
163: }
164:
165: setToolTipText(null);
166:
167: return this ;
168: }
169:
170: protected ImageIcon getElementIcon(Object value) {
171: DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
172: this .setForeground(Color.BLACK);
173:
174: if (node.getUserObject() != null
175: && node.getUserObject() instanceof AbstractLibraryObject) {
176: return ((AbstractLibraryObject) node.getUserObject())
177: .getIcon();
178: }
179:
180: if (node.getUserObject() != null
181: && (node.getUserObject() instanceof GroupTotal))
182: return grouptotalIcon;
183: if (node.getUserObject() != null
184: && (node.getUserObject() instanceof JRField || node
185: .getUserObject() instanceof CrosstabGroup))
186: return fieldsIcon;
187: if (node.getUserObject() != null
188: && (node.getUserObject() instanceof JRVariable || node
189: .getUserObject() instanceof Measure))
190: return variablesIcon;
191: if (node.getUserObject() != null
192: && (node.getUserObject() instanceof JRParameter || node
193: .getUserObject() instanceof CrosstabParameter))
194: return parametersIcon;
195: if (node.getUserObject() != null
196: && node.getUserObject() instanceof CustomExpression)
197: return expressionIcon;
198:
199: if (node.getUserObject().toString().equals(
200: it.businesslogic.ireport.util.I18n.getString(
201: "gui.library.fields", "Fields")))
202: return folderFieldsIcon;
203: if (node.getUserObject().toString().equals(
204: it.businesslogic.ireport.util.I18n.getString(
205: "gui.library.variables", "Variables")))
206: return folderVariablesIcon;
207: if (node.getUserObject().toString().equals(
208: it.businesslogic.ireport.util.I18n.getString(
209: "gui.library.parameters", "Parameters")))
210: return folderParametersIcon;
211:
212: if (node.getUserObject() != null
213: && node.getUserObject() instanceof SubDataset)
214: return datasetIcon;
215:
216: return null;
217:
218: //return objectIcon;
219: }
220:
221: }
|