Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.swing / org.gvsig.expressionevaluator.swing.api / src / main / java / org / gvsig / expressionevaluator / swing / spi / AbstractElement.java @ 44259

History | View | Annotate | Download (3.44 KB)

1
package org.gvsig.expressionevaluator.swing.spi;
2

    
3
import java.util.Objects;
4
import javax.swing.ImageIcon;
5
import org.gvsig.expressionevaluator.swing.Element;
6
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig;
7
import org.gvsig.expressionevaluator.swing.JExpressionBuilder;
8
import org.gvsig.tools.swing.api.Component;
9
import org.gvsig.tools.swing.api.ToolsSwingLocator;
10
import org.gvsig.tools.swing.icontheme.IconTheme;
11
import org.slf4j.Logger;
12
import org.slf4j.LoggerFactory;
13

    
14
/**
15
 *
16
 * @author jjdelcerro
17
 */
18
public abstract class AbstractElement implements Element {
19

    
20
    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractElement.class);
21
    
22
    final Object value;
23
    final String iconName;
24
    final ImageIcon icon;
25
    private final String name;
26
    private ExpressionBuilderConfig config;
27

    
28
    protected AbstractElement(String name) {
29
        this(name, name, null);
30
    }
31
    
32
    protected AbstractElement(String name, Object value) {
33
        this(name, value, null);
34
    }
35
    
36
    protected AbstractElement(String name, Object value, String iconName) {
37
        if( name == null ) {
38
            this.name = Objects.toString(value);
39
        } else {
40
            this.name = name;
41
        }
42
        if( value == null ) {
43
            this.value = name;
44
        } else {
45
            this.value = value;
46
        }
47
        this.iconName = iconName;
48
        IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent();
49
        if( theme.exists(iconName) ) {
50
            this.icon = theme.get(iconName);
51
        } else if( this instanceof GroupElement ) {
52
            this.icon = theme.get("expressionbuilder-element-group");
53
        } else {
54
            this.icon = theme.get("expressionbuilder-element");
55
        }
56
    }
57

    
58
    @Override
59
    public Element setConfig(ExpressionBuilderConfig config) {
60
        this.config = config;
61
        return this;
62
    }
63
    
64
    @Override
65
    public ExpressionBuilderConfig getConfig() {
66
        return this.config;
67
    }
68
    
69
    @Override
70
    public String getName() {
71
        return this.name;
72
    }
73
    
74
    @Override
75
    public Object getValue() {
76
        return this.value;
77
    }
78

    
79
    @Override
80
    public String getRenderedValue() {
81
        return Objects.toString(this.value);
82
    }
83

    
84
    @Override
85
    public String getDescription() {
86
        return null;
87
    }
88

    
89
    @Override
90
    public String getLabel() {
91
        return Objects.toString(this.value, "");
92
    }
93

    
94
    @Override
95
    @SuppressWarnings("StringEquality")
96
    public int compareTo(Object other) {
97
        String otherLabel = null;
98
        if( other!=null ) {
99
            otherLabel = other.toString();
100
        }
101
        String thisLabel = this.getLabel();
102
        if (thisLabel== otherLabel) {
103
            return 0;
104
        } else if (thisLabel== null) {
105
            return -1;
106
        } else if (otherLabel == null) {
107
            return 1;
108
        }
109
        return thisLabel.compareTo(otherLabel);        
110
    }
111
    
112
    @Override
113
    public String getIconName() {
114
        return iconName;
115
    }
116
    
117
    @Override
118
    public ImageIcon getIcon() {
119
        return this.icon;
120
    }
121

    
122
    @Override
123
    public void used() {
124
    }
125
    
126
    @Override
127
    public Component getAditionalPanel(JExpressionBuilder expressionBuilder) {
128
        return null;
129
    }
130

    
131
    @Override
132
    public String toString() {
133
        return this.getLabel();
134
    }
135

    
136
    @Override
137
    public void reload() {
138
    }
139

    
140
    @Override
141
    public boolean isEnabled() {
142
        return true;
143
    }
144

    
145
}