Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / swing / cellrenderers / StringTableCellRenderer.java @ 40561

History | View | Annotate | Download (2.56 KB)

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

    
26
import java.awt.Component;
27
import java.awt.FlowLayout;
28

    
29
import javax.swing.BorderFactory;
30
import javax.swing.JCheckBox;
31
import javax.swing.JPanel;
32
import javax.swing.JTable;
33
import javax.swing.JTextField;
34
import javax.swing.border.MatteBorder;
35
import javax.swing.table.DefaultTableCellRenderer;
36

    
37
public class StringTableCellRenderer extends DefaultTableCellRenderer {
38
          private static final long serialVersionUID = 2121615214282741840L;
39

    
40
                private JTextField txt;
41

    
42
                private boolean isBordered;
43
                private MatteBorder selectedBorder;
44
                private MatteBorder unselectedBorder;
45

    
46

    
47

    
48
                public JTextField getTextField() {
49
                        return txt;
50
                }
51

    
52
                public Component getTableCellRendererComponent(JTable table, Object value,
53
                                boolean isSelected, boolean hasFocus, int row, int column) {
54
                        if (value == null)
55
                                return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
56

    
57
                        if (isBordered) {
58
                                if (isSelected) {
59
                                        if (selectedBorder == null) {
60
                                                selectedBorder = BorderFactory.createMatteBorder(2, 5, 2,
61
                                                                5, table.getSelectionBackground());
62
                                        }
63

    
64
                                        setBorder(selectedBorder);
65
                                } else {
66
                                        if (unselectedBorder == null) {
67
                                                unselectedBorder = BorderFactory.createMatteBorder(2, 5, 2,
68
                                                                5, table.getBackground());
69
                                        }
70

    
71
                                        setBorder(unselectedBorder);
72
                                }
73
                        }
74
                        try {
75
                                String v = (String) value;
76
                                txt = new JTextField(v);
77
                                txt.setBackground(table.getBackground());
78
                                return txt;
79
                        } catch (ClassCastException ccEx) {
80
                                throw new RuntimeException("Trying to use a Boolean cell renderer with a non-Boolean datatype");
81
                        }
82

    
83
                }
84

    
85
        }