root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / VectorialUniqueValueLegend.java @ 14315
History | View | Annotate | Download (20.4 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.rendering; |
42 |
|
43 |
import java.sql.Types; |
44 |
import java.text.ParseException; |
45 |
import java.util.ArrayList; |
46 |
import java.util.Comparator; |
47 |
import java.util.Iterator; |
48 |
import java.util.TreeMap; |
49 |
|
50 |
import org.apache.log4j.Logger; |
51 |
|
52 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
53 |
import com.hardcode.gdbms.engine.data.DataSource; |
54 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
55 |
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException; |
56 |
import com.hardcode.gdbms.engine.instruction.SemanticException; |
57 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
58 |
import com.hardcode.gdbms.engine.values.NullValue; |
59 |
import com.hardcode.gdbms.engine.values.StringValue; |
60 |
import com.hardcode.gdbms.engine.values.Value; |
61 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
62 |
import com.iver.cit.gvsig.fmap.core.FShape; |
63 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
64 |
import com.iver.cit.gvsig.fmap.core.ISLDCompatible; |
65 |
import com.iver.cit.gvsig.fmap.core.SLDTags; |
66 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
67 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
68 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
69 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
70 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
71 |
import com.iver.utiles.XMLEntity; |
72 |
|
73 |
/**
|
74 |
* Leyenda vectorial por valores ?nicos.
|
75 |
* @author Vicente Caballero Navarro
|
76 |
*/
|
77 |
//public class VectorialUniqueValueLegend implements IVectorialUniqueValueLegend {
|
78 |
public class VectorialUniqueValueLegend extends AbstractClassifiedVectorLegend implements IVectorialUniqueValueLegend { |
79 |
private static final Logger log = Logger.getLogger(VectorialUniqueValueLegend.class); |
80 |
protected int fieldId; |
81 |
protected DataSource dataSource; |
82 |
|
83 |
private TreeMap<Value, ISymbol> symbols = new TreeMap<Value, ISymbol>( |
84 |
new Comparator<Object>() { |
85 |
public int compare(Object o1, Object o2) { |
86 |
if ((o1 != null) && (o2 != null)) { |
87 |
Value v2 = (Value) o2; |
88 |
Value v1 = (Value) o1; |
89 |
BooleanValue boolVal; |
90 |
|
91 |
// TODO estas dos comprobaciones son por evitar un bug en el gdbms, cuando se solucione se puede eliminar.
|
92 |
if (v1 instanceof NullValue && v2 instanceof NullValue) { |
93 |
return 0; |
94 |
} |
95 |
|
96 |
if (v1 instanceof NullValue) { |
97 |
return -1; |
98 |
} |
99 |
|
100 |
if (v2 instanceof NullValue) { |
101 |
return 1; |
102 |
} |
103 |
|
104 |
try {
|
105 |
boolVal = (BooleanValue) (v1.greater(v2)); |
106 |
|
107 |
if (boolVal.getValue()) {
|
108 |
return 1; |
109 |
} |
110 |
|
111 |
boolVal = (BooleanValue) (v1.less(v2)); |
112 |
|
113 |
if (boolVal.getValue()) {
|
114 |
return -1; |
115 |
} |
116 |
} catch (IncompatibleTypesException e) {
|
117 |
// TODO Auto-generated catch block
|
118 |
//e.printStackTrace();
|
119 |
} |
120 |
|
121 |
try {
|
122 |
if (((BooleanValue) v1.equals(v2)).getValue()) {
|
123 |
return 0; |
124 |
} |
125 |
} catch (IncompatibleTypesException e) {
|
126 |
// TODO Auto-generated catch block
|
127 |
//e.printStackTrace();
|
128 |
} |
129 |
|
130 |
if (v1 instanceof StringValue) { |
131 |
return -1; |
132 |
} |
133 |
|
134 |
if (v2 instanceof StringValue) { |
135 |
return 1; |
136 |
} |
137 |
} |
138 |
|
139 |
return 0; |
140 |
} |
141 |
}); // Para poder ordenar
|
142 |
private ArrayList<Value> keys = new ArrayList<Value>(); // En lugar de un HashSet, para tener acceso por ?ndice |
143 |
private String[] fieldNames; |
144 |
private String labelFieldName; |
145 |
private String labelFieldHeight; |
146 |
private String labelFieldRotation; |
147 |
private ISymbol defaultSymbol;
|
148 |
private int shapeType; |
149 |
private String valueType = NullValue.class.getName(); |
150 |
private boolean useDefaultSymbol = false; |
151 |
private ZSort zSort;
|
152 |
|
153 |
|
154 |
/**
|
155 |
* Crea un nuevo VectorialUniqueValueLegend.
|
156 |
*/
|
157 |
public VectorialUniqueValueLegend() {
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* Crea un nuevo VectorialUniqueValueLegend.
|
162 |
*
|
163 |
* @param shapeType Tipo de shape.
|
164 |
*/
|
165 |
public VectorialUniqueValueLegend(int shapeType) { |
166 |
setShapeType(shapeType); |
167 |
} |
168 |
|
169 |
public void setShapeType(int shapeType) { |
170 |
if (this.shapeType != shapeType) { |
171 |
ISymbol old = defaultSymbol; |
172 |
defaultSymbol = SymbologyFactory.createDefaultSymbolByShapeType(shapeType); |
173 |
fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, defaultSymbol));
|
174 |
this.shapeType = shapeType;
|
175 |
} |
176 |
} |
177 |
|
178 |
public void setValueSymbolByID(int id, ISymbol symbol) { |
179 |
ISymbol old = symbols.put(keys.get(id), symbol); |
180 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(old, symbol));
|
181 |
} |
182 |
|
183 |
/**
|
184 |
* Se usa en la tabla que muestra una leyenda.
|
185 |
* @deprecated use setValueSymbolByID(int id, ISymbol symbol);
|
186 |
* @param id
|
187 |
* @param symbol
|
188 |
*/
|
189 |
public void setValueSymbol(int id, ISymbol symbol) { |
190 |
ISymbol old = symbols.put(keys.get(id), symbol); |
191 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(old, symbol));
|
192 |
} |
193 |
|
194 |
public Object[] getValues() { |
195 |
return symbols.keySet().toArray(new Object[0]); |
196 |
} |
197 |
|
198 |
public void addSymbol(Object key, ISymbol symbol) { |
199 |
ISymbol resul; |
200 |
resul = symbols.put((Value) key, symbol); |
201 |
|
202 |
if (resul != null) { |
203 |
log.error("Error: la clave " + key +
|
204 |
" ya exist?a. Resul = " + resul);
|
205 |
log.warn("symbol nuevo:" + symbol.getDescription() +
|
206 |
" Sviejo= " + resul.getDescription());
|
207 |
} else {
|
208 |
keys.add((Value) key); |
209 |
|
210 |
if (!key.getClass().equals(NullValue.class)) {
|
211 |
valueType = key.getClass().getName(); |
212 |
} |
213 |
} |
214 |
|
215 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(resul, symbol));
|
216 |
|
217 |
} |
218 |
|
219 |
public void clear() { |
220 |
keys.clear(); |
221 |
ISymbol[] olds = symbols.values().toArray(new ISymbol[0]); |
222 |
symbols.clear(); |
223 |
removeLegendListener(zSort); |
224 |
zSort = null;
|
225 |
|
226 |
fireLegendClearEvent(new LegendClearEvent(olds));
|
227 |
} |
228 |
|
229 |
public String[] getDescriptions() { |
230 |
String[] descriptions = new String[symbols.size()]; |
231 |
ISymbol[] auxSym = getSymbols();
|
232 |
|
233 |
for (int i = 0; i < descriptions.length; i++) |
234 |
descriptions[i] = auxSym[i].getDescription(); |
235 |
|
236 |
return descriptions;
|
237 |
} |
238 |
|
239 |
public ISymbol[] getSymbols() { |
240 |
return symbols.values().toArray(new ISymbol[0]); |
241 |
} |
242 |
|
243 |
public String[] getClassifyingFieldNames() { |
244 |
return fieldNames;
|
245 |
} |
246 |
|
247 |
public void setClassifyingFieldNames(String[] fNames) { |
248 |
fieldNames = fNames; |
249 |
try {
|
250 |
fieldId = dataSource.getFieldIndexByName(fieldNames[0]);
|
251 |
} catch (NullPointerException e) { |
252 |
log.warn("data source not set");
|
253 |
} catch (ReadDriverException e) {
|
254 |
log.warn("failed setting field id");
|
255 |
} |
256 |
} |
257 |
|
258 |
/*
|
259 |
* @see com.iver.cit.gvsig.fmap.rendering.IVectorialLegend#getSymbol(int)
|
260 |
*/
|
261 |
public ISymbol getSymbol(int recordIndex) throws ReadDriverException { |
262 |
Value val = dataSource.getFieldValue(recordIndex, fieldId); |
263 |
ISymbol theSymbol = getSymbolByValue(val); |
264 |
|
265 |
return theSymbol;
|
266 |
} |
267 |
|
268 |
/**
|
269 |
* Devuelve un s?mbolo a partir de una IFeature. OJO!! Cuando usamos un
|
270 |
* feature iterator de base de datos el ?nico campo que vendr? rellenado es
|
271 |
* el de fieldID. Los dem?s vendr?n a nulos para ahorra tiempo de creaci?n.
|
272 |
*
|
273 |
* @param feat
|
274 |
* IFeature
|
275 |
*
|
276 |
* @return S?mbolo.
|
277 |
*/
|
278 |
public ISymbol getSymbolByFeature(IFeature feat) {
|
279 |
Value val = feat.getAttribute(FLyrVect.forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD |
280 |
? 0 :fieldId);
|
281 |
ISymbol theSymbol = getSymbolByValue(val); |
282 |
|
283 |
if (theSymbol != null) { |
284 |
return theSymbol;
|
285 |
|
286 |
} |
287 |
|
288 |
return getDefaultSymbol();
|
289 |
} |
290 |
|
291 |
public ISymbol getDefaultSymbol() {
|
292 |
|
293 |
NullUniqueValue nuv=new NullUniqueValue();
|
294 |
if (symbols.containsKey(nuv))
|
295 |
return symbols.get(nuv);
|
296 |
|
297 |
if(defaultSymbol==null) { |
298 |
defaultSymbol = SymbologyFactory.createDefaultSymbolByShapeType(shapeType); |
299 |
fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null, defaultSymbol)); |
300 |
} |
301 |
return defaultSymbol;
|
302 |
} |
303 |
|
304 |
|
305 |
public String getSLDString(String name) { |
306 |
try {
|
307 |
|
308 |
XmlBuilder xmlBuilder = new XmlBuilder();
|
309 |
xmlBuilder.writeHeader(); |
310 |
xmlBuilder.openTag(SLDTags.SLD_ROOT, SLDTags.VERSION_ATTR, SLDTags.VERSION_1_0_0); |
311 |
xmlBuilder.openTag(SLDTags.NAMEDLAYER); |
312 |
xmlBuilder.writeTag(SLDTags.NAME,name); |
313 |
xmlBuilder.openTag(SLDTags.USERSTYLE); |
314 |
xmlBuilder.openTag(SLDTags.FEATURETYPESTYLE); |
315 |
//xmlBuilder.writeTag(SLDTags.FEATURETYPENAME,"fieldName");
|
316 |
|
317 |
ISymbol[] mySymbols = this.getSymbols(); |
318 |
Object[] values = this.getValues(); |
319 |
String valueStr = null; |
320 |
|
321 |
for(int i = 0; i < mySymbols.length; i++ ){ |
322 |
valueStr = values[i].toString(); |
323 |
xmlBuilder.openTag(SLDTags.RULE); |
324 |
xmlBuilder.writeTag(SLDTags.NAME, valueStr); |
325 |
xmlBuilder.openTag(SLDTags.FILTER); |
326 |
xmlBuilder.openTag(SLDTags.PROPERTYISEQUALTO); |
327 |
xmlBuilder.writeTag(SLDTags.PROPERTYNAME, fieldNames[0]);
|
328 |
xmlBuilder.writeTag(SLDTags.LITERAL, valueStr); |
329 |
xmlBuilder.closeTag(); |
330 |
xmlBuilder.closeTag(); |
331 |
if (mySymbols[i] instanceof ISLDCompatible) { |
332 |
ISLDCompatible symSLD = (ISLDCompatible) mySymbols[i]; |
333 |
xmlBuilder.writeRaw(symSLD.toSLD()); |
334 |
} else
|
335 |
throw new RuntimeException("Cannot convert Symbol " + i + " " + mySymbols[i].getDescription() + " to SLD"); |
336 |
|
337 |
xmlBuilder.closeTag(); |
338 |
} |
339 |
|
340 |
xmlBuilder.closeTag(); |
341 |
xmlBuilder.closeTag(); |
342 |
xmlBuilder.closeTag(); |
343 |
xmlBuilder.closeTag(); |
344 |
return xmlBuilder.getXML();
|
345 |
|
346 |
} catch (Exception e) { |
347 |
e.printStackTrace(); |
348 |
return null; |
349 |
} |
350 |
} |
351 |
|
352 |
public XMLEntity getXMLEntity() {
|
353 |
XMLEntity xml = new XMLEntity();
|
354 |
xml.putProperty("className", this.getClass().getName()); |
355 |
xml.putProperty("fieldNames", fieldNames[0]); |
356 |
xml.putProperty("labelfield", labelFieldName);
|
357 |
xml.putProperty("labelFieldHeight", labelFieldHeight);
|
358 |
xml.putProperty("labelFieldRotation", labelFieldRotation);
|
359 |
|
360 |
xml.putProperty("useDefaultSymbol", useDefaultSymbol);
|
361 |
xml.addChild(getDefaultSymbol().getXMLEntity()); |
362 |
xml.putProperty("numKeys", keys.size());
|
363 |
|
364 |
if (keys.size() > 0) { |
365 |
xml.putProperty("tipoValueKeys", valueType);
|
366 |
|
367 |
String[] sk = new String[keys.size()]; |
368 |
String[] sv = new String[keys.size()]; |
369 |
int[] stk = new int[keys.size()]; |
370 |
int[] stv = new int[keys.size()]; |
371 |
ISymbol[] fsymbols = getSymbols();
|
372 |
Object[] values = getValues(); |
373 |
|
374 |
for (int i = 0; i < keys.size(); i++) { |
375 |
if (keys.get(i).toString().equals("")) { |
376 |
sk[i] =" ";
|
377 |
}else {
|
378 |
sk[i] = keys.get(i).toString(); |
379 |
} |
380 |
if (((Value) values[i]).toString().equals("")) { |
381 |
sv[i] =" ";
|
382 |
}else {
|
383 |
sv[i] = ((Value) values[i]).toString(); |
384 |
} |
385 |
stk[i]= keys.get(i).getSQLType(); |
386 |
stv[i]= ((Value)values[i]).getSQLType(); |
387 |
xml.addChild(fsymbols[i].getXMLEntity()); |
388 |
|
389 |
///System.out.println("get-----------"+sk[i]+"--"+fsymbols[i].getDescription()+"---"+fsymbols[i].getColor());
|
390 |
} |
391 |
|
392 |
xml.putProperty("keys", sk);
|
393 |
xml.putProperty("values", sv);
|
394 |
xml.putProperty("typeKeys",stk);
|
395 |
xml.putProperty("typeValues",stv);
|
396 |
} |
397 |
|
398 |
if (zSort!=null) { |
399 |
XMLEntity xmlZSort = zSort.getXMLEntity(); |
400 |
xmlZSort.putProperty("id", "zSort"); |
401 |
xml.addChild(xmlZSort); |
402 |
} |
403 |
return xml;
|
404 |
} |
405 |
|
406 |
public void setXMLEntity03(XMLEntity xml) { |
407 |
clear(); |
408 |
setClassifyingFieldNames(new String[] {xml.getStringProperty("fieldName")}); |
409 |
|
410 |
int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol"); |
411 |
|
412 |
if (useDefaultSymbol == 1) { |
413 |
setDefaultSymbol(FSymbol.createFromXML03(xml.getChild(0)));
|
414 |
} else {
|
415 |
setDefaultSymbol(null);
|
416 |
} |
417 |
|
418 |
int numKeys = xml.getIntProperty("numKeys"); |
419 |
|
420 |
if (numKeys > 0) { |
421 |
String className = xml.getStringProperty("tipoValueKeys"); |
422 |
String[] sk = xml.getStringArrayProperty("keys"); |
423 |
String[] sv = xml.getStringArrayProperty("values"); |
424 |
Value auxValue; |
425 |
Value auxValue2; |
426 |
|
427 |
for (int i = 0; i < numKeys; i++) { |
428 |
try {
|
429 |
auxValue = ValueFactory.createValue(sk[i], className); |
430 |
auxValue2 = ValueFactory.createValue(sv[i], className); |
431 |
|
432 |
ISymbol sym = FSymbol.createFromXML03(xml.getChild(i + |
433 |
useDefaultSymbol)); |
434 |
|
435 |
symbols.put(auxValue2, sym); |
436 |
keys.add(auxValue); |
437 |
|
438 |
} catch (SemanticException e) {
|
439 |
log.error("Exception", e);
|
440 |
e.printStackTrace(); |
441 |
} |
442 |
} |
443 |
} |
444 |
} |
445 |
|
446 |
public void setXMLEntity(XMLEntity xml) { |
447 |
clear(); |
448 |
if (xml.contains("fieldName")) |
449 |
setClassifyingFieldNames(new String[] {xml.getStringProperty("fieldName")}); |
450 |
else
|
451 |
setClassifyingFieldNames(xml.getStringArrayProperty("fieldNames"));
|
452 |
|
453 |
useDefaultSymbol = xml.getBooleanProperty("useDefaultSymbol");
|
454 |
setDefaultSymbol(SymbologyFactory.createSymbolFromXML(xml.getChild(0), null)); |
455 |
|
456 |
int numKeys = xml.getIntProperty("numKeys"); |
457 |
|
458 |
if (numKeys > 0) { |
459 |
String className = xml.getStringProperty("tipoValueKeys"); |
460 |
String[] sk = xml.getStringArrayProperty("keys"); |
461 |
String[] sv = xml.getStringArrayProperty("values"); |
462 |
Value auxValue = null;
|
463 |
Value auxValue2 = null;
|
464 |
int[] stk=null; |
465 |
if (xml.contains("typeKeys")) { |
466 |
stk = xml.getIntArrayProperty("typeKeys");
|
467 |
int[] stv = xml.getIntArrayProperty("typeValues"); |
468 |
for (int i = 0; i < numKeys; i++) { |
469 |
boolean isDefault = false; |
470 |
if (getValue(sk[i], stk[i]) == null) { |
471 |
isDefault = true;
|
472 |
} |
473 |
|
474 |
if (className
|
475 |
.equals("com.hardcode.gdbms.engine.values.NullUniqueValue")
|
476 |
|| isDefault) { |
477 |
auxValue = new NullUniqueValue();
|
478 |
auxValue2 = ValueFactory.createNullValue(); |
479 |
} else {
|
480 |
auxValue = getValue(sk[i], stk[i]); // ValueFactory.createValue(sk[i],
|
481 |
// className);
|
482 |
auxValue2 = getValue(sv[i], stv[i]); // ValueFactory.createValue(sv[i],
|
483 |
// className);
|
484 |
} |
485 |
|
486 |
// (substituir la de baix per esta) ISymbol sym = SymbolFactory.createFromXML(xml.getChild(i + 1), null);
|
487 |
ISymbol sym = SymbologyFactory.createSymbolFromXML(xml.getChild(i + 1), null); |
488 |
symbols.put(auxValue2, sym); |
489 |
keys.add(auxValue); |
490 |
} |
491 |
} else {
|
492 |
for (int i = 0; i < numKeys; i++) { |
493 |
boolean isDefault = false; |
494 |
if (getValue(sk[i]) == null) { |
495 |
isDefault = true;
|
496 |
} |
497 |
if (className
|
498 |
.equals("com.hardcode.gdbms.engine.values.NullUniqueValue")
|
499 |
|| isDefault) { |
500 |
auxValue = new NullUniqueValue();
|
501 |
auxValue2 = ValueFactory.createNullValue(); |
502 |
} else {
|
503 |
auxValue = getValue(sk[i]); // ValueFactory.createValue(sk[i],
|
504 |
// className);
|
505 |
auxValue2 = getValue(sv[i]); // ValueFactory.createValue(sv[i],
|
506 |
// className);
|
507 |
} |
508 |
ISymbol sym = FSymbol.createFromXML(xml.getChild(i + 1));
|
509 |
symbols.put(auxValue2, sym); |
510 |
keys.add(auxValue); |
511 |
} |
512 |
} |
513 |
} |
514 |
|
515 |
XMLEntity zSortXML = xml.firstChild("id", "zSort"); |
516 |
if (zSortXML != null) { |
517 |
zSort = new ZSort(this); |
518 |
zSort.setXMLEntity(zSortXML); |
519 |
addLegendListener(zSort); |
520 |
} |
521 |
} |
522 |
|
523 |
public void setDefaultSymbol(ISymbol s) { |
524 |
if (s == null) throw new NullPointerException("Default symbol cannot be null"); |
525 |
ISymbol old = defaultSymbol; |
526 |
defaultSymbol = s; |
527 |
fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, defaultSymbol));
|
528 |
|
529 |
|
530 |
} |
531 |
/**
|
532 |
* Devuelve el valor a partir de su valor en un string.
|
533 |
*
|
534 |
* @param s
|
535 |
* String con el valor.
|
536 |
* @deprecated M?todo utilizado hasta la 1.0 alpha 855 Debes utilizar a partir de ahora getValue(String s,int type);
|
537 |
* @return Value.
|
538 |
*/
|
539 |
private Value getValue(String s) { |
540 |
Value val = new NullUniqueValue();
|
541 |
if (s.equals("Resto de Valores"))return val; |
542 |
try {
|
543 |
try {
|
544 |
val = ValueFactory.createValueByType(s, Types.INTEGER);
|
545 |
|
546 |
return val;
|
547 |
} catch (NumberFormatException e) { |
548 |
} |
549 |
|
550 |
try {
|
551 |
val = ValueFactory.createValueByType(s, Types.BIGINT);
|
552 |
|
553 |
return val;
|
554 |
} catch (NumberFormatException e) { |
555 |
} |
556 |
|
557 |
try {
|
558 |
val = ValueFactory.createValueByType(s, Types.FLOAT);
|
559 |
|
560 |
return val;
|
561 |
} catch (NumberFormatException e) { |
562 |
} |
563 |
|
564 |
try {
|
565 |
val = ValueFactory.createValueByType(s, Types.DOUBLE);
|
566 |
|
567 |
return val;
|
568 |
} catch (NumberFormatException e) { |
569 |
} |
570 |
|
571 |
val = ValueFactory.createValueByType(s, Types.LONGVARCHAR);
|
572 |
|
573 |
} catch (ParseException e) { |
574 |
log.warn("parse exception", e);
|
575 |
} |
576 |
|
577 |
return val;
|
578 |
} |
579 |
|
580 |
/**
|
581 |
* Devuelve el valor a partir de su valor en un string.
|
582 |
*
|
583 |
* @param s String con el valor.
|
584 |
*
|
585 |
* @return Value.
|
586 |
*/
|
587 |
private Value getValue(String s,int type) { |
588 |
Value val = new NullUniqueValue();
|
589 |
if (type==Types.OTHER) |
590 |
return val;
|
591 |
try {
|
592 |
val = ValueFactory.createValueByType(s, type); |
593 |
} catch (ParseException e) { |
594 |
e.printStackTrace(); |
595 |
} |
596 |
return val;
|
597 |
} |
598 |
|
599 |
public ILegend cloneLegend() throws XMLException { |
600 |
return LegendFactory.createFromXML(getXMLEntity());
|
601 |
} |
602 |
|
603 |
|
604 |
/* (non-Javadoc)
|
605 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDataSource(com.hardcode.gdbms.engine.data.DataSource)
|
606 |
*/
|
607 |
public void setDataSource(DataSource ds) throws FieldNotFoundException, |
608 |
ReadDriverException { |
609 |
dataSource = ds; |
610 |
ds.start(); |
611 |
fieldId = ds.getFieldIndexByName(fieldNames[0]);
|
612 |
ds.stop(); |
613 |
} |
614 |
|
615 |
/*
|
616 |
* (non-Javadoc)
|
617 |
*
|
618 |
* @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#getSymbolByValue(com.hardcode.gdbms.engine.values.Value)
|
619 |
*/
|
620 |
public ISymbol getSymbolByValue(Value key) {
|
621 |
ISymbol symbol = symbols.get(key); |
622 |
if (symbol!=null) { |
623 |
return symbol;
|
624 |
} else if (useDefaultSymbol) { |
625 |
return getDefaultSymbol();
|
626 |
} |
627 |
return null; |
628 |
|
629 |
} |
630 |
|
631 |
public int getShapeType() { |
632 |
return shapeType;
|
633 |
} |
634 |
|
635 |
public void useDefaultSymbol(boolean b) { |
636 |
useDefaultSymbol = b; |
637 |
} |
638 |
|
639 |
/**
|
640 |
* Devuelve si se utiliza o no el resto de valores para representarse.
|
641 |
* @return True si se utiliza el resto de valores.
|
642 |
*/
|
643 |
public boolean isUseDefaultSymbol() { |
644 |
return useDefaultSymbol;
|
645 |
} |
646 |
|
647 |
public void delSymbol(Object key) { |
648 |
keys.remove(key); |
649 |
|
650 |
fireClassifiedSymbolChangeEvent( |
651 |
new SymbolLegendEvent(
|
652 |
symbols.remove(key), |
653 |
null));
|
654 |
} |
655 |
|
656 |
public ZSort getZSort() {
|
657 |
return zSort;
|
658 |
} |
659 |
|
660 |
public void setZSort(ZSort zSort) { |
661 |
this.zSort = zSort;
|
662 |
addLegendListener(zSort); |
663 |
} |
664 |
|
665 |
public String getClassName() { |
666 |
return getClass().getName();
|
667 |
} |
668 |
|
669 |
public void replace(ISymbol oldSymbol, ISymbol newSymbol) { |
670 |
if (symbols.containsValue(oldSymbol)) {
|
671 |
Iterator<Value> it = symbols.keySet().iterator();
|
672 |
while (it.hasNext()) {
|
673 |
Value key = it.next(); |
674 |
if (symbols.get(key).equals(oldSymbol)) {
|
675 |
symbols.remove(key); |
676 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(
|
677 |
symbols.put(key, newSymbol), newSymbol)); |
678 |
} |
679 |
|
680 |
} |
681 |
} |
682 |
} |
683 |
} |