Revision 47436 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/dal/feature/swing/table/BooleanCellRenderer.java
BooleanCellRenderer.java | ||
---|---|---|
5 | 5 |
*/ |
6 | 6 |
package org.gvsig.fmap.mapcontrol.dal.feature.swing.table; |
7 | 7 |
|
8 |
import java.awt.Color; |
|
9 | 8 |
import java.awt.Component; |
10 | 9 |
import javax.swing.JCheckBox; |
11 | 10 |
import javax.swing.JLabel; |
... | ... | |
13 | 12 |
import javax.swing.UIManager; |
14 | 13 |
import javax.swing.border.Border; |
15 | 14 |
import javax.swing.border.EmptyBorder; |
16 |
import javax.swing.plaf.UIResource; |
|
17 |
import javax.swing.table.TableCellRenderer; |
|
18 |
import org.gvsig.fmap.dal.feature.Feature; |
|
19 |
import static org.gvsig.fmap.dal.feature.Feature.CHECK_BASIC; |
|
20 |
import static org.gvsig.fmap.dal.feature.Feature.CHECK_REQUIREDS; |
|
21 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
22 | 15 |
|
23 | 16 |
/** |
24 | 17 |
* |
25 | 18 |
* @author fdiaz |
26 | 19 |
*/ |
27 |
public class BooleanCellRenderer extends JCheckBox implements TableCellRenderer, UIResource {
|
|
20 |
public class BooleanCellRenderer extends FeatureAttributeCellRenderer { // implements TableCellRenderer, UIResource {
|
|
28 | 21 |
|
29 | 22 |
private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1); |
30 |
protected final Color backgroundColorWarning;
|
|
23 |
private final JCheckBox chkBox;
|
|
31 | 24 |
|
32 | 25 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
33 | 26 |
public BooleanCellRenderer() { |
34 |
super(); |
|
35 |
setHorizontalAlignment(JLabel.CENTER); |
|
36 |
setBorderPainted(true); |
|
37 |
this.backgroundColorWarning = ToolsSwingLocator.getToolsSwingManager().getWarningBackgroundColor(); |
|
27 |
this.chkBox = new JCheckBox(); |
|
28 |
this.chkBox.setHorizontalAlignment(JLabel.CENTER); |
|
29 |
this.chkBox.setBorderPainted(true); |
|
38 | 30 |
} |
39 | 31 |
|
40 | 32 |
@Override |
41 | 33 |
public Component getTableCellRendererComponent(JTable table, Object value, |
42 | 34 |
boolean isSelected, boolean hasFocus, int row, int column) { |
43 | 35 |
try { |
36 |
this.chkBox.setBackground(this.getBackgroundColor(table, isSelected, row, column)); |
|
44 | 37 |
if (isSelected) { |
45 |
setForeground(table.getSelectionForeground()); |
|
46 |
super.setBackground(table.getSelectionBackground()); |
|
38 |
this.chkBox.setForeground(table.getSelectionForeground()); |
|
47 | 39 |
} else { |
48 |
ConfigurableFeatureTableModel tableModel = (ConfigurableFeatureTableModel) table.getModel(); |
|
49 |
|
|
50 |
Feature feature = tableModel.getFeatureAt(row); |
|
51 |
setForeground(table.getForeground()); |
|
52 |
setBackground(table.getBackground()); |
|
53 |
if (tableModel.getFeatureStore().isFeatureModified(feature)) { |
|
54 |
try { |
|
55 |
feature.validate(Feature.CHECK_RULES_AT_FINISH | CHECK_REQUIREDS | CHECK_BASIC); |
|
56 |
} catch (Exception ex) { |
|
57 |
this.setBackground(this.backgroundColorWarning); |
|
58 |
} |
|
59 |
} |
|
40 |
this.chkBox.setForeground(table.getForeground()); |
|
60 | 41 |
} |
61 |
setSelected((value != null && ((Boolean) value))); |
|
42 |
this.chkBox.setSelected((value != null && ((Boolean) value)));
|
|
62 | 43 |
|
63 | 44 |
if (hasFocus) { |
64 |
setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); |
|
45 |
this.chkBox.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
|
|
65 | 46 |
} else { |
66 |
setBorder(noFocusBorder); |
|
47 |
this.chkBox.setBorder(noFocusBorder);
|
|
67 | 48 |
} |
68 | 49 |
} catch (Exception e) { |
69 | 50 |
|
Also available in: Unified diff