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 @ 44263
History | View | Annotate | Download (3.75 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.ImageIcon; |
7 |
import org.gvsig.expressionevaluator.swing.Element; |
8 |
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig; |
9 |
import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
10 |
import org.gvsig.tools.swing.api.Component; |
11 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
12 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
13 |
import org.slf4j.Logger; |
14 |
import org.slf4j.LoggerFactory; |
15 |
|
16 |
/**
|
17 |
*
|
18 |
* @author jjdelcerro
|
19 |
*/
|
20 |
public abstract class AbstractElement implements Element { |
21 |
|
22 |
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractElement.class); |
23 |
|
24 |
final Object value; |
25 |
final String iconName; |
26 |
final ImageIcon icon; |
27 |
private String name; |
28 |
private ExpressionBuilderConfig config;
|
29 |
|
30 |
protected AbstractElement(String name) { |
31 |
this(name, name, null); |
32 |
} |
33 |
|
34 |
protected AbstractElement(String name, Object value) { |
35 |
this(name, value, null); |
36 |
} |
37 |
|
38 |
protected AbstractElement(String name, Object value, String iconName) { |
39 |
if( name == null ) { |
40 |
this.name = Objects.toString(value);
|
41 |
} else {
|
42 |
this.name = name;
|
43 |
} |
44 |
if( value == null ) { |
45 |
this.value = name;
|
46 |
} else {
|
47 |
this.value = value;
|
48 |
} |
49 |
this.iconName = iconName;
|
50 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
51 |
if( theme.exists(iconName) ) {
|
52 |
this.icon = theme.get(iconName);
|
53 |
} else if( this instanceof GroupElement ) { |
54 |
this.icon = theme.get("expressionbuilder-element-group"); |
55 |
} else {
|
56 |
this.icon = theme.get("expressionbuilder-element"); |
57 |
} |
58 |
} |
59 |
|
60 |
@Override
|
61 |
public Element setConfig(ExpressionBuilderConfig config) { |
62 |
this.config = config;
|
63 |
return this; |
64 |
} |
65 |
|
66 |
@Override
|
67 |
public ExpressionBuilderConfig getConfig() {
|
68 |
return this.config; |
69 |
} |
70 |
|
71 |
@Override
|
72 |
public String getName() { |
73 |
return this.name; |
74 |
} |
75 |
|
76 |
protected void setName(String name) { |
77 |
this.name = name;
|
78 |
} |
79 |
|
80 |
@Override
|
81 |
public Object getValue() { |
82 |
return this.value; |
83 |
} |
84 |
|
85 |
@Override
|
86 |
public Collection<Element> getValues() { |
87 |
return Collections.EMPTY_LIST; |
88 |
} |
89 |
|
90 |
@Override
|
91 |
public boolean hasMoreValues() { |
92 |
return false; |
93 |
} |
94 |
|
95 |
@Override
|
96 |
public String getRenderedValue() { |
97 |
return Objects.toString(this.value); |
98 |
} |
99 |
|
100 |
@Override
|
101 |
public String getDescription() { |
102 |
return null; |
103 |
} |
104 |
|
105 |
@Override
|
106 |
public String getLabel() { |
107 |
return Objects.toString(this.value, ""); |
108 |
} |
109 |
|
110 |
@Override
|
111 |
@SuppressWarnings("StringEquality") |
112 |
public int compareTo(Object other) { |
113 |
String otherLabel = null; |
114 |
if( other!=null ) { |
115 |
otherLabel = other.toString(); |
116 |
} |
117 |
String thisLabel = this.getLabel(); |
118 |
if (thisLabel== otherLabel) {
|
119 |
return 0; |
120 |
} else if (thisLabel== null) { |
121 |
return -1; |
122 |
} else if (otherLabel == null) { |
123 |
return 1; |
124 |
} |
125 |
return thisLabel.compareTo(otherLabel);
|
126 |
} |
127 |
|
128 |
@Override
|
129 |
public String getIconName() { |
130 |
return iconName;
|
131 |
} |
132 |
|
133 |
@Override
|
134 |
public ImageIcon getIcon() { |
135 |
return this.icon; |
136 |
} |
137 |
|
138 |
@Override
|
139 |
public void used() { |
140 |
} |
141 |
|
142 |
@Override
|
143 |
public Component getAditionalPanel(JExpressionBuilder expressionBuilder) { |
144 |
return null; |
145 |
} |
146 |
|
147 |
@Override
|
148 |
public String toString() { |
149 |
return this.getLabel(); |
150 |
} |
151 |
|
152 |
@Override
|
153 |
public void reload() { |
154 |
} |
155 |
|
156 |
@Override
|
157 |
public boolean isEnabled() { |
158 |
return true; |
159 |
} |
160 |
|
161 |
} |