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 / app / gui / command / ColorRenderer.java @ 40558

History | View | Annotate | Download (2.65 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.app.gui.command;
25
import java.awt.Color;
26
import java.awt.Component;
27

    
28
import javax.swing.BorderFactory;
29
import javax.swing.JLabel;
30
import javax.swing.JTable;
31
import javax.swing.border.Border;
32
import javax.swing.table.TableCellRenderer;
33

    
34
public class ColorRenderer extends JLabel
35
                           implements TableCellRenderer {
36
    Border unselectedBorder = null;
37
    Border selectedBorder = null;
38
    boolean isBordered = true;
39

    
40
    public ColorRenderer(boolean isBordered) {
41
        this.isBordered = isBordered;
42
        setOpaque(true); //MUST do this for background to show up.
43
    }
44

    
45
    public Component getTableCellRendererComponent(
46
                            JTable table, Object color,
47
                            boolean isSelected, boolean hasFocus,
48
                            int row, int column) {
49
        Color newColor = (Color)color;
50
        setBackground(newColor);
51
        if (isBordered) {
52
            if (isSelected) {
53
                if (selectedBorder == null) {
54
                    selectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
55
                                              table.getSelectionBackground());
56
                }
57
                setBorder(selectedBorder);
58
            } else {
59
                if (unselectedBorder == null) {
60
                    unselectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
61
                                              table.getBackground());
62
                }
63
                setBorder(unselectedBorder);
64
            }
65
        }
66

    
67
        setToolTipText("RGB value: " + newColor.getRed() + ", "
68
                                     + newColor.getGreen() + ", "
69
                                     + newColor.getBlue());
70
        return this;
71
    }
72
}