Revision 44910 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/legend/impl/VectorialUniqueValueLegend.java
VectorialUniqueValueLegend.java | ||
---|---|---|
31 | 31 |
import java.util.Map; |
32 | 32 |
import java.util.Map.Entry; |
33 | 33 |
import java.util.TreeMap; |
34 |
import java.util.logging.Level; |
|
35 |
import org.apache.commons.lang3.ObjectUtils; |
|
36 |
import org.apache.commons.lang3.mutable.MutableObject; |
|
37 |
import org.gvsig.fmap.dal.DataTypeUtils; |
|
34 | 38 |
|
35 | 39 |
import org.slf4j.Logger; |
36 | 40 |
import org.slf4j.LoggerFactory; |
... | ... | |
45 | 49 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
46 | 50 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
47 | 51 |
import org.gvsig.tools.ToolsLocator; |
52 |
import org.gvsig.tools.dataTypes.Coercion; |
|
53 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
48 | 54 |
import org.gvsig.tools.dynobject.DynStruct; |
49 | 55 |
import org.gvsig.tools.persistence.PersistenceManager; |
50 | 56 |
import org.gvsig.tools.persistence.PersistentState; |
... | ... | |
94 | 100 |
setShapeType(shapeType); |
95 | 101 |
} |
96 | 102 |
|
103 |
@Override |
|
97 | 104 |
public void setShapeType(int shapeType) { |
98 | 105 |
if (this.shapeType != shapeType) { |
99 | 106 |
if(defaultSymbol==null || defaultSymbol.getSymbolType()!=shapeType){ |
... | ... | |
105 | 112 |
} |
106 | 113 |
} |
107 | 114 |
|
115 |
@Override |
|
108 | 116 |
public void setValueSymbolByID(int id, ISymbol symbol) { |
109 | 117 |
ISymbol old = (ISymbol)symbols.put(keys.get(id), symbol); |
110 | 118 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(old, symbol)); |
111 | 119 |
} |
112 | 120 |
|
121 |
@Override |
|
113 | 122 |
public Object[] getValues() { |
114 | 123 |
return symbols.keySet().toArray(new Object[0]); |
115 | 124 |
} |
116 | 125 |
|
126 |
@Override |
|
117 | 127 |
public void addSymbol(Object key, ISymbol symbol) { |
118 | 128 |
ISymbol resul; |
119 | 129 |
if (key == null) { |
... | ... | |
143 | 153 |
fireLegendClearEvent(new LegendClearEvent(olds)); |
144 | 154 |
} |
145 | 155 |
|
156 |
@Override |
|
146 | 157 |
public void clear() { |
147 | 158 |
keys.clear(); |
148 | 159 |
ISymbol[] olds = (ISymbol[])symbols.values().toArray(new ISymbol[0]); |
... | ... | |
153 | 164 |
fireLegendClearEvent(new LegendClearEvent(olds)); |
154 | 165 |
} |
155 | 166 |
|
167 |
@Override |
|
156 | 168 |
public String[] getDescriptions() { |
157 | 169 |
String[] descriptions = new String[symbols.size()]; |
158 | 170 |
ISymbol[] auxSym = getSymbols(); |
... | ... | |
164 | 176 |
return descriptions; |
165 | 177 |
} |
166 | 178 |
|
179 |
@Override |
|
167 | 180 |
public ISymbol[] getSymbols() { |
168 | 181 |
ISymbol[] symbolList; |
169 | 182 |
if (nullValueSymbol == null) { |
... | ... | |
183 | 196 |
} |
184 | 197 |
} |
185 | 198 |
|
199 |
@Override |
|
186 | 200 |
public void setClassifyingFieldNames(String[] fNames) { |
187 | 201 |
// TODO: Check if need more process |
188 | 202 |
super.setClassifyingFieldNames(fNames); |
... | ... | |
199 | 213 |
* @return S?mbolo. |
200 | 214 |
* @throws MapContextException |
201 | 215 |
*/ |
216 |
@Override |
|
202 | 217 |
public ISymbol getSymbolByFeature(Feature feat) throws MapContextException { |
203 | 218 |
|
204 | 219 |
Object val = null; |
... | ... | |
223 | 238 |
} |
224 | 239 |
|
225 | 240 |
|
241 |
@Override |
|
226 | 242 |
public ISymbol getDefaultSymbol() { |
227 | 243 |
|
228 | 244 |
if(defaultSymbol==null) { |
... | ... | |
232 | 248 |
return defaultSymbol; |
233 | 249 |
} |
234 | 250 |
|
251 |
@Override |
|
235 | 252 |
public void setDefaultSymbol(ISymbol s) { |
236 | 253 |
ISymbol mySymbol = defaultSymbol; |
237 | 254 |
|
... | ... | |
250 | 267 |
* |
251 | 268 |
* @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#getSymbolByValue(com.hardcode.gdbms.engine.values.Value) |
252 | 269 |
*/ |
270 |
@Override |
|
253 | 271 |
public ISymbol getSymbolByValue(Object key) { |
254 | 272 |
ISymbol symbol = null; |
255 | 273 |
if (key == null) { |
... | ... | |
265 | 283 |
|
266 | 284 |
} |
267 | 285 |
|
286 |
@Override |
|
268 | 287 |
public Object getSymbolKey(ISymbol symbol) { |
269 | 288 |
if (symbol != null) { |
270 | 289 |
for (Iterator<Entry<Object, ISymbol>> iterator = symbols.entrySet() |
... | ... | |
278 | 297 |
return null; |
279 | 298 |
} |
280 | 299 |
|
300 |
@Override |
|
281 | 301 |
public int getShapeType() { |
282 | 302 |
return shapeType; |
283 | 303 |
} |
284 | 304 |
|
305 |
@Override |
|
285 | 306 |
public void useDefaultSymbol(boolean b) { |
286 | 307 |
useDefaultSymbol = b; |
287 | 308 |
} |
... | ... | |
290 | 311 |
* Devuelve si se utiliza o no el resto de valores para representarse. |
291 | 312 |
* @return True si se utiliza el resto de valores. |
292 | 313 |
*/ |
314 |
@Override |
|
293 | 315 |
public boolean isUseDefaultSymbol() { |
294 | 316 |
return useDefaultSymbol; |
295 | 317 |
} |
296 | 318 |
|
319 |
@Override |
|
297 | 320 |
public void delSymbol(Object key) { |
298 | 321 |
keys.remove(key); |
299 | 322 |
|
... | ... | |
307 | 330 |
return getClass().getName(); |
308 | 331 |
} |
309 | 332 |
|
333 |
@Override |
|
310 | 334 |
public void replace(ISymbol oldSymbol, ISymbol newSymbol) { |
311 | 335 |
if (symbols.containsValue(oldSymbol)) { |
312 | 336 |
Iterator<Object> it = symbols.keySet().iterator(); |
... | ... | |
320 | 344 |
} |
321 | 345 |
} |
322 | 346 |
} |
347 |
@Override |
|
323 | 348 |
public Color[] getColorScheme() { |
324 | 349 |
return selectedColors; |
325 | 350 |
} |
326 | 351 |
|
352 |
@Override |
|
327 | 353 |
public void setColorScheme(Color[] cc) { |
328 | 354 |
this.selectedColors = cc; |
329 | 355 |
} |
330 | 356 |
|
357 |
@Override |
|
331 | 358 |
public Object clone() throws CloneNotSupportedException { |
332 | 359 |
VectorialUniqueValueLegend clone = |
333 | 360 |
(VectorialUniqueValueLegend) super.clone(); |
... | ... | |
381 | 408 |
removeLegendListener(list[i]); |
382 | 409 |
} |
383 | 410 |
} |
384 |
|
|
411 |
|
|
412 |
public void setClassifyingFieldTypes(int[] fieldTypes) { |
|
413 |
|
|
414 |
Class fieldClass = ToolsLocator.getDataTypesManager().getDefaultClass(fieldTypes[0]); |
|
415 |
if (!Comparable.class.isAssignableFrom(fieldClass)) { |
|
416 |
throw new IllegalArgumentException("Should be comparable"); |
|
417 |
} |
|
418 |
super.setClassifyingFieldTypes(fieldTypes); |
|
419 |
} |
|
420 |
|
|
385 | 421 |
private Map<Object, ISymbol> createSymbolMap() { |
386 |
return new TreeMap<Object, ISymbol>( |
|
387 |
new Comparator<Object>() { |
|
388 |
public int compare(Object o1, Object o2) { |
|
389 |
if ((o1 != null) && (o2 != null)) { |
|
390 |
Object v2 = o2; |
|
391 |
Object v1 = o1; |
|
392 |
if (v1 instanceof Number && v2 instanceof Number) { |
|
393 |
return ((Number) v1).intValue() |
|
394 |
- ((Number) v2).intValue(); |
|
395 |
} |
|
396 |
if (v1 instanceof String && v2 instanceof String) { |
|
397 |
return ((String) v1).compareTo(((String) v2)); |
|
398 |
} |
|
399 |
} |
|
422 |
final MutableObject<Coercion> convert = new MutableObject<>(); |
|
400 | 423 |
|
401 |
return 0; |
|
402 |
} |
|
403 |
}); |
|
424 |
return new TreeMap<Object, ISymbol>( |
|
425 |
new Comparator<Object>() { |
|
426 |
public int compare(Object o1, Object o2) { |
|
427 |
if (convert.getValue() == null) { |
|
428 |
convert.setValue(ToolsLocator.getDataTypesManager().getCoercion(getClassifyingFieldTypes()[0])); |
|
429 |
} |
|
430 |
try { |
|
431 |
return ObjectUtils.compare((Comparable) (convert.getValue().coerce(o1)), (Comparable) (convert.getValue().coerce(o2))); |
|
432 |
} catch (CoercionException ex) { |
|
433 |
throw new RuntimeException("Not able to coerce values in symbol map"); |
|
434 |
} |
|
435 |
} |
|
436 |
}); |
|
437 |
} |
|
404 | 438 |
|
405 |
} |
|
406 |
|
|
407 | 439 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
408 | 440 |
public void loadFromState(PersistentState state) |
409 | 441 |
throws PersistenceException { |
Also available in: Unified diff