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 @ 44198
History | View | Annotate | Download (2.79 KB)
1 | 43321 | fdiaz | /* 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 | |||
33 | /**
|
||
34 | * @author fdiaz
|
||
35 | *
|
||
36 | */
|
||
37 | public class TiledCellRenderer extends JPanel implements TableCellRenderer { |
||
38 | |||
39 | /**
|
||
40 | *
|
||
41 | */
|
||
42 | private static final long serialVersionUID = 3875203211014535067L; |
||
43 | |||
44 | private JCheckBox checkBox; |
||
45 | |||
46 | /**
|
||
47 | *
|
||
48 | */
|
||
49 | public TiledCellRenderer() {
|
||
50 | super(new BorderLayout()); //new FlowLayout(FlowLayout.CENTER, 0, 0)); |
||
51 | checkBox = new JCheckBox(); |
||
52 | checkBox.setOpaque(false);
|
||
53 | checkBox.setHorizontalAlignment(JCheckBox.CENTER);
|
||
54 | add(checkBox, BorderLayout.CENTER);
|
||
55 | } |
||
56 | |||
57 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, |
||
58 | int row, int column) { |
||
59 | if (isSelected) {
|
||
60 | checkBox.setForeground(table.getSelectionForeground()); |
||
61 | checkBox.setBackground(table.getSelectionBackground()); |
||
62 | setForeground(table.getSelectionForeground()); |
||
63 | setBackground(table.getSelectionBackground()); |
||
64 | } else {
|
||
65 | checkBox.setForeground(table.getForeground()); |
||
66 | checkBox.setBackground(table.getBackground()); |
||
67 | setForeground(table.getForeground()); |
||
68 | setBackground(table.getBackground()); |
||
69 | } |
||
70 | |||
71 | boolean booleanValue = ((Boolean) value).booleanValue(); |
||
72 | boolean cellEditable = table.getModel().isCellEditable(row, column);
|
||
73 | if(!cellEditable && !booleanValue){
|
||
74 | checkBox.setVisible(false);
|
||
75 | } else {
|
||
76 | checkBox.setVisible(true);
|
||
77 | } |
||
78 | checkBox.setEnabled(cellEditable); |
||
79 | checkBox.setSelected((value != null && booleanValue));
|
||
80 | return this; |
||
81 | } |
||
82 | } |