Statistics
| Revision:

svn-gvsig-desktop / tags / v1_11_0_Build_1306 / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / gui / panels / utils / SelectedLayersListCellRenderer.java @ 35731

History | View | Annotate | Download (3.51 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Prodevelop Integraci?n de Tecnolog?as SL
34
 *   Conde Salvatierra de ?lava , 34-10
35
 *   46004 Valencia
36
 *   Spain
37
 *
38
 *   +34 963 510 612
39
 *   +34 963 510 968
40
 *   gis@prodevelop.es
41
 *   http://www.prodevelop.es
42
 */
43
package es.prodevelop.cit.gvsig.arcims.gui.panels.utils;
44

    
45
import java.awt.Component;
46

    
47
import javax.swing.DefaultListCellRenderer;
48
import javax.swing.Icon;
49
import javax.swing.JComponent;
50
import javax.swing.JList;
51
import javax.swing.UIManager;
52
import javax.swing.border.Border;
53
import javax.swing.border.EmptyBorder;
54

    
55

    
56
/**
57
 * This class sets the tool tips in a JList component.
58
 *
59
 * @author jldominguez
60
 */
61
public class SelectedLayersListCellRenderer extends DefaultListCellRenderer {
62
    private static final Border SAFE_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1,
63
            1);
64
    private static final long serialVersionUID = 0;
65

    
66
    public SelectedLayersListCellRenderer() {
67
        super();
68
    }
69

    
70
    /**
71
     * Sets special graphic properties (colors, and tool tips) in list elements
72
     * and returns <tt>this</tt>.
73
     */
74
    public Component getListCellRendererComponent(JList list, Object value,
75
        int index, boolean isSelected, boolean cellHasFocus) {
76
        JComponent jc;
77
        LayersListElement lle;
78
        setComponentOrientation(list.getComponentOrientation());
79

    
80
        if (isSelected) {
81
            setBackground(list.getSelectionBackground());
82
            setForeground(list.getSelectionForeground());
83
        }
84
        else {
85
            setBackground(list.getBackground());
86
            setForeground(list.getForeground());
87
        }
88

    
89
        if (value instanceof Icon) {
90
            setIcon((Icon) value);
91
            setText("");
92
        }
93
        else {
94
            setIcon(null);
95
            setText((value == null) ? "" : value.toString());
96
        }
97

    
98
        setEnabled(list.isEnabled());
99
        setFont(list.getFont());
100
        setBorder((cellHasFocus)
101
            ? UIManager.getBorder("List.focusCellHighlightBorder")
102
            : getNoFocusBorder());
103

    
104
        // Set the specific tool tip:
105
        if (value instanceof LayersListElement) {
106
            lle = (LayersListElement) value;
107
            jc = (JComponent) this;
108
            jc.setToolTipText(lle.toolTipText());
109
        }
110

    
111
        return this;
112
    }
113

    
114
    private static Border getNoFocusBorder() {
115
        if (System.getSecurityManager() != null) {
116
            return SAFE_NO_FOCUS_BORDER;
117
        }
118
        else {
119
            return noFocusBorder;
120
        }
121
    }
122
}