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: * StyleCellRenderer.java
028: *
029: * Created on March 22, 2006, 4:44 PM
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.style;
034:
035: import it.businesslogic.ireport.JasperTemplate;
036: import it.businesslogic.ireport.Style;
037: import it.businesslogic.ireport.Template;
038: import it.businesslogic.ireport.UndefinedStyle;
039: import java.awt.Color;
040: import java.awt.Component;
041: import javax.swing.DefaultListCellRenderer;
042: import javax.swing.Icon;
043: import javax.swing.ImageIcon;
044: import javax.swing.JComponent;
045: import javax.swing.JLabel;
046: import javax.swing.JList;
047: import javax.swing.JTree;
048: import javax.swing.tree.DefaultMutableTreeNode;
049: import javax.swing.tree.DefaultTreeCellRenderer;
050:
051: /**
052: *
053: * @author gtoffoli
054: */
055: public class StyleCellRenderer extends DefaultTreeCellRenderer {
056:
057: static ImageIcon styleIcon;
058: static ImageIcon undefinedStyleIcon;
059: static ImageIcon templateIcon;
060: static ImageIcon linkTemplateIcon;
061:
062: /** Creates a new instance of StyleCellRenderer */
063: public StyleCellRenderer() {
064: super ();
065: if (styleIcon == null)
066: styleIcon = new javax.swing.ImageIcon(
067: getClass()
068: .getResource(
069: "/it/businesslogic/ireport/icons/styles/style.png"));
070: if (undefinedStyleIcon == null)
071: undefinedStyleIcon = new javax.swing.ImageIcon(
072: getClass()
073: .getResource(
074: "/it/businesslogic/ireport/icons/styles/undefinedStyle.png"));
075: if (templateIcon == null)
076: templateIcon = new javax.swing.ImageIcon(
077: getClass()
078: .getResource(
079: "/it/businesslogic/ireport/icons/styles/template.png"));
080: if (linkTemplateIcon == null)
081: linkTemplateIcon = new javax.swing.ImageIcon(
082: getClass()
083: .getResource(
084: "/it/businesslogic/ireport/icons/styles/linktemplate.png"));
085:
086: }
087:
088: public Component getTreeCellRendererComponent(JTree tree,
089: Object node, boolean isSelected, boolean isExpanded,
090: boolean isLeaf, int row, boolean cellHasFocus) {
091: JLabel c = (JLabel) super
092: .getTreeCellRendererComponent(tree, node, isSelected,
093: isExpanded, isLeaf, row, cellHasFocus);
094: //c.setOpaque(false);
095:
096: ImageIcon icon = getElementIcon(node);
097: if (icon != null)
098: c.setIcon(icon);
099: return c;
100: }
101:
102: protected ImageIcon getElementIcon(Object value) {
103: DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
104:
105: this .setForeground(Color.BLACK);
106:
107: if (node.getUserObject() instanceof UndefinedStyle)
108: this .setForeground(Color.GRAY);
109:
110: if (node.getUserObject() instanceof UndefinedStyle)
111: return undefinedStyleIcon;
112: if (node.getUserObject() instanceof Style)
113: return styleIcon;
114: if (node.getUserObject() instanceof JasperTemplate) {
115: if (((JasperTemplate) node.getUserObject()).getParent() == null)
116: return templateIcon;
117: else
118: return linkTemplateIcon;
119: }
120: if (node.getUserObject() instanceof Template)
121: return linkTemplateIcon;
122: return undefinedStyleIcon;
123: }
124:
125: public Color getBackgroundNonSelectionColor() {
126: return null;
127: }
128:
129: public Color getBackground() {
130: return null;
131: }
132:
133: }
|