01: package com.salmonllc.swing.table;
02:
03: import java.awt.Component;
04: import javax.swing.DefaultCellEditor;
05: import javax.swing.JTable;
06:
07: import com.salmonllc.swing.SCheckBox;
08: import com.salmonllc.swing.SComponentHelper;
09:
10: public class CheckBoxCellEditor extends DefaultCellEditor {
11: SCheckBox _cbx;
12:
13: public CheckBoxCellEditor(SCheckBox checkBox) {
14: super (checkBox);
15: _cbx = checkBox;
16: }
17:
18: public Object getCellEditorValue() {
19: return _cbx.isSelected() ? _cbx.getTrueValue() : _cbx
20: .getFalseValue();
21: }
22:
23: /**
24: * @see javax.swing.table.TableCellEditor#getTableCellEditorComponent(JTable, Object, boolean, int, int)
25: */
26: public Component getTableCellEditorComponent(JTable table,
27: Object value, boolean isSelected, int row, int column) {
28: SCheckBox box = (SCheckBox) super .getTableCellEditorComponent(
29: table, value, isSelected, row, column);
30:
31: boolean selected = false;
32: if (SComponentHelper.valuesEqual(value, box.getTrueValue()))
33: selected = true;
34: box.setSelected(selected);
35: return box;
36: }
37:
38: }
|