KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ProjectExplorerTreeCellRenderer.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 ProjectExplorerTreeCellRenderer extends DefaultTreeCellRenderer {
43     static ImageIcon folderClosedIcon;
44     static ImageIcon folderOpenedIcon;
45     
46     static ImageIcon dirtyDocumentIcon;
47     static ImageIcon documentIcon;
48
49     public ProjectExplorerTreeCellRenderer() {
50         super();
51         if (folderClosedIcon == null)
52             folderClosedIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/folderClosed.gif"));
53         if (folderOpenedIcon == null)
54             folderOpenedIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/folderOpened.gif"));
55         if (dirtyDocumentIcon == null)
56             dirtyDocumentIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/docDirty.gif"));
57         if (documentIcon == null)
58             documentIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/tree/doc.gif"));
59         
60         /*
61         this.setOpenIcon(folderOpenedIcon);
62         this.setClosedIcon(folderClosedIcon);
63         this.setLeafIcon(documentIcon);
64          */

65     }
66
67     public Component getTreeCellRendererComponent(
68                         JTree tree,
69                         Object JavaDoc value,
70                         boolean sel,
71                         boolean expanded,
72                         boolean leaf,
73                         int row,
74                         boolean hasFocus) {
75
76         super.getTreeCellRendererComponent(
77                         tree, value, sel,
78                         expanded, leaf, row,
79                         hasFocus);
80              
81         if (!((DefaultMutableTreeNode)value).isRoot() && leaf && isDirty(value)) {
82             setIcon(dirtyDocumentIcon);
83             setToolTipText(null);
84         } else if (!((DefaultMutableTreeNode)value).isRoot() && leaf && !isDirty(value)) {
85             setIcon(documentIcon);
86             setToolTipText(null);
87         }
88         else if (( ((DefaultMutableTreeNode)value).isRoot() || !leaf) && expanded)
89         {
90              setIcon(folderOpenedIcon);
91             setToolTipText(null); //no tool tip
92
}
93         else if (( ((DefaultMutableTreeNode)value).isRoot() || !leaf) && !expanded)
94         {
95             setIcon(folderClosedIcon);
96             setToolTipText(null); //no tool tip
97
}
98
99         return this;
100     }
101
102     protected boolean isDirty(Object JavaDoc value) {
103         DefaultMutableTreeNode node =
104                 (DefaultMutableTreeNode)value;
105         
106         if (node.getUserObject() instanceof DocumentTreeEntry)
107         {
108             DocumentTreeEntry nodeInfo =
109                 (DocumentTreeEntry)(node.getUserObject());
110             if (nodeInfo.getJrf() != null)
111                 return nodeInfo.getJrf().getReport().isModified();
112         }
113         return false;
114     }
115 }
116
117
Popular Tags