Statistics
| Revision:

svn-gvsig-desktop / 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 @ 47436

History | View | Annotate | Download (1.78 KB)

1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.fmap.mapcontrol.dal.feature.swing.table;
7

    
8
import java.awt.Component;
9
import javax.swing.JCheckBox;
10
import javax.swing.JLabel;
11
import javax.swing.JTable;
12
import javax.swing.UIManager;
13
import javax.swing.border.Border;
14
import javax.swing.border.EmptyBorder;
15

    
16
/**
17
 *
18
 * @author fdiaz
19
 */
20
public class BooleanCellRenderer extends FeatureAttributeCellRenderer { // implements TableCellRenderer, UIResource {
21

    
22
    private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
23
    private final JCheckBox chkBox;
24

    
25
    @SuppressWarnings("OverridableMethodCallInConstructor")
26
    public BooleanCellRenderer() {
27
        this.chkBox = new JCheckBox();
28
        this.chkBox.setHorizontalAlignment(JLabel.CENTER);
29
        this.chkBox.setBorderPainted(true);
30
    }
31

    
32
    @Override
33
    public Component getTableCellRendererComponent(JTable table, Object value,
34
            boolean isSelected, boolean hasFocus, int row, int column) {
35
        try {
36
            this.chkBox.setBackground(this.getBackgroundColor(table, isSelected, row, column));
37
            if (isSelected) {
38
                this.chkBox.setForeground(table.getSelectionForeground());
39
            } else {
40
                this.chkBox.setForeground(table.getForeground());
41
            }
42
            this.chkBox.setSelected((value != null && ((Boolean) value)));
43

    
44
            if (hasFocus) {
45
                this.chkBox.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
46
            } else {
47
                this.chkBox.setBorder(noFocusBorder);
48
            }
49
        } catch (Exception e) {
50
            
51
        }
52

    
53
        return this;
54
    }
55
}