svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / VectorialUniqueValueLegend.java @ 16454
History | View | Annotate | Download (20.5 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 |
* Vectorial legend for unique values
|
75 |
*
|
76 |
* @author Vicente Caballero Navarro
|
77 |
*/
|
78 |
//public class VectorialUniqueValueLegend implements IVectorialUniqueValueLegend {
|
79 |
public class VectorialUniqueValueLegend extends AbstractClassifiedVectorLegend implements IVectorialUniqueValueLegend { |
80 |
private static final Logger log = Logger.getLogger(VectorialUniqueValueLegend.class); |
81 |
protected int fieldId; |
82 |
protected DataSource dataSource; |
83 |
|
84 |
private TreeMap<Value, ISymbol> symbols = new TreeMap<Value, ISymbol>( |
85 |
new Comparator<Object>() { |
86 |
public int compare(Object o1, Object o2) { |
87 |
if ((o1 != null) && (o2 != null)) { |
88 |
Value v2 = (Value) o2; |
89 |
Value v1 = (Value) o1; |
90 |
BooleanValue boolVal; |
91 |
|
92 |
// TODO estas dos comprobaciones son por evitar un bug en el gdbms, cuando se solucione se puede eliminar.
|
93 |
if (v1 instanceof NullValue && v2 instanceof NullValue) { |
94 |
return 0; |
95 |
} |
96 |
|
97 |
if (v1 instanceof NullValue) { |
98 |
return -1; |
99 |
} |
100 |
|
101 |
if (v2 instanceof NullValue) { |
102 |
return 1; |
103 |
} |
104 |
|
105 |
try {
|
106 |
boolVal = (BooleanValue) (v1.greater(v2)); |
107 |
|
108 |
if (boolVal.getValue()) {
|
109 |
return 1; |
110 |
} |
111 |
|
112 |
boolVal = (BooleanValue) (v1.less(v2)); |
113 |
|
114 |
if (boolVal.getValue()) {
|
115 |
return -1; |
116 |
} |
117 |
} catch (IncompatibleTypesException e) {
|
118 |
// TODO Auto-generated catch block
|
119 |
//e.printStackTrace();
|
120 |
} |
121 |
|
122 |
try {
|
123 |
if (((BooleanValue) v1.equals(v2)).getValue()) {
|
124 |
return 0; |
125 |
} |
126 |
} catch (IncompatibleTypesException e) {
|
127 |
// TODO Auto-generated catch block
|
128 |
//e.printStackTrace();
|
129 |
} |
130 |
|
131 |
if (v1 instanceof StringValue) { |
132 |
return -1; |
133 |
} |
134 |
|
135 |
if (v2 instanceof StringValue) { |
136 |
return 1; |
137 |
} |
138 |
} |
139 |
|
140 |
return 0; |
141 |
} |
142 |
}); // Para poder ordenar
|
143 |
private ArrayList<Value> keys = new ArrayList<Value>(); // En lugar de un HashSet, para tener acceso por ?ndice |
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 |
/**
|
152 |
* Constructor method
|
153 |
*/
|
154 |
public VectorialUniqueValueLegend() {
|
155 |
} |
156 |
|
157 |
/**
|
158 |
* Constructor method
|
159 |
*
|
160 |
* @param shapeType Type of the shape.
|
161 |
*/
|
162 |
public VectorialUniqueValueLegend(int shapeType) { |
163 |
setShapeType(shapeType); |
164 |
} |
165 |
|
166 |
public void setShapeType(int shapeType) { |
167 |
if (this.shapeType != shapeType) { |
168 |
ISymbol old = defaultSymbol; |
169 |
defaultSymbol = SymbologyFactory.createDefaultSymbolByShapeType(shapeType); |
170 |
fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, defaultSymbol));
|
171 |
this.shapeType = shapeType;
|
172 |
} |
173 |
} |
174 |
|
175 |
public void setValueSymbolByID(int id, ISymbol symbol) { |
176 |
ISymbol old = symbols.put(keys.get(id), symbol); |
177 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(old, symbol));
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* Used in the table that shows the legend
|
182 |
*
|
183 |
* @deprecated use setValueSymbolByID(int id, ISymbol symbol);
|
184 |
* @param id
|
185 |
* @param symbol
|
186 |
*/
|
187 |
public void setValueSymbol(int id, ISymbol symbol) { |
188 |
ISymbol old = symbols.put(keys.get(id), symbol); |
189 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(old, symbol));
|
190 |
} |
191 |
|
192 |
public Object[] getValues() { |
193 |
return symbols.keySet().toArray(new Object[0]); |
194 |
} |
195 |
|
196 |
public void addSymbol(Object key, ISymbol symbol) { |
197 |
ISymbol resul; |
198 |
resul = symbols.put((Value) key, symbol); |
199 |
|
200 |
if (resul != null) { |
201 |
log.error("Error: la clave " + key +
|
202 |
" ya exist?a. Resul = " + resul);
|
203 |
log.warn("symbol nuevo:" + symbol.getDescription() +
|
204 |
" Sviejo= " + resul.getDescription());
|
205 |
} else {
|
206 |
keys.add((Value) key); |
207 |
|
208 |
if (!key.getClass().equals(NullValue.class)) {
|
209 |
valueType = key.getClass().getName(); |
210 |
} |
211 |
} |
212 |
|
213 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(resul, symbol));
|
214 |
|
215 |
} |
216 |
|
217 |
public void clear() { |
218 |
keys.clear(); |
219 |
ISymbol[] olds = symbols.values().toArray(new ISymbol[0]); |
220 |
symbols.clear(); |
221 |
removeLegendListener(getZSort()); |
222 |
setZSort(null);
|
223 |
|
224 |
fireLegendClearEvent(new LegendClearEvent(olds));
|
225 |
} |
226 |
|
227 |
public String[] getDescriptions() { |
228 |
String[] descriptions = new String[symbols.size()]; |
229 |
ISymbol[] auxSym = getSymbols();
|
230 |
|
231 |
for (int i = 0; i < descriptions.length; i++) |
232 |
descriptions[i] = auxSym[i].getDescription(); |
233 |
|
234 |
return descriptions;
|
235 |
} |
236 |
|
237 |
public ISymbol[] getSymbols() { |
238 |
return symbols.values().toArray(new ISymbol[0]); |
239 |
} |
240 |
|
241 |
@Override
|
242 |
public void setClassifyingFieldNames(String[] fNames) { |
243 |
super.setClassifyingFieldNames(fNames);
|
244 |
try {
|
245 |
fieldId = dataSource.getFieldIndexByName(getClassifyingFieldNames()[0]);
|
246 |
} catch (NullPointerException e) { |
247 |
log.warn("data source not set");
|
248 |
} catch (ReadDriverException e) {
|
249 |
log.warn("failed setting field id");
|
250 |
} |
251 |
} |
252 |
/*
|
253 |
* @see com.iver.cit.gvsig.fmap.rendering.IVectorialLegend#getSymbol(int)
|
254 |
*/
|
255 |
public ISymbol getSymbol(int recordIndex) throws ReadDriverException { |
256 |
Value val = dataSource.getFieldValue(recordIndex, fieldId); |
257 |
ISymbol theSymbol = getSymbolByValue(val); |
258 |
|
259 |
return theSymbol;
|
260 |
} |
261 |
|
262 |
/**
|
263 |
* Devuelve un s?mbolo a partir de una IFeature. OJO!! Cuando usamos un
|
264 |
* feature iterator de base de datos el ?nico campo que vendr? rellenado es
|
265 |
* el de fieldID. Los dem?s vendr?n a nulos para ahorra tiempo de creaci?n.
|
266 |
*
|
267 |
* @param feat
|
268 |
* IFeature
|
269 |
*
|
270 |
* @return S?mbolo.
|
271 |
*/
|
272 |
public ISymbol getSymbolByFeature(IFeature feat) {
|
273 |
Value val = feat.getAttribute(FLyrVect.forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD |
274 |
? 0 :fieldId);
|
275 |
ISymbol theSymbol = getSymbolByValue(val); |
276 |
|
277 |
if (theSymbol != null) { |
278 |
return theSymbol;
|
279 |
|
280 |
} |
281 |
|
282 |
return getDefaultSymbol();
|
283 |
} |
284 |
|
285 |
public ISymbol getDefaultSymbol() {
|
286 |
|
287 |
NullUniqueValue nuv=new NullUniqueValue();
|
288 |
if (symbols.containsKey(nuv))
|
289 |
return symbols.get(nuv);
|
290 |
|
291 |
if(defaultSymbol==null) { |
292 |
defaultSymbol = SymbologyFactory.createDefaultSymbolByShapeType(shapeType); |
293 |
fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null, defaultSymbol)); |
294 |
} |
295 |
return defaultSymbol;
|
296 |
} |
297 |
|
298 |
|
299 |
public String getSLDString(String name) { |
300 |
try {
|
301 |
|
302 |
XmlBuilder xmlBuilder = new XmlBuilder();
|
303 |
xmlBuilder.writeHeader(); |
304 |
xmlBuilder.openTag(SLDTags.SLD_ROOT, SLDTags.VERSION_ATTR, SLDTags.VERSION_1_0_0); |
305 |
xmlBuilder.openTag(SLDTags.NAMEDLAYER); |
306 |
xmlBuilder.writeTag(SLDTags.NAME,name); |
307 |
xmlBuilder.openTag(SLDTags.USERSTYLE); |
308 |
xmlBuilder.openTag(SLDTags.FEATURETYPESTYLE); |
309 |
//xmlBuilder.writeTag(SLDTags.FEATURETYPENAME,"fieldName");
|
310 |
|
311 |
ISymbol[] mySymbols = this.getSymbols(); |
312 |
Object[] values = this.getValues(); |
313 |
String valueStr = null; |
314 |
|
315 |
for(int i = 0; i < mySymbols.length; i++ ){ |
316 |
valueStr = values[i].toString(); |
317 |
xmlBuilder.openTag(SLDTags.RULE); |
318 |
xmlBuilder.writeTag(SLDTags.NAME, valueStr); |
319 |
xmlBuilder.openTag(SLDTags.FILTER); |
320 |
xmlBuilder.openTag(SLDTags.PROPERTYISEQUALTO); |
321 |
xmlBuilder.writeTag(SLDTags.PROPERTYNAME, getClassifyingFieldNames()[0]);
|
322 |
xmlBuilder.writeTag(SLDTags.LITERAL, valueStr); |
323 |
xmlBuilder.closeTag(); |
324 |
xmlBuilder.closeTag(); |
325 |
if (mySymbols[i] instanceof ISLDCompatible) { |
326 |
ISLDCompatible symSLD = (ISLDCompatible) mySymbols[i]; |
327 |
xmlBuilder.writeRaw(symSLD.toSLD()); |
328 |
} else
|
329 |
throw new RuntimeException("Cannot convert Symbol " + i + " " + mySymbols[i].getDescription() + " to SLD"); |
330 |
|
331 |
xmlBuilder.closeTag(); |
332 |
} |
333 |
|
334 |
xmlBuilder.closeTag(); |
335 |
xmlBuilder.closeTag(); |
336 |
xmlBuilder.closeTag(); |
337 |
xmlBuilder.closeTag(); |
338 |
return xmlBuilder.getXML();
|
339 |
|
340 |
} catch (Exception e) { |
341 |
e.printStackTrace(); |
342 |
return null; |
343 |
} |
344 |
} |
345 |
|
346 |
public XMLEntity getXMLEntity() {
|
347 |
XMLEntity xml = new XMLEntity();
|
348 |
xml.putProperty("className", this.getClass().getName()); |
349 |
xml.putProperty("fieldNames", getClassifyingFieldNames()[0]); |
350 |
|
351 |
///////////////////////////////////////PEPE
|
352 |
xml.putProperty("fieldTypes", getClassifyingFieldTypes()[0]); |
353 |
///////////////////////////////////////PEPE
|
354 |
|
355 |
xml.putProperty("labelfield", labelFieldName);
|
356 |
xml.putProperty("labelFieldHeight", labelFieldHeight);
|
357 |
xml.putProperty("labelFieldRotation", labelFieldRotation);
|
358 |
|
359 |
xml.putProperty("useDefaultSymbol", useDefaultSymbol);
|
360 |
xml.addChild(getDefaultSymbol().getXMLEntity()); |
361 |
xml.putProperty("numKeys", keys.size());
|
362 |
|
363 |
if (keys.size() > 0) { |
364 |
xml.putProperty("tipoValueKeys", valueType);
|
365 |
|
366 |
String[] sk = new String[keys.size()]; |
367 |
String[] sv = new String[keys.size()]; |
368 |
int[] stk = new int[keys.size()]; |
369 |
int[] stv = new int[keys.size()]; |
370 |
ISymbol[] fsymbols = getSymbols();
|
371 |
Object[] values = getValues(); |
372 |
|
373 |
for (int i = 0; i < keys.size(); i++) { |
374 |
if (keys.get(i).toString().equals("")) { |
375 |
sk[i] =" ";
|
376 |
}else {
|
377 |
sk[i] = keys.get(i).toString(); |
378 |
} |
379 |
if (((Value) values[i]).toString().equals("")) { |
380 |
sv[i] =" ";
|
381 |
}else {
|
382 |
sv[i] = ((Value) values[i]).toString(); |
383 |
} |
384 |
stk[i]= keys.get(i).getSQLType(); |
385 |
stv[i]= ((Value)values[i]).getSQLType(); |
386 |
xml.addChild(fsymbols[i].getXMLEntity()); |
387 |
|
388 |
///System.out.println("get-----------"+sk[i]+"--"+fsymbols[i].getDescription()+"---"+fsymbols[i].getColor());
|
389 |
} |
390 |
|
391 |
xml.putProperty("keys", sk);
|
392 |
xml.putProperty("values", sv);
|
393 |
xml.putProperty("typeKeys",stk);
|
394 |
xml.putProperty("typeValues",stv);
|
395 |
} |
396 |
|
397 |
if (getZSort()!=null) { |
398 |
XMLEntity xmlZSort = getZSort().getXMLEntity(); |
399 |
xmlZSort.putProperty("id", "zSort"); |
400 |
xml.addChild(xmlZSort); |
401 |
} |
402 |
return xml;
|
403 |
} |
404 |
|
405 |
public void setXMLEntity03(XMLEntity xml) { |
406 |
clear(); |
407 |
setClassifyingFieldNames(new String[] {xml.getStringProperty("fieldName")}); |
408 |
|
409 |
int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol"); |
410 |
|
411 |
if (useDefaultSymbol == 1) { |
412 |
setDefaultSymbol(FSymbol.createFromXML03(xml.getChild(0)));
|
413 |
} else {
|
414 |
setDefaultSymbol(null);
|
415 |
} |
416 |
|
417 |
int numKeys = xml.getIntProperty("numKeys"); |
418 |
|
419 |
if (numKeys > 0) { |
420 |
String className = xml.getStringProperty("tipoValueKeys"); |
421 |
String[] sk = xml.getStringArrayProperty("keys"); |
422 |
String[] sv = xml.getStringArrayProperty("values"); |
423 |
Value auxValue; |
424 |
Value auxValue2; |
425 |
|
426 |
for (int i = 0; i < numKeys; i++) { |
427 |
try {
|
428 |
auxValue = ValueFactory.createValue(sk[i], className); |
429 |
auxValue2 = ValueFactory.createValue(sv[i], className); |
430 |
|
431 |
ISymbol sym = FSymbol.createFromXML03(xml.getChild(i + |
432 |
useDefaultSymbol)); |
433 |
|
434 |
symbols.put(auxValue2, sym); |
435 |
keys.add(auxValue); |
436 |
|
437 |
} catch (SemanticException e) {
|
438 |
log.error("Exception", e);
|
439 |
e.printStackTrace(); |
440 |
} |
441 |
} |
442 |
} |
443 |
} |
444 |
|
445 |
public void setXMLEntity(XMLEntity xml) { |
446 |
clear(); |
447 |
if (xml.contains("fieldName")) |
448 |
setClassifyingFieldNames(new String[] {xml.getStringProperty("fieldName")}); |
449 |
else
|
450 |
setClassifyingFieldNames(xml.getStringArrayProperty("fieldNames"));
|
451 |
|
452 |
if (xml.contains("fieldTypes")) |
453 |
setClassifyingFieldTypes(new int[] {xml.getIntProperty("fieldTypes")}); |
454 |
|
455 |
useDefaultSymbol = xml.getBooleanProperty("useDefaultSymbol");
|
456 |
setDefaultSymbol(SymbologyFactory.createSymbolFromXML(xml.getChild(0), null)); |
457 |
|
458 |
int numKeys = xml.getIntProperty("numKeys"); |
459 |
|
460 |
if (numKeys > 0) { |
461 |
String className = xml.getStringProperty("tipoValueKeys"); |
462 |
String[] sk = xml.getStringArrayProperty("keys"); |
463 |
String[] sv = xml.getStringArrayProperty("values"); |
464 |
Value auxValue = null;
|
465 |
Value auxValue2 = null;
|
466 |
int[] stk=null; |
467 |
if (xml.contains("typeKeys")) { |
468 |
stk = xml.getIntArrayProperty("typeKeys");
|
469 |
int[] stv = xml.getIntArrayProperty("typeValues"); |
470 |
for (int i = 0; i < numKeys; i++) { |
471 |
boolean isDefault = false; |
472 |
if (getValue(sk[i], stk[i]) == null) { |
473 |
isDefault = true;
|
474 |
} |
475 |
|
476 |
if (className
|
477 |
.equals("com.hardcode.gdbms.engine.values.NullUniqueValue")
|
478 |
|| isDefault) { |
479 |
auxValue = new NullUniqueValue();
|
480 |
auxValue2 = ValueFactory.createNullValue(); |
481 |
} else {
|
482 |
auxValue = getValue(sk[i], stk[i]); // ValueFactory.createValue(sk[i],
|
483 |
// className);
|
484 |
auxValue2 = getValue(sv[i], stv[i]); // ValueFactory.createValue(sv[i],
|
485 |
// className);
|
486 |
} |
487 |
|
488 |
// (substituir la de baix per esta) ISymbol sym = SymbolFactory.createFromXML(xml.getChild(i + 1), null);
|
489 |
ISymbol sym = SymbologyFactory.createSymbolFromXML(xml.getChild(i + 1), null); |
490 |
symbols.put(auxValue2, sym); |
491 |
keys.add(auxValue); |
492 |
} |
493 |
} else {
|
494 |
for (int i = 0; i < numKeys; i++) { |
495 |
boolean isDefault = false; |
496 |
if (getValue(sk[i]) == null) { |
497 |
isDefault = true;
|
498 |
} |
499 |
if (className
|
500 |
.equals("com.hardcode.gdbms.engine.values.NullUniqueValue")
|
501 |
|| isDefault) { |
502 |
auxValue = new NullUniqueValue();
|
503 |
auxValue2 = ValueFactory.createNullValue(); |
504 |
} else {
|
505 |
auxValue = getValue(sk[i]); // ValueFactory.createValue(sk[i],
|
506 |
// className);
|
507 |
auxValue2 = getValue(sv[i]); // ValueFactory.createValue(sv[i],
|
508 |
// className);
|
509 |
} |
510 |
ISymbol sym = FSymbol.createFromXML(xml.getChild(i + 1));
|
511 |
symbols.put(auxValue2, sym); |
512 |
keys.add(auxValue); |
513 |
} |
514 |
} |
515 |
} |
516 |
|
517 |
XMLEntity zSortXML = xml.firstChild("id", "zSort"); |
518 |
if (zSortXML != null) { |
519 |
ZSort zSort = new ZSort(this); |
520 |
zSort.setXMLEntity(zSortXML); |
521 |
addLegendListener(zSort); |
522 |
setZSort(zSort); |
523 |
} |
524 |
} |
525 |
|
526 |
public void setDefaultSymbol(ISymbol s) { |
527 |
if (s == null) throw new NullPointerException("Default symbol cannot be null"); |
528 |
ISymbol old = defaultSymbol; |
529 |
defaultSymbol = s; |
530 |
fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, defaultSymbol));
|
531 |
|
532 |
|
533 |
} |
534 |
/**
|
535 |
* Returns the value using the its value in a string.
|
536 |
*
|
537 |
*
|
538 |
* @param s String with the value.
|
539 |
* @deprecated Method used until 1.0 alpha 855 You should use getValue(String s,int type);
|
540 |
* @return Value.
|
541 |
*/
|
542 |
private Value getValue(String s) { |
543 |
Value val = new NullUniqueValue();
|
544 |
if (s.equals("Resto de Valores"))return val; |
545 |
try {
|
546 |
try {
|
547 |
val = ValueFactory.createValueByType(s, Types.INTEGER);
|
548 |
|
549 |
return val;
|
550 |
} catch (NumberFormatException e) { |
551 |
} |
552 |
|
553 |
try {
|
554 |
val = ValueFactory.createValueByType(s, Types.BIGINT);
|
555 |
|
556 |
return val;
|
557 |
} catch (NumberFormatException e) { |
558 |
} |
559 |
|
560 |
try {
|
561 |
val = ValueFactory.createValueByType(s, Types.FLOAT);
|
562 |
|
563 |
return val;
|
564 |
} catch (NumberFormatException e) { |
565 |
} |
566 |
|
567 |
try {
|
568 |
val = ValueFactory.createValueByType(s, Types.DOUBLE);
|
569 |
|
570 |
return val;
|
571 |
} catch (NumberFormatException e) { |
572 |
} |
573 |
|
574 |
val = ValueFactory.createValueByType(s, Types.LONGVARCHAR);
|
575 |
|
576 |
} catch (ParseException e) { |
577 |
log.warn("parse exception", e);
|
578 |
} |
579 |
|
580 |
return val;
|
581 |
} |
582 |
|
583 |
/**
|
584 |
* Devuelve el valor a partir de su valor en un string.
|
585 |
*
|
586 |
* @param s String con el valor.
|
587 |
*
|
588 |
* @return Value.
|
589 |
*/
|
590 |
private Value getValue(String s,int type) { |
591 |
Value val = new NullUniqueValue();
|
592 |
if (type==Types.OTHER) |
593 |
return val;
|
594 |
try {
|
595 |
val = ValueFactory.createValueByType(s, type); |
596 |
} catch (ParseException e) { |
597 |
e.printStackTrace(); |
598 |
} |
599 |
return val;
|
600 |
} |
601 |
|
602 |
public ILegend cloneLegend() throws XMLException { |
603 |
return LegendFactory.createFromXML(getXMLEntity());
|
604 |
} |
605 |
|
606 |
|
607 |
/* (non-Javadoc)
|
608 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDataSource(com.hardcode.gdbms.engine.data.DataSource)
|
609 |
*/
|
610 |
public void setDataSource(DataSource ds) throws FieldNotFoundException, |
611 |
ReadDriverException { |
612 |
dataSource = ds; |
613 |
ds.start(); |
614 |
fieldId = ds.getFieldIndexByName(getClassifyingFieldNames()[0]);
|
615 |
ds.stop(); |
616 |
} |
617 |
|
618 |
/*
|
619 |
* (non-Javadoc)
|
620 |
*
|
621 |
* @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#getSymbolByValue(com.hardcode.gdbms.engine.values.Value)
|
622 |
*/
|
623 |
public ISymbol getSymbolByValue(Value key) {
|
624 |
ISymbol symbol = symbols.get(key); |
625 |
if (symbol!=null) { |
626 |
return symbol;
|
627 |
} else if (useDefaultSymbol) { |
628 |
return getDefaultSymbol();
|
629 |
} |
630 |
return null; |
631 |
|
632 |
} |
633 |
|
634 |
public int getShapeType() { |
635 |
return shapeType;
|
636 |
} |
637 |
|
638 |
public void useDefaultSymbol(boolean b) { |
639 |
useDefaultSymbol = b; |
640 |
} |
641 |
|
642 |
/**
|
643 |
* Devuelve si se utiliza o no el resto de valores para representarse.
|
644 |
* @return True si se utiliza el resto de valores.
|
645 |
*/
|
646 |
public boolean isUseDefaultSymbol() { |
647 |
return useDefaultSymbol;
|
648 |
} |
649 |
|
650 |
public void delSymbol(Object key) { |
651 |
keys.remove(key); |
652 |
|
653 |
fireClassifiedSymbolChangeEvent( |
654 |
new SymbolLegendEvent(
|
655 |
symbols.remove(key), |
656 |
null));
|
657 |
} |
658 |
|
659 |
public String getClassName() { |
660 |
return getClass().getName();
|
661 |
} |
662 |
|
663 |
public void replace(ISymbol oldSymbol, ISymbol newSymbol) { |
664 |
if (symbols.containsValue(oldSymbol)) {
|
665 |
Iterator<Value> it = symbols.keySet().iterator();
|
666 |
while (it.hasNext()) {
|
667 |
Value key = it.next(); |
668 |
if (symbols.get(key).equals(oldSymbol)) {
|
669 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(
|
670 |
symbols.put(key, newSymbol), newSymbol)); |
671 |
} |
672 |
|
673 |
} |
674 |
} |
675 |
} |
676 |
} |