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: * DocumentExpressionEditorTreeCellRenderer.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 DocumentExpressionEditorTreeCellRenderer extends
045: DefaultTreeCellRenderer {
046:
047: //static ImageIcon fieldIcon;
048: //static ImageIcon variableIcon;
049: //static ImageIcon parameterIcon;
050: static ImageIcon folderFieldsIcon;
051: static ImageIcon folderVariablesIcon;
052: static ImageIcon folderParametersIcon;
053: static ImageIcon customFolderIcon;
054:
055: static ImageIcon fieldsIcon;
056: static ImageIcon variablesIcon;
057: static ImageIcon parametersIcon;
058:
059: public DocumentExpressionEditorTreeCellRenderer() {
060: super ();
061: //if (fieldIcon == null) fieldIcon = new javax.swing.ImageIcon(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/field.gif"));
062: //if (variableIcon == null) variableIcon = new javax.swing.ImageIcon(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/variable.gif"));
063: //if (parameterIcon == null) parameterIcon = new javax.swing.ImageIcon(getClass().getResource("/it/businesslogic/ireport/icons/tree/editor/parameter.gif"));
064: if (folderFieldsIcon == null)
065: folderFieldsIcon = new javax.swing.ImageIcon(
066: getClass()
067: .getResource(
068: "/it/businesslogic/ireport/icons/tree/editor/fieldsfolder.png"));
069: if (folderVariablesIcon == null)
070: folderVariablesIcon = new javax.swing.ImageIcon(
071: getClass()
072: .getResource(
073: "/it/businesslogic/ireport/icons/tree/editor/variablesfolder.png"));
074: if (folderParametersIcon == null)
075: folderParametersIcon = new javax.swing.ImageIcon(
076: getClass()
077: .getResource(
078: "/it/businesslogic/ireport/icons/tree/editor/parametersfolder.png"));
079:
080: if (fieldsIcon == null)
081: fieldsIcon = new javax.swing.ImageIcon(
082: getClass()
083: .getResource(
084: "/it/businesslogic/ireport/icons/tree/editor/field.png"));
085: if (variablesIcon == null)
086: variablesIcon = new javax.swing.ImageIcon(
087: getClass()
088: .getResource(
089: "/it/businesslogic/ireport/icons/tree/editor/variable.png"));
090: if (parametersIcon == null)
091: parametersIcon = new javax.swing.ImageIcon(
092: getClass()
093: .getResource(
094: "/it/businesslogic/ireport/icons/tree/editor/parameter.png"));
095:
096: if (customFolderIcon == null)
097: customFolderIcon = new javax.swing.ImageIcon(
098: getClass()
099: .getResource(
100: "/it/businesslogic/ireport/icons/tree/editor/customfolder.gif"));
101:
102: /*
103: this.setOpenIcon(folderOpenedIcon);
104: this.setClosedIcon(folderClosedIcon);
105: this.setLeafIcon(documentIcon);
106: */
107: }
108:
109: public Component getTreeCellRendererComponent(JTree tree,
110: Object value, boolean sel, boolean expanded, boolean leaf,
111: int row, boolean hasFocus) {
112:
113: super .getTreeCellRendererComponent(tree, value, sel, expanded,
114: leaf, row, hasFocus);
115: this .setForeground(Color.BLACK);
116: ImageIcon icon = getElementIcon(value);
117: setIcon(icon);
118:
119: setToolTipText(null);
120:
121: return this ;
122: }
123:
124: protected ImageIcon getElementIcon(Object value) {
125:
126: if (!(value instanceof DefaultMutableTreeNode))
127: return customFolderIcon;
128: DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
129: this .setForeground(Color.BLACK);
130:
131: if (node.getUserObject() instanceof IconedString) {
132: IconedString iconedString = (IconedString) node
133: .getUserObject();
134: setText(iconedString.getStr());
135: return iconedString.getIcon();
136: }
137:
138: if (node.getUserObject().toString().equalsIgnoreCase(
139: "Variables"))
140: return folderVariablesIcon;
141: if (node.getUserObject().toString().equalsIgnoreCase("Fields"))
142: return folderFieldsIcon;
143: if (node.getUserObject().toString().equalsIgnoreCase(
144: "Parameters"))
145: return folderParametersIcon;
146:
147: if (node.getParent() != null
148: && node.getParent() instanceof DefaultMutableTreeNode) {
149: DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node
150: .getParent();
151: if (parentNode.getUserObject().toString().equalsIgnoreCase(
152: "Variables"))
153: return variablesIcon;
154: if (parentNode.getUserObject().toString().equalsIgnoreCase(
155: "Fields"))
156: return fieldsIcon;
157: if (parentNode.getUserObject().toString().equalsIgnoreCase(
158: "Parameters"))
159: return parametersIcon;
160: }
161: return customFolderIcon;
162: }
163: }
|