1 30 package com.genimen.djeneric.tools.administrator.nodes; 31 32 import java.awt.Color ; 33 import java.awt.Component ; 34 import java.awt.Font ; 35 import java.awt.Graphics ; 36 37 import javax.swing.Icon ; 38 import javax.swing.JLabel ; 39 import javax.swing.JTree ; 40 import javax.swing.tree.TreeCellRenderer ; 41 42 import com.genimen.djeneric.tools.administrator.Administrator; 43 44 public class AdministratorTreeCellRenderer extends JLabel implements TreeCellRenderer 45 { 46 private static final long serialVersionUID = 1L; 47 protected static Font _defaultFont; 48 protected final static Color _selectedBackgroundColor = Color.yellow; 49 51 static 52 { 53 _defaultFont = new Font ("SansSerif", 0, 12); 54 } 55 56 59 protected boolean _selected; 60 61 75 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, 76 boolean leaf, int row, boolean hasFocus) 77 { 78 if (value == null) return this; 79 String stringValue = value.toString(); 80 setText(stringValue); 81 setToolTipText(stringValue); 82 83 84 if (value instanceof AdministratorTreeNode) 85 { 86 setIcon(((AdministratorTreeNode) (value)).getImageIcon()); 87 } 88 else 89 { 90 setIcon(Administrator.getImageIcon("document.gif")); 91 } 93 94 95 _selected = selected; 96 97 return this; 98 } 99 100 107 public void paint(Graphics g) 108 { 109 Color bColor; 110 Icon currentI = getIcon(); 111 112 if (_selected) 113 { 114 bColor = _selectedBackgroundColor; 115 } 116 else if (getParent() != null) 117 { 118 bColor = getParent().getBackground(); 120 } 121 else 122 { 123 bColor = getBackground(); 124 } 125 g.setColor(bColor); 126 127 if (currentI != null && getText() != null) 128 { 129 int offset = (currentI.getIconWidth() + getIconTextGap()); 130 g.fillRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1); 131 } 132 else 133 { 134 g.fillRect(0, 0, getWidth() - 1, getHeight() - 1); 135 } 136 super.paint(g); 137 } 138 } | Popular Tags |