Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / javax / swing / jLabelCellRenderer / JLabelCellRenderer.java @ 40561

History | View | Annotate | Download (2.39 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.javax.swing.jLabelCellRenderer;
25

    
26
import java.awt.Color;
27
import java.awt.Component;
28
import java.io.Serializable;
29

    
30
import javax.swing.DefaultListCellRenderer;
31
import javax.swing.JLabel;
32
import javax.swing.JList;
33
import javax.swing.ListCellRenderer;
34

    
35
/**
36
 * This class allows render a JLabel in a Cell of other graphic component (as a JList)
37
 * 
38
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
39
 */
40
public class JLabelCellRenderer extends DefaultListCellRenderer implements Serializable {
41
        private static final long serialVersionUID = -3820198983465837422L;
42

    
43
        /* (non-Javadoc)
44
         * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
45
         */
46
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
47
        /* The DefaultListCellRenderer class will take care of
48
         * the JLabels text property, it's foreground and background
49
         * colors, and so on.
50
         */
51
        super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
52
                
53
                // Set the text property, background and foreground color
54
        if (value instanceof JLabel) {
55
                setText(((JLabel)value).getText());
56
                    setBackground(((JLabel)value).getBackground());
57
                    
58
                    if (isSelected)
59
                            setForeground(Color.red);
60
                    else
61
                            setForeground(((JLabel)value).getForeground());
62
        }
63

    
64
                return this;
65
        }
66
}