Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / featuretype / FeatureAttributeListCellRenderer.java @ 45162

History | View | Annotate | Download (1.61 KB)

1
package org.gvsig.fmap.dal.swing.impl.featuretype;
2

    
3
import java.awt.Component;
4
import javax.swing.DefaultListCellRenderer;
5
import javax.swing.JLabel;
6
import javax.swing.JList;
7
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
8
import org.gvsig.tools.swing.api.ToolsSwingLocator;
9
import org.gvsig.tools.swing.icontheme.IconTheme;
10

    
11
/**
12
 *
13
 * @author jjdelcerro
14
 */
15
public class FeatureAttributeListCellRenderer 
16
        extends DefaultListCellRenderer
17
    {
18

    
19
    private final IconTheme iconTheme;
20

    
21
    public FeatureAttributeListCellRenderer() {
22
        this.iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
23
    }
24
    
25
    @Override
26
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
27
        JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
28
        FeatureAttributeDescriptor attrdesc = (FeatureAttributeDescriptor) value;
29
        String theLabel;
30
        try {
31
            if (attrdesc.hasLabel()) {
32
                theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), attrdesc.getName());
33
            } else {
34
                theLabel = attrdesc.getName();
35
            }
36
            label.setText(theLabel);
37
            String iconName = attrdesc.getDataType().getIconName();
38
            if (iconTheme.exists(iconName)) {
39
                label.setIcon(iconTheme.get(iconName));
40
            } else {
41
                label.setIcon(null);
42
            }
43
        } catch (Exception ex) {
44
            label.setText("#ERROR#");
45
        }
46
        return label;
47
    }
48
    
49
}