1 16 package org.apache.log4j.lf5.viewer.categoryexplorer; 17 18 import javax.swing.*; 19 import javax.swing.tree.DefaultTreeCellRenderer ; 20 import java.awt.*; 21 import java.net.URL ; 22 23 29 30 32 public class CategoryNodeRenderer extends DefaultTreeCellRenderer { 33 37 public static final Color FATAL_CHILDREN = new Color(189, 113, 0); 38 39 protected JCheckBox _checkBox = new JCheckBox(); 43 protected JPanel _panel = new JPanel(); 44 protected static ImageIcon _sat = null; 45 47 51 public CategoryNodeRenderer() { 55 _panel.setBackground(UIManager.getColor("Tree.textBackground")); 56 57 if (_sat == null) { 58 String resource = 60 "/org/apache/log4j/lf5/viewer/images/channelexplorer_satellite.gif"; 61 URL satURL = getClass().getResource(resource); 62 63 _sat = new ImageIcon(satURL); 64 } 65 66 setOpaque(false); 67 _checkBox.setOpaque(false); 68 _panel.setOpaque(false); 69 70 _panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); 73 _panel.add(_checkBox); 74 _panel.add(this); 75 76 setOpenIcon(_sat); 77 setClosedIcon(_sat); 78 setLeafIcon(_sat); 79 } 80 81 public Component getTreeCellRendererComponent( 85 JTree tree, Object value, 86 boolean selected, boolean expanded, 87 boolean leaf, int row, 88 boolean hasFocus) { 89 90 CategoryNode node = (CategoryNode) value; 91 95 super.getTreeCellRendererComponent( 96 tree, value, selected, expanded, 97 leaf, row, hasFocus); 98 99 if (row == 0) { 100 _checkBox.setVisible(false); 102 } else { 103 _checkBox.setVisible(true); 104 _checkBox.setSelected(node.isSelected()); 105 } 106 String toolTip = buildToolTip(node); 107 _panel.setToolTipText(toolTip); 108 if (node.hasFatalChildren()) { 109 this.setForeground(FATAL_CHILDREN); 110 } 111 if (node.hasFatalRecords()) { 112 this.setForeground(Color.red); 113 } 114 115 return _panel; 116 } 117 118 public Dimension getCheckBoxOffset() { 119 return new Dimension(0, 0); 120 } 121 122 126 protected String buildToolTip(CategoryNode node) { 127 StringBuffer result = new StringBuffer (); 128 result.append(node.getTitle()).append(" contains a total of "); 129 result.append(node.getTotalNumberOfRecords()); 130 result.append(" LogRecords."); 131 result.append(" Right-click for more info."); 132 return result.toString(); 133 } 134 138 142 } 143 144 145 146 147 148 149 | Popular Tags |