1 30 package com.genimen.djeneric.tools.modeler.userperspective; 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.DefaultMutableTreeNode ; 41 import javax.swing.tree.TreeCellRenderer ; 42 43 import com.genimen.djeneric.tools.modeler.ModelEditor; 44 import com.genimen.djeneric.util.DjLogger; 45 46 public class ExtentNodeRenderer extends JLabel implements TreeCellRenderer 47 { 48 private static final long serialVersionUID = 1L; 49 protected static Font defaultFont; 50 protected final static Color SelectedBackgroundColor = Color.yellow; 51 53 static 54 { 55 try 56 { 57 defaultFont = new Font ("SansSerif", 0, 12); 58 } 59 catch (Exception e) 60 { 61 DjLogger.log(e); 62 } 63 } 64 65 68 protected boolean selected; 69 70 91 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, 92 boolean leaf, int row, boolean hasFocus) 93 { 94 if (value == null) return (this); 95 String stringValue = value.toString(); 96 setText(stringValue); 97 setToolTipText(stringValue); 98 99 100 if (value instanceof ExtentNode) 101 { 102 setIcon(((ExtentNode) (value)).getImageIcon()); 103 } 104 else if (value instanceof DefaultMutableTreeNode ) 105 { 106 setIcon(ModelEditor.getImageIcon("empty.gif")); 107 } 108 109 110 this.selected = selected; 111 112 return (this); 113 } 114 115 123 public void paint(Graphics g) 124 { 125 Color bColor; 126 Icon currentI = getIcon(); 127 128 if (selected) 129 { 130 bColor = SelectedBackgroundColor; 131 } 132 else if (getParent() != null) 133 { 134 137 bColor = getParent().getBackground(); 138 } 139 else 140 { 141 bColor = getBackground(); 142 } 143 g.setColor(bColor); 144 145 if (currentI != null && getText() != null) 146 { 147 int offset = (currentI.getIconWidth() + getIconTextGap()); 148 g.fillRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1); 149 } 150 else 151 { 152 g.fillRect(0, 0, getWidth() - 1, getHeight() - 1); 153 } 154 super.paint(g); 155 } 156 } | Popular Tags |