svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / table / models / TableColorButtonColumnRenderer.java @ 40561
History | View | Annotate | Download (2.38 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.table.models; |
25 |
|
26 |
import java.awt.Color; |
27 |
import java.awt.Component; |
28 |
|
29 |
import javax.swing.BorderFactory; |
30 |
import javax.swing.JLabel; |
31 |
import javax.swing.JTable; |
32 |
import javax.swing.border.Border; |
33 |
import javax.swing.table.TableCellRenderer; |
34 |
/**
|
35 |
* Componente tabla
|
36 |
*
|
37 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
38 |
*/
|
39 |
public class TableColorButtonColumnRenderer extends JLabel implements TableCellRenderer { |
40 |
private static final long serialVersionUID = 4792441413562824229L; |
41 |
Border unselectedBorder = null; |
42 |
Border selectedBorder = null; |
43 |
boolean isBordered = true; |
44 |
|
45 |
public TableColorButtonColumnRenderer(boolean isBordered) { |
46 |
this.isBordered = isBordered;
|
47 |
setOpaque(true);
|
48 |
} |
49 |
|
50 |
public Component getTableCellRendererComponent(JTable table, Object color, boolean isSelected, boolean hasFocus, int row, int column) { |
51 |
if (!(color instanceof Color)) |
52 |
return this; |
53 |
|
54 |
Color newColor = (Color) color; |
55 |
setBackground(newColor); |
56 |
if (isBordered) {
|
57 |
if (isSelected) {
|
58 |
if (selectedBorder == null) { |
59 |
selectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5, table.getSelectionBackground()); |
60 |
} |
61 |
setBorder(selectedBorder); |
62 |
} else {
|
63 |
if (unselectedBorder == null) { |
64 |
unselectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5, table.getBackground()); |
65 |
} |
66 |
setBorder(unselectedBorder); |
67 |
} |
68 |
} |
69 |
|
70 |
setToolTipText("RGB value: " + newColor.getRed() + ", " + newColor.getGreen() + ", " + newColor.getBlue()); |
71 |
return this; |
72 |
} |
73 |
} |