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 @ 44338

History | View | Annotate | Download (3.79 KB)

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

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

    
17
/**
18
 *
19
 * @author jjdelcerro
20
 */
21
public abstract class AbstractElement implements Element {
22

    
23
    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractElement.class);
24
    
25
    private final Object value;
26
    private final String iconName;
27
    protected Icon icon;
28
    private String name;
29
    private ExpressionBuilderConfig config;
30

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

    
61
    @Override
62
    public Element setConfig(ExpressionBuilderConfig config) {
63
        this.config = config;
64
        return this;
65
    }
66
    
67
    @Override
68
    public ExpressionBuilderConfig getConfig() {
69
        return this.config;
70
    }
71
    
72
    @Override
73
    public String getName() {
74
        return this.name;
75
    }
76
    
77
    protected void setName(String name) {
78
        this.name = name;
79
    }
80
    
81
    @Override
82
    public Object getValue() {
83
        return this.value;
84
    }
85

    
86
    @Override
87
    public Collection<Element> getValues() {
88
        return Collections.EMPTY_LIST;
89
    }
90

    
91
    @Override
92
    public boolean hasMoreValues() {
93
        return false;
94
    }
95
    
96
    @Override
97
    public String getRenderedValue() {
98
        return Objects.toString(this.value);
99
    }
100

    
101
    @Override
102
    public String getDescription() {
103
        return null;
104
    }
105

    
106
    @Override
107
    public String getLabel() {
108
        return Objects.toString(this.value, "");
109
    }
110

    
111
    @Override
112
    @SuppressWarnings("StringEquality")
113
    public int compareTo(Object other) {
114
        String otherLabel = null;
115
        if( other!=null ) {
116
            otherLabel = other.toString();
117
        }
118
        String thisLabel = this.getLabel();
119
        if (thisLabel== otherLabel) {
120
            return 0;
121
        } else if (thisLabel== null) {
122
            return -1;
123
        } else if (otherLabel == null) {
124
            return 1;
125
        }
126
        return thisLabel.compareTo(otherLabel);        
127
    }
128
    
129
    @Override
130
    public String getIconName() {
131
        return iconName;
132
    }
133
    
134
    @Override
135
    public Icon getIcon() {
136
        return this.icon;
137
    }
138

    
139
    @Override
140
    public void used() {
141
    }
142
    
143
    @Override
144
    public Component getAditionalPanel(JExpressionBuilder expressionBuilder) {
145
        return null;
146
    }
147

    
148
    @Override
149
    public String toString() {
150
        return this.getLabel();
151
    }
152

    
153
    @Override
154
    public void reload() {
155
    }
156

    
157
    @Override
158
    public boolean isEnabled() {
159
        return true;
160
    }
161

    
162
}