1 package net.sf.jga.swing; 33 34 import javax.swing.table.TableCellEditor ; 35 import javax.swing.table.TableCellRenderer ; 36 import javax.swing.table.TableColumn ; 37 import net.sf.jga.fn.BinaryFunctor; 38 import net.sf.jga.fn.UnaryFunctor; 39 40 47 48 public class GenericTableColumn<R,C> extends TableColumn { 49 50 static final long serialVersionUID = 1960293231258498520L; 51 52 private Class <C> _coltype; 53 private UnaryFunctor<R,C> _getFn; 54 private BinaryFunctor<R,C,C> _setFn; 55 56 61 public GenericTableColumn(Class <C> coltype, UnaryFunctor<R,C> getFn) { 62 this(coltype, getFn, null); 63 } 64 65 73 public GenericTableColumn(Class <C> coltype, UnaryFunctor<R,C> getFn, 74 BinaryFunctor<R,C,C> setFn) 75 { 76 _coltype = coltype; 77 _getFn = getFn; 78 _setFn = setFn; 79 } 80 81 91 public GenericTableColumn(Class <C> coltype, UnaryFunctor<R,C> getFn, 92 BinaryFunctor<R,C,C> setFn, 93 UnaryFunctor<C,String > formatter, 94 UnaryFunctor<String ,C> parser) 95 { 96 this(coltype, getFn, setFn); 97 98 if (formatter != null) { 99 setCellRenderer(new GenericTableCellRenderer<C>(formatter)); 100 101 if (parser != null && setFn != null) { 102 setCellEditor(new GenericCellEditor<C>(formatter, parser)); 103 } 104 } 105 } 106 107 108 116 public GenericTableColumn(Class <C> coltype, UnaryFunctor<R,C> getFn, 117 BinaryFunctor<R,C,C> setFn, 118 TableCellRenderer renderer, TableCellEditor editor) 119 { 120 this(coltype, getFn, setFn); 121 setCellRenderer(renderer); 122 if (setFn != null) 123 setCellEditor(editor); 124 } 125 126 127 130 public C getValueAt (R rowvalue) { 131 return _getFn.fn(rowvalue); 132 } 133 134 137 public void setValueAt (R rowvalue, Object obj) { 138 if (_setFn != null) { 139 _setFn.fn(rowvalue, (C) obj); 142 } 143 } 144 145 148 public boolean isEditable() { 149 return _setFn != null; 150 } 151 152 155 public Class <C> getColumnClass() { 156 return _coltype; 157 } 158 159 162 public String toString() { 163 return super.toString() +"["+_getFn+","+_setFn+"]"; 164 } 165 } 166 | Popular Tags |