1 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 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 (getClass().getResource("/it/businesslogic/ireport/icons/olap/measure.png")); 55 if (dimensionIcon == null) dimensionIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/olap/axis.png")); 56 if (hierarchyIcon == null) hierarchyIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/olap/hierarchy.png")); 57 58 } 59 60 public Component getTreeCellRendererComponent( 61 JTree tree, 62 Object 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 value) { 83 84 if (!(value instanceof DefaultMutableTreeNode)) return null; 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 ex) 100 { 101 102 } 103 return null; 104 } 105 } 106 107 | Popular Tags |