1 30 package com.genimen.djeneric.ui; 31 32 import java.awt.Component ; 33 34 import javax.swing.JCheckBox ; 35 import javax.swing.JTable ; 36 import javax.swing.UIManager ; 37 import javax.swing.border.Border ; 38 import javax.swing.border.EmptyBorder ; 39 import javax.swing.table.TableCellRenderer ; 40 41 import com.genimen.djeneric.language.Messages; 42 import com.genimen.djeneric.repository.DjDomain; 43 import com.genimen.djeneric.repository.DjDomainValue; 44 45 51 public class DjCheckCellRenderer extends JCheckBox implements TableCellRenderer 52 { 53 private static final long serialVersionUID = 1L; 54 55 protected static Border _noFocusBorder; 56 57 protected DjDomainValue[] _domainValues = null; 58 59 62 public DjCheckCellRenderer() 63 { 64 super(); 65 _noFocusBorder = new EmptyBorder (1, 2, 1, 2); 66 setOpaque(true); 67 setBorder(_noFocusBorder); 68 } 69 70 76 public DjCheckCellRenderer(DjDomain dom) throws Exception 77 { 78 this(); 79 _domainValues = dom.getValidValues(); 80 if (_domainValues.length != 2) 81 { 82 throw new Exception (Messages.getString("DjCheckCellRenderer.Domain", dom.getName())); 83 } 84 } 85 86 98 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, 99 int row, int column) 100 { 101 if (_domainValues != null) 102 { 103 setSelected(_domainValues[0].getDescription().equals(value)); 104 } 105 else if (value instanceof Boolean ) 106 { 107 Boolean b = (Boolean ) value; 108 setSelected(b.booleanValue()); 109 } 110 111 setBackground(isSelected && !hasFocus ? table.getSelectionBackground() : table.getBackground()); 112 setForeground(isSelected && !hasFocus ? table.getSelectionForeground() : table.getForeground()); 113 114 setFont(table.getFont()); 115 setBorder(hasFocus ? UIManager.getBorder("Table.focusCellHighlightBorder") : _noFocusBorder); 116 return this; 117 } 118 119 } | Popular Tags |