1 32 33 package it.businesslogic.ireport.gui.documentstructure; 34 import it.businesslogic.ireport.*; 35 import it.businesslogic.ireport.crosstab.CrosstabCell; 36 import javax.swing.tree.*; 37 import javax.swing.*; 38 import java.awt.*; 39 40 44 public class DocumentStructureTreeCellRenderer extends DefaultTreeCellRenderer { 45 46 static ImageIcon docIcon; 47 static ImageIcon bandIcon; 48 static ImageIcon textfieldIcon; 49 static ImageIcon statictextIcon; 50 static ImageIcon imageIcon; 51 static ImageIcon ellipseIcon; 52 static ImageIcon rectangleIcon; 53 static ImageIcon subreportIcon; 54 static ImageIcon lineIcon; 55 static ImageIcon chartIcon; 56 static ImageIcon elementGroupIcon; 57 static ImageIcon frameIcon; 58 static ImageIcon crosstabIcon; 59 static ImageIcon cellIcon; 60 static ImageIcon crosstabrootIcon; 61 static ImageIcon breakIcon; 62 63 public DocumentStructureTreeCellRenderer() { 64 super(); 65 if (docIcon == null) docIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/doc.gif")); 66 if (bandIcon == null) bandIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/band.gif")); 67 if (textfieldIcon == null) textfieldIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/textfield.gif")); 68 if (statictextIcon == null) statictextIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/static.gif")); 69 if (imageIcon == null) imageIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/image.gif")); 70 if (ellipseIcon == null) ellipseIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/ellipse.gif")); 71 if (rectangleIcon == null) rectangleIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/rectangle.gif")); 72 if (subreportIcon == null) subreportIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/subreport.gif")); 73 if (lineIcon == null) lineIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/line.gif")); 74 if (chartIcon == null) chartIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/chart.gif")); 75 if (elementGroupIcon == null) elementGroupIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/elementgroup.png")); 76 if (frameIcon == null) frameIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/frame.png")); 77 if (crosstabIcon == null) crosstabIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/crosstab.png")); 78 if (cellIcon == null) cellIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/cell.png")); 79 if (crosstabrootIcon == null) crosstabrootIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/crosstabroot.png")); 80 if (breakIcon == null) breakIcon = new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/tree/elements/break.png")); 81 82 87 } 88 89 public Component getTreeCellRendererComponent( 90 JTree tree, 91 Object value, 92 boolean sel, 93 boolean expanded, 94 boolean leaf, 95 int row, 96 boolean hasFocus) { 97 98 super.getTreeCellRendererComponent( 99 tree, value, sel, 100 expanded, leaf, row, 101 hasFocus); 102 this.setForeground( Color.BLACK); 103 ImageIcon icon = getElementIcon(value); 104 setIcon(icon); 105 106 setToolTipText(null); 107 108 return this; 109 } 110 111 protected ImageIcon getElementIcon(Object value) { 112 DefaultMutableTreeNode node = 113 (DefaultMutableTreeNode)value; 114 this.setForeground( Color.BLACK); 115 116 if (node.getUserObject() instanceof ReportElement && 117 !((ReportElement)node.getUserObject()).insideBandReal()) 118 this.setForeground( Color.RED); 119 120 if ((node.getUserObject()+"").equals("Crosstab")) return crosstabrootIcon; 121 if (node.getUserObject() instanceof Band) return bandIcon; 122 if (node.getUserObject() instanceof CrosstabCell) return cellIcon; 123 if (node.getUserObject() instanceof TextFieldReportElement ) return textfieldIcon; 124 if (node.getUserObject() instanceof StaticTextReportElement ) return statictextIcon; 125 if (node.getUserObject() instanceof ChartReportElement) return chartIcon; 126 if (node.getUserObject() instanceof ChartReportElement2) return chartIcon; 127 if (node.getUserObject() instanceof ImageReportElement) return imageIcon; 128 if (node.getUserObject() instanceof EllipseReportElement) return ellipseIcon; 129 if (node.getUserObject() instanceof RectangleReportElement) return rectangleIcon; 130 if (node.getUserObject() instanceof SubReportElement) return subreportIcon; 131 if (node.getUserObject() instanceof LineReportElement) return lineIcon; 132 if (node.getUserObject() instanceof ElementGroup) return elementGroupIcon; 133 if (node.getUserObject() instanceof FrameReportElement) return frameIcon; 134 if (node.getUserObject() instanceof CrosstabReportElement) return crosstabIcon; 135 if (node.getUserObject() instanceof BreakReportElement) return breakIcon; 136 137 return docIcon; 138 } 139 } 140 141 | Popular Tags |