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.TreeCellRenderer ; 41 42 import com.genimen.djeneric.tools.modeler.ModelEditor; 43 44 public class ResourceFolderRenderer 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 setIcon(ModelEditor.getImageIcon("folder.gif")); 84 85 86 _selected = selected; 87 88 return this; 89 } 90 91 98 public void paint(Graphics g) 99 { 100 Color bColor; 101 Icon currentI = getIcon(); 102 103 if (_selected) 104 { 105 bColor = _selectedBackgroundColor; 106 } 107 else if (getParent() != null) 108 { 109 bColor = getParent().getBackground(); 111 } 112 else 113 { 114 bColor = getBackground(); 115 } 116 g.setColor(bColor); 117 118 if (currentI != null && getText() != null) 119 { 120 int offset = (currentI.getIconWidth() + getIconTextGap()); 121 g.fillRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1); 122 } 123 else 124 { 125 g.fillRect(0, 0, getWidth() - 1, getHeight() - 1); 126 } 127 super.paint(g); 128 } 129 } | Popular Tags |