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 / JLabelCellRendererWithTextAsToolTipText.java @ 40561

History | View | Annotate | Download (2.7 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.JLabel;
31
import javax.swing.JList;
32
import javax.swing.ListCellRenderer;
33
/**
34
 * This class allows render a JLabel in a Cell of other graphic component (as a JList) and
35
 * if mouse is on this cell, a tool tip text with the text value will be shown
36
 * 
37
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
38
 */
39
public class JLabelCellRendererWithTextAsToolTipText extends JLabelCellRenderer implements Serializable {
40
        private static final long serialVersionUID = 4799667459274027212L;
41

    
42
        /* (non-Javadoc)
43
         * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
44
         */
45
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
46
        /* The DefaultListCellRenderer class will take care of
47
         * the JLabels text property, it's foreground and background
48
         * colors, and so on.
49
         */
50
        super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
51
                
52
                // Set the text property, background and foreground color
53
        if (value instanceof JLabel) {
54
                setText(((JLabel)value).getText());
55
                    setBackground(((JLabel)value).getBackground());
56
                    
57
                    if (isSelected)
58
                            setForeground(Color.red);
59
                    else
60
                            setForeground(((JLabel)value).getForeground());
61
        }
62
        
63
                return this;
64
        }
65
        
66
        /*
67
         *  (non-Javadoc)
68
         * @see javax.swing.JLabel#setText(java.lang.String)
69
         */
70
        public void setText(String text) {
71
                super.setText(text);
72
                
73
                // Set as tool tip text for this cell, it's text value
74
                if (text != null)
75
                        super.setToolTipText(text);
76
        }
77
}