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 / DefaultFeatureAttributeListCellRenderer.java @ 44644
History | View | Annotate | Download (1.48 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 DefaultFeatureAttributeListCellRenderer |
16 |
extends DefaultListCellRenderer |
17 |
{ |
18 |
|
19 |
private final IconTheme iconTheme; |
20 |
|
21 |
public DefaultFeatureAttributeListCellRenderer() {
|
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 |
if( attrdesc.hasLabel() ) {
|
31 |
theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), attrdesc.getName()); |
32 |
} else {
|
33 |
theLabel = attrdesc.getName(); |
34 |
} |
35 |
label.setText(theLabel); |
36 |
String iconName = attrdesc.getDataType().getIconName();
|
37 |
if( iconTheme.exists(iconName) ) {
|
38 |
label.setIcon(iconTheme.get(iconName)); |
39 |
} else {
|
40 |
label.setIcon(null);
|
41 |
} |
42 |
return label;
|
43 |
} |
44 |
|
45 |
} |