KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > documentstructure > DocumentStructureTreeCellRenderer


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

32
33 package it.businesslogic.ireport.gui.documentstructure;
34 import it.businesslogic.ireport.*;
35 import it.businesslogic.ireport.crosstab.CrosstabCell;
36 import javax.swing.tree.*;
37 import javax.swing.*;
38 import java.awt.*;
39
40 /**
41  *
42  * @author Administrator
43  */

44 public class DocumentStructureTreeCellRenderer extends DefaultTreeCellRenderer {
45
46     static ImageIcon docIcon;
47     static ImageIcon bandIcon;
48     static ImageIcon textfieldIcon;
49     static ImageIcon statictextIcon;
50     static ImageIcon imageIcon;
51     static ImageIcon ellipseIcon;
52     static ImageIcon rectangleIcon;
53     static ImageIcon subreportIcon;
54     static ImageIcon lineIcon;
55     static ImageIcon chartIcon;
56     static ImageIcon elementGroupIcon;
57     static ImageIcon frameIcon;
58     static ImageIcon crosstabIcon;
59     static ImageIcon cellIcon;
60     static ImageIcon crosstabrootIcon;
61     static ImageIcon breakIcon;
62
63     public DocumentStructureTreeCellRenderer() {
64         super();
65         if (docIcon == null) docIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/doc.gif"));
66         if (bandIcon == null) bandIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/band.gif"));
67         if (textfieldIcon == null) textfieldIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/textfield.gif"));
68         if (statictextIcon == null) statictextIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/static.gif"));
69         if (imageIcon == null) imageIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/image.gif"));
70         if (ellipseIcon == null) ellipseIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/ellipse.gif"));
71         if (rectangleIcon == null) rectangleIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/rectangle.gif"));
72         if (subreportIcon == null) subreportIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/subreport.gif"));
73         if (lineIcon == null) lineIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/line.gif"));
74         if (chartIcon == null) chartIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/chart.gif"));
75         if (elementGroupIcon == null) elementGroupIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/elementgroup.png"));
76         if (frameIcon == null) frameIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/frame.png"));
77         if (crosstabIcon == null) crosstabIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/crosstab.png"));
78         if (cellIcon == null) cellIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/cell.png"));
79         if (crosstabrootIcon == null) crosstabrootIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/crosstabroot.png"));
80         if (breakIcon == null) breakIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/break.png"));
81         
82         /*
83         this.setOpenIcon(folderOpenedIcon);
84         this.setClosedIcon(folderClosedIcon);
85         this.setLeafIcon(documentIcon);
86          */

87     }
88
89     public Component getTreeCellRendererComponent(
90                         JTree tree,
91                         Object JavaDoc value,
92                         boolean sel,
93                         boolean expanded,
94                         boolean leaf,
95                         int row,
96                         boolean hasFocus) {
97
98         super.getTreeCellRendererComponent(
99                         tree, value, sel,
100                         expanded, leaf, row,
101                         hasFocus);
102             this.setForeground( Color.BLACK);
103             ImageIcon icon = getElementIcon(value);
104             setIcon(icon);
105
106             setToolTipText(null);
107
108         return this;
109     }
110
111     protected ImageIcon getElementIcon(Object JavaDoc value) {
112         DefaultMutableTreeNode node =
113                 (DefaultMutableTreeNode)value;
114         this.setForeground( Color.BLACK);
115         
116         if (node.getUserObject() instanceof ReportElement &&
117             !((ReportElement)node.getUserObject()).insideBandReal())
118             this.setForeground( Color.RED);
119         
120         if ((node.getUserObject()+"").equals("Crosstab")) return crosstabrootIcon;
121         if (node.getUserObject() instanceof Band) return bandIcon;
122         if (node.getUserObject() instanceof CrosstabCell) return cellIcon;
123         if (node.getUserObject() instanceof TextFieldReportElement ) return textfieldIcon;
124         if (node.getUserObject() instanceof StaticTextReportElement ) return statictextIcon;
125         if (node.getUserObject() instanceof ChartReportElement) return chartIcon;
126         if (node.getUserObject() instanceof ChartReportElement2) return chartIcon;
127         if (node.getUserObject() instanceof ImageReportElement) return imageIcon;
128         if (node.getUserObject() instanceof EllipseReportElement) return ellipseIcon;
129         if (node.getUserObject() instanceof RectangleReportElement) return rectangleIcon;
130         if (node.getUserObject() instanceof SubReportElement) return subreportIcon;
131         if (node.getUserObject() instanceof LineReportElement) return lineIcon;
132         if (node.getUserObject() instanceof ElementGroup) return elementGroupIcon;
133         if (node.getUserObject() instanceof FrameReportElement) return frameIcon;
134         if (node.getUserObject() instanceof CrosstabReportElement) return crosstabIcon;
135         if (node.getUserObject() instanceof BreakReportElement) return breakIcon;
136         
137         return docIcon;
138     }
139 }
140
141
Popular Tags