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 / FeatureAttributeListCellRendererImpl.java @ 46485
History | View | Annotate | Download (3.54 KB)
1 | 44644 | jjdelcerro | 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 | 45739 | jjdelcerro | import org.gvsig.fmap.dal.DataManager; |
8 | 44644 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
9 | 46485 | fdiaz | import org.gvsig.fmap.dal.swing.DALSwingLocator; |
10 | import org.gvsig.fmap.dal.swing.DataSwingManager; |
||
11 | 45739 | jjdelcerro | import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributeListCellRenderer; |
12 | 44644 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
13 | import org.gvsig.tools.swing.icontheme.IconTheme; |
||
14 | 45739 | jjdelcerro | import org.gvsig.tools.util.LabeledValue; |
15 | 44644 | jjdelcerro | |
16 | /**
|
||
17 | *
|
||
18 | * @author jjdelcerro
|
||
19 | */
|
||
20 | 45739 | jjdelcerro | public class FeatureAttributeListCellRendererImpl |
21 | 44644 | jjdelcerro | extends DefaultListCellRenderer |
22 | 45739 | jjdelcerro | implements FeatureAttributeListCellRenderer
|
23 | 44644 | jjdelcerro | { |
24 | |||
25 | private final IconTheme iconTheme; |
||
26 | 46485 | fdiaz | private Integer useLabels; |
27 | private final DataSwingManager dalSwingManager; |
||
28 | 44644 | jjdelcerro | |
29 | 45739 | jjdelcerro | public FeatureAttributeListCellRendererImpl() {
|
30 | 44644 | jjdelcerro | this.iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
|
31 | 46485 | fdiaz | this.useLabels = null; |
32 | this.dalSwingManager = DALSwingLocator.getDataSwingManager();
|
||
33 | 44644 | jjdelcerro | } |
34 | |||
35 | @Override
|
||
36 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
||
37 | JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
||
38 | 45739 | jjdelcerro | if( value == null ) { |
39 | return label;
|
||
40 | } |
||
41 | FeatureAttributeDescriptor attrdesc; |
||
42 | if( value instanceof LabeledValue ) { |
||
43 | attrdesc = ((LabeledValue<FeatureAttributeDescriptor>)value).getValue(); |
||
44 | } else {
|
||
45 | attrdesc = (FeatureAttributeDescriptor) value; |
||
46 | 45903 | fdiaz | } |
47 | String theLabel = ""; |
||
48 | String iconName = null; |
||
49 | 45162 | omartinez | try {
|
50 | 45903 | fdiaz | if(attrdesc != null) { |
51 | 46485 | fdiaz | if(this.useLabels == null) { |
52 | theLabel = dalSwingManager.getAttributeDescriptorLabel(attrdesc); |
||
53 | } else {
|
||
54 | switch (this.useLabels) { |
||
55 | case DataManager.USE_LABELS_NO:
|
||
56 | 45903 | fdiaz | theLabel = attrdesc.getName(); |
57 | 46485 | fdiaz | break;
|
58 | case DataManager.USE_LABELS_YES:
|
||
59 | if (attrdesc.hasLabel()) {
|
||
60 | theLabel = attrdesc.getLocalizedLabel(); |
||
61 | } else {
|
||
62 | theLabel = attrdesc.getName(); |
||
63 | } |
||
64 | break;
|
||
65 | case DataManager.USE_LABELS_BOTH:
|
||
66 | default:
|
||
67 | if (attrdesc.hasLabel()) {
|
||
68 | theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), attrdesc.getName()); |
||
69 | } else {
|
||
70 | theLabel = attrdesc.getName(); |
||
71 | } |
||
72 | break;
|
||
73 | } |
||
74 | 45903 | fdiaz | } |
75 | iconName = attrdesc.getDataType().getIconName(); |
||
76 | 45162 | omartinez | } |
77 | label.setText(theLabel); |
||
78 | if (iconTheme.exists(iconName)) {
|
||
79 | label.setIcon(iconTheme.get(iconName)); |
||
80 | } else {
|
||
81 | label.setIcon(null);
|
||
82 | } |
||
83 | } catch (Exception ex) { |
||
84 | label.setText("#ERROR#");
|
||
85 | 44644 | jjdelcerro | } |
86 | return label;
|
||
87 | } |
||
88 | 45739 | jjdelcerro | |
89 | @Override
|
||
90 | 46485 | fdiaz | public void setUseLabels(Integer useLabels) { |
91 | 45739 | jjdelcerro | this.useLabels = useLabels;
|
92 | } |
||
93 | |||
94 | @Override
|
||
95 | 46485 | fdiaz | public Integer getUseLabels() { |
96 | 45739 | jjdelcerro | return this.useLabels; |
97 | } |
||
98 | 44644 | jjdelcerro | |
99 | } |