svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / gui / utils / ColorRenderer.java @ 40596
History | View | Annotate | Download (3.06 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 |
|
25 |
package org.gvsig.app.gui.utils; |
26 |
|
27 |
import java.awt.Color; |
28 |
import java.awt.Component; |
29 |
|
30 |
import javax.swing.BorderFactory; |
31 |
import javax.swing.JLabel; |
32 |
import javax.swing.JTable; |
33 |
import javax.swing.border.Border; |
34 |
import javax.swing.table.TableCellRenderer; |
35 |
|
36 |
|
37 |
/**
|
38 |
* DOCUMENT ME!
|
39 |
*
|
40 |
* @author vcn
|
41 |
*/
|
42 |
public class ColorRenderer extends JLabel implements TableCellRenderer { |
43 |
Border unselectedBorder = null; |
44 |
Border selectedBorder = null; |
45 |
boolean isBordered = true; |
46 |
|
47 |
/**
|
48 |
* Creates a new ColorRenderer object.
|
49 |
*
|
50 |
* @param isBordered DOCUMENT ME!
|
51 |
*/
|
52 |
public ColorRenderer(boolean isBordered) { |
53 |
this.isBordered = isBordered;
|
54 |
setOpaque(true); //MUST do this for background to show up. |
55 |
} |
56 |
|
57 |
/**
|
58 |
* DOCUMENT ME!
|
59 |
*
|
60 |
* @param table DOCUMENT ME!
|
61 |
* @param color DOCUMENT ME!
|
62 |
* @param isSelected DOCUMENT ME!
|
63 |
* @param hasFocus DOCUMENT ME!
|
64 |
* @param row DOCUMENT ME!
|
65 |
* @param column DOCUMENT ME!
|
66 |
*
|
67 |
* @return DOCUMENT ME!
|
68 |
*/
|
69 |
public Component getTableCellRendererComponent(JTable table, Object color, |
70 |
boolean isSelected, boolean hasFocus, int row, int column) { |
71 |
Color newColor = (Color) color; |
72 |
setBackground(newColor); |
73 |
|
74 |
//JLabel boton=new JLabel("si");
|
75 |
//boton.setBackground(new Color(10,10,100));
|
76 |
//add(boton);
|
77 |
//System.out.println("dentro de Color Renderer");
|
78 |
if (isBordered) {
|
79 |
if (isSelected) {
|
80 |
if (selectedBorder == null) { |
81 |
selectedBorder = BorderFactory.createMatteBorder(2, 5, 2, |
82 |
5, table.getSelectionBackground());
|
83 |
} |
84 |
|
85 |
setBorder(selectedBorder); |
86 |
} else {
|
87 |
if (unselectedBorder == null) { |
88 |
unselectedBorder = BorderFactory.createMatteBorder(2, 5, 2, |
89 |
5, table.getBackground());
|
90 |
} |
91 |
|
92 |
setBorder(unselectedBorder); |
93 |
} |
94 |
} |
95 |
|
96 |
/* setToolTipText("RGB value: " + newColor.getRed() + ", " +
|
97 |
newColor.getGreen() + ", " + newColor.getBlue());
|
98 |
*/
|
99 |
return this; |
100 |
} |
101 |
} |