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: * OlapTreeCellRenderer.java
028: *
029: * Created on 1 giugno 2003, 16.04
030: *
031: */
032:
033: package it.businesslogic.ireport.data.olap;
034:
035: import it.businesslogic.ireport.*;
036: import it.businesslogic.ireport.data.olap.WalkableWrapper;
037: import javax.swing.tree.*;
038: import javax.swing.*;
039: import java.awt.*;
040: import mondrian.olap.QueryAxis;
041:
042: /**
043: *
044: * @author Administrator
045: */
046: public class OlapTreeCellRenderer extends DefaultTreeCellRenderer {
047:
048: static ImageIcon measureIcon;
049: static ImageIcon dimensionIcon;
050: static ImageIcon hierarchyIcon;
051:
052: public OlapTreeCellRenderer() {
053: super ();
054:
055: if (measureIcon == null)
056: measureIcon = new javax.swing.ImageIcon(
057: getClass()
058: .getResource(
059: "/it/businesslogic/ireport/icons/olap/measure.png"));
060: if (dimensionIcon == null)
061: dimensionIcon = new javax.swing.ImageIcon(
062: getClass()
063: .getResource(
064: "/it/businesslogic/ireport/icons/olap/axis.png"));
065: if (hierarchyIcon == null)
066: hierarchyIcon = new javax.swing.ImageIcon(
067: getClass()
068: .getResource(
069: "/it/businesslogic/ireport/icons/olap/hierarchy.png"));
070:
071: }
072:
073: public Component getTreeCellRendererComponent(JTree tree,
074: Object value, boolean sel, boolean expanded, boolean leaf,
075: int row, boolean hasFocus) {
076:
077: super .getTreeCellRendererComponent(tree, value, sel, expanded,
078: leaf, row, hasFocus);
079: this .setForeground(Color.BLACK);
080: ImageIcon icon = getElementIcon(value);
081: setIcon(icon);
082:
083: setToolTipText(null);
084:
085: return this ;
086: }
087:
088: protected ImageIcon getElementIcon(Object value) {
089:
090: if (!(value instanceof DefaultMutableTreeNode))
091: return null; // ?!!!
092:
093: DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
094:
095: try {
096: WalkableWrapper ww = (WalkableWrapper) node.getUserObject();
097:
098: if (node.getParent() != null
099: && node.getParent() instanceof DefaultMutableTreeNode) {
100: if (ww.isMeasure())
101: return measureIcon;
102: if (ww.getWalkable() instanceof QueryAxis)
103: return dimensionIcon;
104: return hierarchyIcon;
105: }
106:
107: } catch (Exception ex) {
108:
109: }
110: return null;
111: }
112: }
|