Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / TiledCellRenderer.java @ 45810

History | View | Annotate | Download (3.1 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2017 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.dal.serverexplorer.filesystem.swing;
24

    
25
import java.awt.BorderLayout;
26
import java.awt.Component;
27

    
28
import javax.swing.JCheckBox;
29
import javax.swing.JPanel;
30
import javax.swing.JTable;
31
import javax.swing.table.TableCellRenderer;
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

    
35
/**
36
 * @author fdiaz
37
 *
38
 */
39
public class TiledCellRenderer extends JPanel implements TableCellRenderer {
40

    
41
    /**
42
     *
43
     */
44
    private static final long serialVersionUID = 3875203211014535067L;
45

    
46
    private JCheckBox checkBox;
47
    
48
    private static final Logger LOGGER = LoggerFactory.getLogger(TiledCellRenderer.class);
49

    
50
    /**
51
     *
52
     */
53
    public TiledCellRenderer() {
54
        super(new BorderLayout()); //new FlowLayout(FlowLayout.CENTER, 0, 0));
55
        checkBox = new JCheckBox();
56
        checkBox.setOpaque(false);
57
        checkBox.setHorizontalAlignment(JCheckBox.CENTER);
58
        add(checkBox, BorderLayout.CENTER);
59
    }
60

    
61
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
62
        int row, int column) {
63
        if (isSelected) {
64
            checkBox.setForeground(table.getSelectionForeground());
65
            checkBox.setBackground(table.getSelectionBackground());
66
            setForeground(table.getSelectionForeground());
67
            setBackground(table.getSelectionBackground());
68
        } else {
69
            checkBox.setForeground(table.getForeground());
70
            checkBox.setBackground(table.getBackground());
71
            setForeground(table.getForeground());
72
            setBackground(table.getBackground());
73
        }
74
         boolean booleanValue;
75
        try {
76
            booleanValue = ((Boolean) value).booleanValue();
77
        } catch (Exception ex) {
78
            booleanValue = false;
79
//            LOGGER.warn("Value is null", ex);
80
        }
81
        boolean cellEditable = table.getModel().isCellEditable(row, column);
82
        if(!cellEditable && !booleanValue){
83
            checkBox.setVisible(false);
84
        } else {
85
            checkBox.setVisible(true);
86
        }
87
        checkBox.setEnabled(cellEditable);
88
        checkBox.setSelected((value != null && booleanValue));
89
        return this;
90
    }
91
}