01: package org.uispec4j;
02:
03: import javax.swing.*;
04: import java.awt.*;
05:
06: /**
07: * Default implementation for the TableCellValueConverter interface.
08: * This converter returns the displayed value for JLabel and JComboBox components, and a Boolean
09: * in the case of a JCheckBox. If another renderer type is used, it will returned the stringified object
10: * used by the internal model of the table (using toString()), or an empty string if this model
11: * object is null.
12: */
13: public class DefaultTableCellValueConverter implements
14: TableCellValueConverter {
15:
16: public Object getValue(int row, int column,
17: Component renderedComponent, Object modelObject) {
18: if (renderedComponent instanceof JLabel) {
19: return ((JLabel) renderedComponent).getText();
20: } else if (renderedComponent instanceof JComboBox) {
21: return ((JComboBox) renderedComponent).getSelectedItem()
22: .toString();
23: } else if (renderedComponent instanceof JCheckBox) {
24: return Boolean.valueOf(((JCheckBox) renderedComponent)
25: .isSelected());
26: }
27: if (modelObject != null) {
28: return modelObject.toString();
29: }
30: return "";
31: }
32: }
|