KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > data > olap > OlapTreeCellRenderer


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  * OlapTreeCellRenderer.java
28  *
29  * Created on 1 giugno 2003, 16.04
30  *
31  */

32
33 package it.businesslogic.ireport.data.olap;
34 import it.businesslogic.ireport.*;
35 import it.businesslogic.ireport.data.olap.WalkableWrapper;
36 import javax.swing.tree.*;
37 import javax.swing.*;
38 import java.awt.*;
39 import mondrian.olap.QueryAxis;
40 /**
41  *
42  * @author Administrator
43  */

44 public class OlapTreeCellRenderer extends DefaultTreeCellRenderer {
45
46     
47     static ImageIcon measureIcon;
48     static ImageIcon dimensionIcon;
49     static ImageIcon hierarchyIcon;
50     
51     public OlapTreeCellRenderer() {
52         super();
53
54         if (measureIcon == null) measureIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/olap/measure.png"));
55         if (dimensionIcon == null) dimensionIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/olap/axis.png"));
56         if (hierarchyIcon == null) hierarchyIcon = new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/olap/hierarchy.png"));
57         
58     }
59
60     public Component getTreeCellRendererComponent(
61                         JTree tree,
62                         Object JavaDoc value,
63                         boolean sel,
64                         boolean expanded,
65                         boolean leaf,
66                         int row,
67                         boolean hasFocus) {
68
69         super.getTreeCellRendererComponent(
70                         tree, value, sel,
71                         expanded, leaf, row,
72                         hasFocus);
73             this.setForeground( Color.BLACK);
74             ImageIcon icon = getElementIcon(value);
75             setIcon(icon);
76
77             setToolTipText(null);
78
79         return this;
80     }
81
82     protected ImageIcon getElementIcon(Object JavaDoc value) {
83         
84         if (!(value instanceof DefaultMutableTreeNode)) return null; // ?!!!
85

86         DefaultMutableTreeNode node =
87                 (DefaultMutableTreeNode)value;
88
89         try {
90             WalkableWrapper ww = (WalkableWrapper)node.getUserObject();
91
92             if (node.getParent() != null && node.getParent() instanceof DefaultMutableTreeNode)
93             {
94                 if (ww.isMeasure()) return measureIcon;
95                 if (ww.getWalkable() instanceof QueryAxis) return dimensionIcon;
96                 return hierarchyIcon;
97             }
98             
99         } catch (Exception JavaDoc ex)
100         {
101             
102         }
103         return null;
104     }
105 }
106
107
Popular Tags