Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / utils / ColorRenderer.java @ 9828

History | View | Annotate | Download (3.48 KB)

1 312 fernando
/*
2
 * Created on 15-mar-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7 1103 fjp
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47 312 fernando
package com.iver.cit.gvsig.gui.utils;
48
49
import java.awt.Color;
50
import java.awt.Component;
51
52
import javax.swing.BorderFactory;
53
import javax.swing.JLabel;
54
import javax.swing.JTable;
55
import javax.swing.border.Border;
56
import javax.swing.table.TableCellRenderer;
57
58
59
/**
60
 * DOCUMENT ME!
61
 *
62
 * @author vcn
63
 */
64
public class ColorRenderer extends JLabel implements TableCellRenderer {
65
    Border unselectedBorder = null;
66
    Border selectedBorder = null;
67
    boolean isBordered = true;
68
69
    /**
70
     * Creates a new ColorRenderer object.
71
     *
72
     * @param isBordered DOCUMENT ME!
73
     */
74
    public ColorRenderer(boolean isBordered) {
75
        this.isBordered = isBordered;
76
        setOpaque(true); //MUST do this for background to show up.
77
    }
78
79
    /**
80
     * DOCUMENT ME!
81
     *
82
     * @param table DOCUMENT ME!
83
     * @param color DOCUMENT ME!
84
     * @param isSelected DOCUMENT ME!
85
     * @param hasFocus DOCUMENT ME!
86
     * @param row DOCUMENT ME!
87
     * @param column DOCUMENT ME!
88
     *
89
     * @return DOCUMENT ME!
90
     */
91
    public Component getTableCellRendererComponent(JTable table, Object color,
92
        boolean isSelected, boolean hasFocus, int row, int column) {
93
        Color newColor = (Color) color;
94
        setBackground(newColor);
95
96
        //JLabel boton=new JLabel("si");
97
        //boton.setBackground(new Color(10,10,100));
98
        //add(boton);
99
        //System.out.println("dentro de Color Renderer");
100
        if (isBordered) {
101
            if (isSelected) {
102
                if (selectedBorder == null) {
103
                    selectedBorder = BorderFactory.createMatteBorder(2, 5, 2,
104
                            5, table.getSelectionBackground());
105
                }
106
107
                setBorder(selectedBorder);
108
            } else {
109
                if (unselectedBorder == null) {
110
                    unselectedBorder = BorderFactory.createMatteBorder(2, 5, 2,
111
                            5, table.getBackground());
112
                }
113
114
                setBorder(unselectedBorder);
115
            }
116
        }
117
118
      /*  setToolTipText("RGB value: " + newColor.getRed() + ", " +
119
            newColor.getGreen() + ", " + newColor.getBlue());
120
*/
121
        return this;
122
    }
123
}