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: * ProjectExplorerTreeCellRenderer.java
028: *
029: * Created on 1 giugno 2003, 16.04
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: import it.businesslogic.ireport.*;
036: import javax.swing.tree.*;
037: import javax.swing.*;
038: import java.awt.*;
039:
040: /**
041: *
042: * @author Administrator
043: */
044: public class ProjectExplorerTreeCellRenderer extends
045: DefaultTreeCellRenderer {
046: static ImageIcon folderClosedIcon;
047: static ImageIcon folderOpenedIcon;
048:
049: static ImageIcon dirtyDocumentIcon;
050: static ImageIcon documentIcon;
051:
052: public ProjectExplorerTreeCellRenderer() {
053: super ();
054: if (folderClosedIcon == null)
055: folderClosedIcon = new javax.swing.ImageIcon(
056: getClass()
057: .getResource(
058: "/it/businesslogic/ireport/icons/tree/folderClosed.gif"));
059: if (folderOpenedIcon == null)
060: folderOpenedIcon = new javax.swing.ImageIcon(
061: getClass()
062: .getResource(
063: "/it/businesslogic/ireport/icons/tree/folderOpened.gif"));
064: if (dirtyDocumentIcon == null)
065: dirtyDocumentIcon = new javax.swing.ImageIcon(
066: getClass()
067: .getResource(
068: "/it/businesslogic/ireport/icons/tree/docDirty.gif"));
069: if (documentIcon == null)
070: documentIcon = new javax.swing.ImageIcon(
071: getClass()
072: .getResource(
073: "/it/businesslogic/ireport/icons/tree/doc.gif"));
074:
075: /*
076: this.setOpenIcon(folderOpenedIcon);
077: this.setClosedIcon(folderClosedIcon);
078: this.setLeafIcon(documentIcon);
079: */
080: }
081:
082: public Component getTreeCellRendererComponent(JTree tree,
083: Object value, boolean sel, boolean expanded, boolean leaf,
084: int row, boolean hasFocus) {
085:
086: super .getTreeCellRendererComponent(tree, value, sel, expanded,
087: leaf, row, hasFocus);
088:
089: if (!((DefaultMutableTreeNode) value).isRoot() && leaf
090: && isDirty(value)) {
091: setIcon(dirtyDocumentIcon);
092: setToolTipText(null);
093: } else if (!((DefaultMutableTreeNode) value).isRoot() && leaf
094: && !isDirty(value)) {
095: setIcon(documentIcon);
096: setToolTipText(null);
097: } else if ((((DefaultMutableTreeNode) value).isRoot() || !leaf)
098: && expanded) {
099: setIcon(folderOpenedIcon);
100: setToolTipText(null); //no tool tip
101: } else if ((((DefaultMutableTreeNode) value).isRoot() || !leaf)
102: && !expanded) {
103: setIcon(folderClosedIcon);
104: setToolTipText(null); //no tool tip
105: }
106:
107: return this ;
108: }
109:
110: protected boolean isDirty(Object value) {
111: DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
112:
113: if (node.getUserObject() instanceof DocumentTreeEntry) {
114: DocumentTreeEntry nodeInfo = (DocumentTreeEntry) (node
115: .getUserObject());
116: if (nodeInfo.getJrf() != null)
117: return nodeInfo.getJrf().getReport().isModified();
118: }
119: return false;
120: }
121: }
|