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: * DocumentStructureTreeCellRenderer.java
028: *
029: * Created on 1 giugno 2003, 16.04
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.documentstructure;
034:
035: import it.businesslogic.ireport.*;
036: import it.businesslogic.ireport.crosstab.CrosstabCell;
037: import it.businesslogic.ireport.crosstab.CrosstabGroup;
038: import it.businesslogic.ireport.crosstab.CrosstabParameter;
039: import it.businesslogic.ireport.crosstab.Measure;
040: import it.businesslogic.ireport.gui.library.CustomExpression;
041: import javax.swing.tree.*;
042: import javax.swing.*;
043: import java.awt.*;
044:
045: /**
046: *
047: * @author Administrator
048: */
049: public class DocumentStructureTreeCellRenderer extends
050: DefaultTreeCellRenderer {
051:
052: static ImageIcon docIcon;
053: static ImageIcon bandIcon;
054:
055: static ImageIcon groupHeaderIcon;
056: static ImageIcon groupFooterIcon;
057:
058: static ImageIcon textfieldIcon;
059: static ImageIcon statictextIcon;
060: static ImageIcon imageIcon;
061: static ImageIcon ellipseIcon;
062: static ImageIcon rectangleIcon;
063: static ImageIcon subreportIcon;
064: static ImageIcon lineIcon;
065: static ImageIcon chartIcon;
066: static ImageIcon elementGroupIcon;
067: static ImageIcon frameIcon;
068: static ImageIcon crosstabIcon;
069: static ImageIcon cellIcon;
070: static ImageIcon crosstabrootIcon;
071: static ImageIcon breakIcon;
072:
073: static ImageIcon fieldsIcon;
074: static ImageIcon variablesIcon;
075: static ImageIcon parametersIcon;
076: static ImageIcon builtinParametersIcon;
077: static ImageIcon builtinVariablesIcon;
078: static ImageIcon folderFieldsIcon;
079: static ImageIcon folderVariablesIcon;
080: static ImageIcon folderParametersIcon;
081: static ImageIcon datasetIcon;
082:
083: static ImageIcon objectIcon;
084: static ImageIcon typeIcon;
085:
086: static ImageIcon folderClosedIcon;
087: static ImageIcon folderOpenedIcon;
088:
089: static ImageIcon expressionIcon;
090:
091: public DocumentStructureTreeCellRenderer() {
092: super ();
093: if (docIcon == null)
094: docIcon = new javax.swing.ImageIcon(
095: getClass()
096: .getResource(
097: "/it/businesslogic/ireport/icons/tree/elements/doc.gif"));
098: if (bandIcon == null)
099: bandIcon = new javax.swing.ImageIcon(
100: getClass()
101: .getResource(
102: "/it/businesslogic/ireport/icons/tree/editor/band.png"));
103: if (textfieldIcon == null)
104: textfieldIcon = new javax.swing.ImageIcon(
105: getClass()
106: .getResource(
107: "/it/businesslogic/ireport/icons/tree/elements/textfield.gif"));
108: if (statictextIcon == null)
109: statictextIcon = new javax.swing.ImageIcon(
110: getClass()
111: .getResource(
112: "/it/businesslogic/ireport/icons/tree/elements/static.gif"));
113: if (imageIcon == null)
114: imageIcon = new javax.swing.ImageIcon(
115: getClass()
116: .getResource(
117: "/it/businesslogic/ireport/icons/tree/elements/image.gif"));
118: if (ellipseIcon == null)
119: ellipseIcon = new javax.swing.ImageIcon(
120: getClass()
121: .getResource(
122: "/it/businesslogic/ireport/icons/tree/elements/ellipse.png"));
123: if (rectangleIcon == null)
124: rectangleIcon = new javax.swing.ImageIcon(
125: getClass()
126: .getResource(
127: "/it/businesslogic/ireport/icons/tree/elements/rectangle.gif"));
128: if (subreportIcon == null)
129: subreportIcon = new javax.swing.ImageIcon(
130: getClass()
131: .getResource(
132: "/it/businesslogic/ireport/icons/tree/elements/subreport.gif"));
133: if (lineIcon == null)
134: lineIcon = new javax.swing.ImageIcon(
135: getClass()
136: .getResource(
137: "/it/businesslogic/ireport/icons/tree/elements/line.gif"));
138: if (chartIcon == null)
139: chartIcon = new javax.swing.ImageIcon(
140: getClass()
141: .getResource(
142: "/it/businesslogic/ireport/icons/tree/elements/chart.gif"));
143: if (elementGroupIcon == null)
144: elementGroupIcon = new javax.swing.ImageIcon(
145: getClass()
146: .getResource(
147: "/it/businesslogic/ireport/icons/tree/elements/elementgroup.png"));
148: if (frameIcon == null)
149: frameIcon = new javax.swing.ImageIcon(
150: getClass()
151: .getResource(
152: "/it/businesslogic/ireport/icons/tree/elements/frame.png"));
153: if (crosstabIcon == null)
154: crosstabIcon = new javax.swing.ImageIcon(
155: getClass()
156: .getResource(
157: "/it/businesslogic/ireport/icons/tree/elements/crosstab.png"));
158: if (cellIcon == null)
159: cellIcon = new javax.swing.ImageIcon(
160: getClass()
161: .getResource(
162: "/it/businesslogic/ireport/icons/tree/elements/cell.png"));
163: if (crosstabrootIcon == null)
164: crosstabrootIcon = new javax.swing.ImageIcon(
165: getClass()
166: .getResource(
167: "/it/businesslogic/ireport/icons/tree/elements/crosstabroot.png"));
168: if (breakIcon == null)
169: breakIcon = new javax.swing.ImageIcon(
170: getClass()
171: .getResource(
172: "/it/businesslogic/ireport/icons/tree/elements/break.png"));
173:
174: if (folderFieldsIcon == null)
175: folderFieldsIcon = new javax.swing.ImageIcon(
176: getClass()
177: .getResource(
178: "/it/businesslogic/ireport/icons/tree/editor/fieldsfolder.png"));
179: if (folderVariablesIcon == null)
180: folderVariablesIcon = new javax.swing.ImageIcon(
181: getClass()
182: .getResource(
183: "/it/businesslogic/ireport/icons/tree/editor/variablesfolder.png"));
184: if (folderParametersIcon == null)
185: folderParametersIcon = new javax.swing.ImageIcon(
186: getClass()
187: .getResource(
188: "/it/businesslogic/ireport/icons/tree/editor/parametersfolder.png"));
189:
190: if (fieldsIcon == null)
191: fieldsIcon = new javax.swing.ImageIcon(
192: getClass()
193: .getResource(
194: "/it/businesslogic/ireport/icons/tree/editor/field.png"));
195: if (variablesIcon == null)
196: variablesIcon = new javax.swing.ImageIcon(
197: getClass()
198: .getResource(
199: "/it/businesslogic/ireport/icons/tree/editor/variable.png"));
200: if (parametersIcon == null)
201: parametersIcon = new javax.swing.ImageIcon(
202: getClass()
203: .getResource(
204: "/it/businesslogic/ireport/icons/tree/editor/parameter.png"));
205: if (datasetIcon == null)
206: datasetIcon = new javax.swing.ImageIcon(
207: getClass()
208: .getResource(
209: "/it/businesslogic/ireport/icons/library/datasource.png"));
210:
211: if (builtinParametersIcon == null)
212: builtinParametersIcon = new javax.swing.ImageIcon(
213: getClass()
214: .getResource(
215: "/it/businesslogic/ireport/icons/tree/editor/builtin_parameter.png"));
216: if (builtinVariablesIcon == null)
217: builtinVariablesIcon = new javax.swing.ImageIcon(
218: getClass()
219: .getResource(
220: "/it/businesslogic/ireport/icons/tree/editor/builtin_variable.png"));
221:
222: if (groupHeaderIcon == null)
223: groupHeaderIcon = new javax.swing.ImageIcon(
224: getClass()
225: .getResource(
226: "/it/businesslogic/ireport/icons/tree/editor/group_header.png"));
227: if (groupFooterIcon == null)
228: groupFooterIcon = new javax.swing.ImageIcon(
229: getClass()
230: .getResource(
231: "/it/businesslogic/ireport/icons/tree/editor/group_footer.png"));
232:
233: if (objectIcon == null)
234: objectIcon = new javax.swing.ImageIcon(
235: getClass()
236: .getResource(
237: "/it/businesslogic/ireport/icons/tree/javabean/object.png"));
238: if (typeIcon == null)
239: typeIcon = new javax.swing.ImageIcon(
240: getClass()
241: .getResource(
242: "/it/businesslogic/ireport/icons/tree/javabean/type.png"));
243: if (folderClosedIcon == null)
244: folderClosedIcon = new javax.swing.ImageIcon(
245: getClass()
246: .getResource(
247: "/it/businesslogic/ireport/icons/tree/folderClosed.gif"));
248: if (folderOpenedIcon == null)
249: folderOpenedIcon = new javax.swing.ImageIcon(
250: getClass()
251: .getResource(
252: "/it/businesslogic/ireport/icons/tree/folderOpened.gif"));
253:
254: if (expressionIcon == null)
255: expressionIcon = new javax.swing.ImageIcon(
256: getClass()
257: .getResource(
258: "/it/businesslogic/ireport/icons/tree/elements/exp.png"));
259:
260: /*
261: this.setOpenIcon(folderOpenedIcon);
262: this.setClosedIcon(folderClosedIcon);
263: this.setLeafIcon(documentIcon);
264: */
265: }
266:
267: public Component getTreeCellRendererComponent(JTree tree,
268: Object value, boolean sel, boolean expanded, boolean leaf,
269: int row, boolean hasFocus) {
270:
271: super .getTreeCellRendererComponent(tree, value, sel, expanded,
272: leaf, row, hasFocus);
273: this .setForeground(Color.BLACK);
274: ImageIcon icon = getElementIcon(value);
275: if (icon != null)
276: setIcon(icon);
277: else {
278: if (expanded) {
279: setIcon(folderOpenedIcon);
280: setToolTipText(null); //no tool tip
281: } else {
282: setIcon(folderClosedIcon);
283: setToolTipText(null); //no tool tip
284: }
285: }
286: setToolTipText(null);
287:
288: //if (value != null && value instanceof ReportObjectTreeNode)
289: //{
290: // setText(getText() + " (" + ((ReportObjectTreeNode)value).getNodeId() + ")");
291: //}
292:
293: return this ;
294: }
295:
296: protected ImageIcon getElementIcon(Object value) {
297: DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
298: this .setForeground(Color.BLACK);
299:
300: if (node.getUserObject() instanceof ReportElement
301: && !((ReportElement) node.getUserObject())
302: .insideBandReal())
303: this .setForeground(Color.RED);
304:
305: if ((node.getUserObject() + "").equals("Crosstab"))
306: return crosstabrootIcon;
307: if (node.getUserObject() instanceof Band) {
308: if (((Band) node.getUserObject()).getHeight() == 0) {
309: this .setForeground(Color.GRAY);
310: }
311:
312: if (((Band) node.getUserObject()).isGroupHeader()) {
313: return groupHeaderIcon;
314: }
315:
316: if (((Band) node.getUserObject()).isGroupFooter()) {
317: return groupFooterIcon;
318: }
319:
320: return bandIcon;
321: }
322: if (node.getUserObject() instanceof CrosstabCell)
323: return cellIcon;
324: if (node.getUserObject() instanceof TextFieldReportElement)
325: return textfieldIcon;
326: if (node.getUserObject() instanceof StaticTextReportElement)
327: return statictextIcon;
328: if (node.getUserObject() instanceof ChartReportElement)
329: return chartIcon;
330: if (node.getUserObject() instanceof ChartReportElement2)
331: return chartIcon;
332: if (node.getUserObject() instanceof ImageReportElement)
333: return imageIcon;
334: if (node.getUserObject() instanceof EllipseReportElement)
335: return ellipseIcon;
336: if (node.getUserObject() instanceof RectangleReportElement)
337: return rectangleIcon;
338: if (node.getUserObject() instanceof SubReportElement)
339: return subreportIcon;
340: if (node.getUserObject() instanceof LineReportElement)
341: return lineIcon;
342: if (node.getUserObject() instanceof ElementGroup)
343: return elementGroupIcon;
344: if (node.getUserObject() instanceof FrameReportElement)
345: return frameIcon;
346: if (node.getUserObject() instanceof CrosstabReportElement)
347: return crosstabIcon;
348: if (node.getUserObject() instanceof BreakReportElement)
349: return breakIcon;
350:
351: if (node.getUserObject() != null
352: && (node.getUserObject() instanceof JRField || node
353: .getUserObject() instanceof CrosstabGroup))
354: return fieldsIcon;
355:
356: if (node.getUserObject() != null
357: && (node.getUserObject() instanceof JRParameter || node
358: .getUserObject() instanceof CrosstabParameter)) {
359: if (node.getUserObject() instanceof JRParameter) {
360: if (((JRParameter) node.getUserObject()).isBuiltin())
361: return builtinParametersIcon;
362: }
363: return parametersIcon;
364: }
365:
366: if (node.getUserObject() != null
367: && (node.getUserObject() instanceof JRVariable || node
368: .getUserObject() instanceof Measure)) {
369: if (node.getUserObject() instanceof JRVariable) {
370: if (((JRVariable) node.getUserObject()).isBuiltin())
371: return builtinVariablesIcon;
372: }
373: return variablesIcon;
374: }
375:
376: if (node.getUserObject().toString().equals(
377: it.businesslogic.ireport.util.I18n.getString(
378: "gui.library.fields", "Fields")))
379: return folderFieldsIcon;
380: if (node.getUserObject().toString().equals(
381: it.businesslogic.ireport.util.I18n.getString(
382: "gui.library.variables", "Variables")))
383: return folderVariablesIcon;
384: if (node.getUserObject().toString().equals(
385: it.businesslogic.ireport.util.I18n.getString(
386: "gui.library.parameters", "Parameters")))
387: return folderParametersIcon;
388: if (node.getUserObject() != null
389: && node.getUserObject() instanceof SubDataset)
390: return datasetIcon;
391:
392: if (node.getUserObject() != null
393: && node.getUserObject() instanceof CustomExpression)
394: return expressionIcon;
395:
396: return docIcon;
397: }
398: }
|