svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / VectorialUniqueValueLegend.java @ 11569
History | View | Annotate | Download (23.1 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.TreeMap; |
48 |
|
49 |
import org.geotools.filter.ExpressionBuilder; |
50 |
import org.geotools.filter.Filter; |
51 |
import org.geotools.styling.FeatureTypeStyle; |
52 |
import org.geotools.styling.NamedLayer; |
53 |
import org.geotools.styling.Rule; |
54 |
import org.geotools.styling.SLDTransformer; |
55 |
import org.geotools.styling.Style; |
56 |
import org.geotools.styling.StyleBuilder; |
57 |
import org.geotools.styling.StyleFactory; |
58 |
import org.geotools.styling.StyledLayerDescriptor; |
59 |
import org.geotools.styling.Symbolizer; |
60 |
|
61 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
62 |
import com.hardcode.gdbms.engine.data.DataSource; |
63 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
64 |
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException; |
65 |
import com.hardcode.gdbms.engine.instruction.SemanticException; |
66 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
67 |
import com.hardcode.gdbms.engine.values.NullValue; |
68 |
import com.hardcode.gdbms.engine.values.StringValue; |
69 |
import com.hardcode.gdbms.engine.values.Value; |
70 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
71 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
72 |
import com.iver.cit.gvsig.fmap.core.ISLDCompatible; |
73 |
import com.iver.cit.gvsig.fmap.core.SLDTags; |
74 |
import com.iver.cit.gvsig.fmap.core.SLDUtils; |
75 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
76 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
77 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
78 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
79 |
import com.iver.utiles.XMLEntity; |
80 |
|
81 |
/**
|
82 |
* Leyenda vectorial por valores ?nicos.
|
83 |
* @author Vicente Caballero Navarro
|
84 |
*/
|
85 |
public class VectorialUniqueValueLegend implements IVectorialUniqueValueLegend { |
86 |
private boolean sorter=true; |
87 |
|
88 |
private TreeMap symbols = new TreeMap(new Comparator() { |
89 |
public int compare(Object o1, Object o2) { |
90 |
if ((o1 != null) && (o2 != null)) { |
91 |
Value v2 = (Value) o2; |
92 |
Value v1 = (Value) o1; |
93 |
BooleanValue boolVal; |
94 |
|
95 |
// TODO estas dos comprobaciones son por evitar un bug en el gdbms, cuando se solucione se puede eliminar.
|
96 |
if (v1 instanceof NullValue && v2 instanceof NullValue) { |
97 |
return 0; |
98 |
} |
99 |
|
100 |
if (v1 instanceof NullValue) { |
101 |
return -1; |
102 |
} |
103 |
|
104 |
if (v2 instanceof NullValue) { |
105 |
return 1; |
106 |
} |
107 |
|
108 |
try {
|
109 |
boolVal = (BooleanValue) (v1.greater(v2)); |
110 |
|
111 |
if (boolVal.getValue()) {
|
112 |
return 1; |
113 |
} |
114 |
|
115 |
boolVal = (BooleanValue) (v1.less(v2)); |
116 |
|
117 |
if (boolVal.getValue()) {
|
118 |
return -1; |
119 |
} |
120 |
} catch (IncompatibleTypesException e) {
|
121 |
// TODO Auto-generated catch block
|
122 |
//e.printStackTrace();
|
123 |
} |
124 |
|
125 |
try {
|
126 |
if (((BooleanValue) v1.equals(v2)).getValue()) {
|
127 |
return 0; |
128 |
} |
129 |
} catch (IncompatibleTypesException e) {
|
130 |
// TODO Auto-generated catch block
|
131 |
//e.printStackTrace();
|
132 |
} |
133 |
|
134 |
if (v1 instanceof StringValue) { |
135 |
return -1; |
136 |
} |
137 |
|
138 |
if (v2 instanceof StringValue) { |
139 |
return 1; |
140 |
} |
141 |
} |
142 |
|
143 |
return 0; |
144 |
} |
145 |
}); // Para poder ordenar
|
146 |
private ArrayList keys = new ArrayList(); // En lugar de un HashSet, para tener acceso por ?ndice |
147 |
private String fieldName; |
148 |
protected int fieldId = -1; |
149 |
private String labelFieldName; |
150 |
private String labelFieldHeight; |
151 |
private String labelFieldRotation; |
152 |
private ISymbol defaultSymbol;
|
153 |
private DataSource dataSource; |
154 |
private int shapeType; |
155 |
private String valueType = NullValue.class.getName(); |
156 |
private boolean useDefaultSymbol = false; |
157 |
|
158 |
/**
|
159 |
* Crea un nuevo VectorialUniqueValueLegend.
|
160 |
*/
|
161 |
public VectorialUniqueValueLegend() {
|
162 |
// defaultSymbol = LegendFactory.DEFAULT_POLYGON_SYMBOL;
|
163 |
} |
164 |
|
165 |
/**
|
166 |
* Crea un nuevo VectorialUniqueValueLegend.
|
167 |
*
|
168 |
* @param shapeType Tipo de shape.
|
169 |
*/
|
170 |
public VectorialUniqueValueLegend(int shapeType) { |
171 |
setShapeType(shapeType); |
172 |
} |
173 |
|
174 |
/**
|
175 |
* @param shapeType
|
176 |
* @uml.property name="shapeType"
|
177 |
*/
|
178 |
public void setShapeType(int shapeType) { |
179 |
if (this.shapeType != shapeType) { |
180 |
/*switch (shapeType) {
|
181 |
case FShape.POINT:
|
182 |
defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT);
|
183 |
|
184 |
break;
|
185 |
|
186 |
case FShape.LINE:
|
187 |
defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE);
|
188 |
|
189 |
break;
|
190 |
|
191 |
case FShape.POLYGON:
|
192 |
defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL);
|
193 |
|
194 |
break;
|
195 |
|
196 |
default:
|
197 |
defaultSymbol = new FSymbol(shapeType);
|
198 |
}*/
|
199 |
defaultSymbol = SymbologyFactory.createDefaultSymbolByShapeType(shapeType); |
200 |
this.shapeType = shapeType;
|
201 |
} |
202 |
} |
203 |
|
204 |
public void setValueSymbolByID(int id, ISymbol symbol) { |
205 |
symbols.put(keys.get(id), symbol); |
206 |
} |
207 |
|
208 |
/**
|
209 |
* Se usa en la tabla que muestra una leyenda.
|
210 |
* @deprecated use setValueSymbolByID(int id, ISymbol symbol);
|
211 |
* @param id
|
212 |
* @param symbol
|
213 |
*/
|
214 |
public void setValueSymbol(int id, ISymbol symbol) { |
215 |
symbols.put(keys.get(id), symbol); |
216 |
} |
217 |
|
218 |
public Object[] getValues() { |
219 |
return symbols.keySet().toArray(new Object[0]); |
220 |
} |
221 |
|
222 |
public void addSymbol(Object key, ISymbol symbol) { |
223 |
Object resul;
|
224 |
resul = symbols.put(key, symbol); |
225 |
|
226 |
if (resul != null) { |
227 |
System.err.println("Error: la clave " + key + |
228 |
" ya exist?a. Resul = " + resul);
|
229 |
System.err.println("symbol nuevo:" + symbol.getDescription() + |
230 |
" Sviejo= " + ((ISymbol) resul).getDescription());
|
231 |
} else {
|
232 |
keys.add(key); |
233 |
|
234 |
if (!key.getClass().equals(NullValue.class)) {
|
235 |
valueType = key.getClass().getName(); |
236 |
} |
237 |
} |
238 |
} |
239 |
|
240 |
public void clear() { |
241 |
keys.clear(); |
242 |
symbols.clear(); |
243 |
} |
244 |
|
245 |
public String[] getDescriptions() { |
246 |
String[] descriptions = new String[symbols.size()]; |
247 |
ISymbol[] auxSym = getSymbols();
|
248 |
|
249 |
for (int i = 0; i < descriptions.length; i++) |
250 |
descriptions[i] = auxSym[i].getDescription(); |
251 |
|
252 |
return descriptions;
|
253 |
} |
254 |
|
255 |
/**
|
256 |
* @return
|
257 |
* @uml.property name="symbols"
|
258 |
*/
|
259 |
public ISymbol[] getSymbols() { |
260 |
return (ISymbol[]) symbols.values().toArray(new ISymbol[0]); |
261 |
} |
262 |
|
263 |
/**
|
264 |
* @return
|
265 |
* @uml.property name="fieldName"
|
266 |
*/
|
267 |
public String getFieldName() { |
268 |
return fieldName;
|
269 |
} |
270 |
|
271 |
/**
|
272 |
* @param s
|
273 |
* @uml.property name="defaultSymbol"
|
274 |
*/
|
275 |
public void setDefaultSymbol(ISymbol s) { |
276 |
defaultSymbol = s; |
277 |
} |
278 |
|
279 |
public String getLabelField() { |
280 |
return labelFieldName;
|
281 |
} |
282 |
|
283 |
public void setLabelField(String fieldName) { |
284 |
labelFieldName = fieldName; |
285 |
} |
286 |
|
287 |
/**
|
288 |
* @param str
|
289 |
* @uml.property name="fieldName"
|
290 |
*/
|
291 |
public void setFieldName(String str) { |
292 |
fieldName = str; |
293 |
} |
294 |
|
295 |
/**
|
296 |
* @see com.iver.cit.gvsig.fmap.rendering.IVectorialLegend#getSymbol(int)
|
297 |
*/
|
298 |
public ISymbol getSymbol(int recordIndex) throws ReadDriverException { |
299 |
Value val = dataSource.getFieldValue(recordIndex, fieldId); |
300 |
ISymbol theSymbol = getSymbolByValue(val); |
301 |
|
302 |
// if (theSymbol != null) {
|
303 |
return theSymbol;
|
304 |
|
305 |
// } else {
|
306 |
// return getDefaultSymbol();
|
307 |
// }
|
308 |
} |
309 |
|
310 |
/**
|
311 |
* Devuelve un s?mbolo a partir de una IFeature. OJO!! Cuando usamos un
|
312 |
* feature iterator de base de datos el ?nico campo que vendr? rellenado es
|
313 |
* el de fieldID. Los dem?s vendr?n a nulos para ahorra tiempo de creaci?n.
|
314 |
*
|
315 |
* @param feat
|
316 |
* IFeature
|
317 |
*
|
318 |
* @return S?mbolo.
|
319 |
*/
|
320 |
public ISymbol getSymbolByFeature(IFeature feat) {
|
321 |
Value val = feat.getAttribute(fieldId); |
322 |
// Value val = feat.getAttribute(0);
|
323 |
ISymbol theSymbol = getSymbolByValue(val); |
324 |
|
325 |
//if (theSymbol != null) {
|
326 |
return theSymbol;
|
327 |
|
328 |
//} else {
|
329 |
// return getDefaultSymbol();
|
330 |
//}
|
331 |
} |
332 |
|
333 |
/**
|
334 |
* @return
|
335 |
* @uml.property name="defaultSymbol"
|
336 |
*/
|
337 |
public ISymbol getDefaultSymbol() {
|
338 |
NullUniqueValue nuv=new NullUniqueValue();
|
339 |
if (symbols.containsKey(nuv))
|
340 |
return (ISymbol)symbols.get(nuv);
|
341 |
return defaultSymbol;
|
342 |
} |
343 |
|
344 |
/**
|
345 |
* @deprecated
|
346 |
* Writes and SLD using GEOTOOLS objetcs.
|
347 |
* @see com.iver.cit.gvsig.fmap.rendering.ILegend#getSLDString()
|
348 |
*/
|
349 |
public String getSLDString_() |
350 |
{ |
351 |
try{
|
352 |
StyledLayerDescriptor sld = new StyledLayerDescriptor();
|
353 |
StyleFactory styleFactory = StyleFactory.createStyleFactory(); |
354 |
StyleBuilder sb = new StyleBuilder();
|
355 |
Style style = sb.createStyle();
|
356 |
style.setName("default");
|
357 |
Filter filter = null; |
358 |
Rule rule = null;
|
359 |
|
360 |
FeatureTypeStyle featStyle = styleFactory.createFeatureTypeStyle(); |
361 |
featStyle.setFeatureTypeName(fieldName); |
362 |
|
363 |
ISymbol[] symbols = this.getSymbols(); |
364 |
Symbolizer[] theSymbolizers = new Symbolizer[symbols.length]; |
365 |
Object[] values = this.getValues(); |
366 |
String valueStr = null; |
367 |
String condition = null; |
368 |
|
369 |
for(int i = 0; i < symbols.length; i++ ) |
370 |
{ |
371 |
valueStr = values[i].toString(); |
372 |
//if(this.valueType == "")
|
373 |
condition = fieldName +"='"+valueStr+"'"; |
374 |
//else
|
375 |
// condition = fieldName +"="+values[i];
|
376 |
filter = (Filter)ExpressionBuilder.parse(condition);
|
377 |
theSymbolizers[0] = SLDUtils.toGeotoolsSymbol(symbols[i]);
|
378 |
rule = styleFactory.createRule(); |
379 |
rule.setName(valueStr); |
380 |
rule.setTitle(valueStr); |
381 |
rule.setFilter(filter); |
382 |
rule.setSymbolizers((Symbolizer[])theSymbolizers.clone());
|
383 |
featStyle.addRule(rule); |
384 |
} |
385 |
style.addFeatureTypeStyle(featStyle); |
386 |
SLDTransformer st = new SLDTransformer();
|
387 |
NamedLayer namedLayer = new NamedLayer();
|
388 |
namedLayer.setName("comunidades");
|
389 |
namedLayer.addStyle(style); |
390 |
sld.addStyledLayer(namedLayer); |
391 |
return st.transform(style);
|
392 |
|
393 |
}catch(Exception e) |
394 |
{ |
395 |
e.printStackTrace(); |
396 |
return null; |
397 |
} |
398 |
} |
399 |
|
400 |
public String getSLDString(String name) |
401 |
{ |
402 |
try{
|
403 |
|
404 |
XmlBuilder xmlBuilder = new XmlBuilder();
|
405 |
xmlBuilder.writeHeader(); |
406 |
xmlBuilder.openTag(SLDTags.SLD_ROOT, SLDTags.VERSION_ATTR, SLDTags.VERSION_1_0_0); |
407 |
xmlBuilder.openTag(SLDTags.NAMEDLAYER); |
408 |
xmlBuilder.writeTag(SLDTags.NAME,name); |
409 |
xmlBuilder.openTag(SLDTags.USERSTYLE); |
410 |
xmlBuilder.openTag(SLDTags.FEATURETYPESTYLE); |
411 |
//xmlBuilder.writeTag(SLDTags.FEATURETYPENAME,"fieldName");
|
412 |
|
413 |
ISymbol[] symbols = this.getSymbols(); |
414 |
Object[] values = this.getValues(); |
415 |
String valueStr = null; |
416 |
|
417 |
for(int i = 0; i < symbols.length; i++ ) |
418 |
{ |
419 |
valueStr = values[i].toString(); |
420 |
xmlBuilder.openTag(SLDTags.RULE); |
421 |
xmlBuilder.writeTag(SLDTags.NAME, valueStr); |
422 |
xmlBuilder.openTag(SLDTags.FILTER); |
423 |
xmlBuilder.openTag(SLDTags.PROPERTYISEQUALTO); |
424 |
xmlBuilder.writeTag(SLDTags.PROPERTYNAME,fieldName); |
425 |
xmlBuilder.writeTag(SLDTags.LITERAL, valueStr); |
426 |
xmlBuilder.closeTag(); |
427 |
xmlBuilder.closeTag(); |
428 |
if (symbols[i] instanceof ISLDCompatible) |
429 |
{ |
430 |
ISLDCompatible symSLD = (ISLDCompatible) symbols[i]; |
431 |
xmlBuilder.writeRaw(symSLD.toSLD()); |
432 |
} |
433 |
else
|
434 |
throw new RuntimeException("Cannot convert Symbol " + i + " " + symbols[i].getDescription() + " to SLD"); |
435 |
|
436 |
xmlBuilder.closeTag(); |
437 |
} |
438 |
|
439 |
xmlBuilder.closeTag(); |
440 |
xmlBuilder.closeTag(); |
441 |
xmlBuilder.closeTag(); |
442 |
xmlBuilder.closeTag(); |
443 |
return xmlBuilder.getXML();
|
444 |
|
445 |
}catch(Exception e) |
446 |
{ |
447 |
e.printStackTrace(); |
448 |
return null; |
449 |
} |
450 |
} |
451 |
|
452 |
public XMLEntity getXMLEntity() {
|
453 |
XMLEntity xml = new XMLEntity();
|
454 |
xml.putProperty("className", this.getClass().getName()); |
455 |
xml.putProperty("fieldName", fieldName);
|
456 |
xml.putProperty("labelfield", labelFieldName);
|
457 |
xml.putProperty("labelFieldHeight", labelFieldHeight);
|
458 |
xml.putProperty("labelFieldRotation", labelFieldRotation);
|
459 |
|
460 |
xml.putProperty("useDefaultSymbol", useDefaultSymbol);
|
461 |
xml.putProperty("sorter",sorter);
|
462 |
xml.addChild(getDefaultSymbol().getXMLEntity()); |
463 |
// xml.putProperty("isBWithHeightText", isBWithHeightText());
|
464 |
xml.putProperty("numKeys", keys.size());
|
465 |
|
466 |
if (keys.size() > 0) { |
467 |
xml.putProperty("tipoValueKeys", valueType);
|
468 |
|
469 |
String[] sk = new String[keys.size()]; |
470 |
String[] sv = new String[keys.size()]; |
471 |
int[] stk = new int[keys.size()]; |
472 |
int[] stv = new int[keys.size()]; |
473 |
ISymbol[] fsymbols = getSymbols();
|
474 |
Object[] values = getValues(); |
475 |
|
476 |
for (int i = 0; i < keys.size(); i++) { |
477 |
if (((Value) keys.get(i)).toString().equals("")) { |
478 |
sk[i] =" ";
|
479 |
}else {
|
480 |
sk[i] = ((Value) keys.get(i)).toString(); |
481 |
} |
482 |
if (((Value) values[i]).toString().equals("")) { |
483 |
sv[i] =" ";
|
484 |
}else {
|
485 |
sv[i] = ((Value) values[i]).toString(); |
486 |
} |
487 |
stk[i]= ((Value)keys.get(i)).getSQLType(); |
488 |
stv[i]= ((Value)values[i]).getSQLType(); |
489 |
xml.addChild(fsymbols[i].getXMLEntity()); |
490 |
|
491 |
///System.out.println("get-----------"+sk[i]+"--"+fsymbols[i].getDescription()+"---"+fsymbols[i].getColor());
|
492 |
} |
493 |
|
494 |
xml.putProperty("keys", sk);
|
495 |
xml.putProperty("values", sv);
|
496 |
xml.putProperty("typeKeys",stk);
|
497 |
xml.putProperty("typeValues",stv);
|
498 |
} |
499 |
|
500 |
return xml;
|
501 |
} |
502 |
|
503 |
public void setXMLEntity03(XMLEntity xml) { |
504 |
clear(); |
505 |
setFieldName(xml.getStringProperty("fieldName"));
|
506 |
setLabelField(xml.getStringProperty("labelfield"));
|
507 |
|
508 |
int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol"); |
509 |
|
510 |
if (useDefaultSymbol == 1) { |
511 |
setDefaultSymbol(FSymbol.createFromXML03(xml.getChild(0)));
|
512 |
} else {
|
513 |
setDefaultSymbol(null);
|
514 |
} |
515 |
|
516 |
int numKeys = xml.getIntProperty("numKeys"); |
517 |
|
518 |
if (numKeys > 0) { |
519 |
String className = xml.getStringProperty("tipoValueKeys"); |
520 |
String[] sk = xml.getStringArrayProperty("keys"); |
521 |
String[] sv = xml.getStringArrayProperty("values"); |
522 |
Value auxValue; |
523 |
Value auxValue2; |
524 |
|
525 |
for (int i = 0; i < numKeys; i++) { |
526 |
try {
|
527 |
auxValue = ValueFactory.createValue(sk[i], className); |
528 |
auxValue2 = ValueFactory.createValue(sv[i], className); |
529 |
|
530 |
ISymbol sym = FSymbol.createFromXML03(xml.getChild(i + |
531 |
useDefaultSymbol)); |
532 |
|
533 |
///addSymbol(auxValue, sym);
|
534 |
symbols.put(auxValue2, sym); |
535 |
keys.add(auxValue); |
536 |
|
537 |
///System.out.println("---set------"+auxValue.toString());
|
538 |
/// System.out.println("set-----------"+sk[i]+"--"+sym.getDescription()+"---"+sym.getColor());
|
539 |
} catch (SemanticException e) {
|
540 |
// TODO Auto-generated catch block
|
541 |
e.printStackTrace(); |
542 |
} |
543 |
} |
544 |
} |
545 |
} |
546 |
|
547 |
public void setXMLEntity(XMLEntity xml) { |
548 |
clear(); |
549 |
setFieldName(xml.getStringProperty("fieldName"));
|
550 |
setLabelField(xml.getStringProperty("labelfield"));
|
551 |
|
552 |
if (xml.contains("labelFieldHeight")) { |
553 |
setLabelHeightField(xml.getStringProperty("labelFieldHeight"));
|
554 |
} |
555 |
|
556 |
if (xml.contains("labelFieldRotation")) { |
557 |
setLabelRotationField(xml.getStringProperty("labelFieldRotation"));
|
558 |
} |
559 |
|
560 |
useDefaultSymbol = xml.getBooleanProperty("useDefaultSymbol");
|
561 |
if (xml.contains("sorter")) |
562 |
sorter = xml.getBooleanProperty("sorter");
|
563 |
setDefaultSymbol(FSymbol.createFromXML(xml.getChild(0)));
|
564 |
|
565 |
// FJP: Esto no es necesario ya. Para comprobar si tenemos un campo de altura, miramos
|
566 |
// si getLabelHeightField devuelve null o no.
|
567 |
/* if (xml.contains("isBWithHeightText")) {
|
568 |
setBWithHeightText(xml.getBooleanProperty("isBWithHeightText"));
|
569 |
} */
|
570 |
|
571 |
//addSymbol(new NullUniqueValue(),getDefaultSymbol());
|
572 |
int numKeys = xml.getIntProperty("numKeys"); |
573 |
|
574 |
if (numKeys > 0) { |
575 |
String className = xml.getStringProperty("tipoValueKeys"); |
576 |
String[] sk = xml.getStringArrayProperty("keys"); |
577 |
String[] sv = xml.getStringArrayProperty("values"); |
578 |
Value auxValue = null;
|
579 |
Value auxValue2 = null;
|
580 |
int[] stk=null; |
581 |
if (xml.contains("typeKeys")) { |
582 |
stk = xml.getIntArrayProperty("typeKeys");
|
583 |
int[] stv = xml.getIntArrayProperty("typeValues"); |
584 |
for (int i = 0; i < numKeys; i++) { |
585 |
boolean isDefault = false; |
586 |
if (getValue(sk[i], stk[i]) == null) { |
587 |
isDefault = true;
|
588 |
} |
589 |
|
590 |
if (className
|
591 |
.equals("com.hardcode.gdbms.engine.values.NullUniqueValue")
|
592 |
|| isDefault) { |
593 |
auxValue = new NullUniqueValue();
|
594 |
auxValue2 = ValueFactory.createNullValue(); |
595 |
} else {
|
596 |
auxValue = getValue(sk[i], stk[i]); // ValueFactory.createValue(sk[i],
|
597 |
// className);
|
598 |
auxValue2 = getValue(sv[i], stv[i]); // ValueFactory.createValue(sv[i],
|
599 |
// className);
|
600 |
} |
601 |
|
602 |
// (substituir la de baix per esta) ISymbol sym = SymbolFactory.createFromXML(xml.getChild(i + 1), null);
|
603 |
ISymbol sym = FSymbol.createFromXML(xml.getChild(i + 1));
|
604 |
symbols.put(auxValue2, sym); |
605 |
keys.add(auxValue); |
606 |
} |
607 |
} else {
|
608 |
for (int i = 0; i < numKeys; i++) { |
609 |
boolean isDefault = false; |
610 |
if (getValue(sk[i]) == null) { |
611 |
isDefault = true;
|
612 |
} |
613 |
if (className
|
614 |
.equals("com.hardcode.gdbms.engine.values.NullUniqueValue")
|
615 |
|| isDefault) { |
616 |
auxValue = new NullUniqueValue();
|
617 |
auxValue2 = ValueFactory.createNullValue(); |
618 |
} else {
|
619 |
auxValue = getValue(sk[i]); // ValueFactory.createValue(sk[i],
|
620 |
// className);
|
621 |
auxValue2 = getValue(sv[i]); // ValueFactory.createValue(sv[i],
|
622 |
// className);
|
623 |
} |
624 |
ISymbol sym = FSymbol.createFromXML(xml.getChild(i + 1));
|
625 |
symbols.put(auxValue2, sym); |
626 |
keys.add(auxValue); |
627 |
} |
628 |
} |
629 |
} |
630 |
} |
631 |
|
632 |
/**
|
633 |
* Devuelve el valor a partir de su valor en un string.
|
634 |
*
|
635 |
* @param s
|
636 |
* String con el valor.
|
637 |
* @deprecated M?todo utilizado hasta la 1.0 alpha 855 Debes utilizar a partir de ahora getValue(String s,int type);
|
638 |
* @return Value.
|
639 |
*/
|
640 |
private Value getValue(String s) { |
641 |
Value val = new NullUniqueValue();
|
642 |
if (s.equals("Resto de Valores"))return val; |
643 |
try {
|
644 |
try {
|
645 |
val = ValueFactory.createValueByType(s, Types.INTEGER);
|
646 |
|
647 |
return val;
|
648 |
} catch (NumberFormatException e) { |
649 |
} |
650 |
|
651 |
try {
|
652 |
val = ValueFactory.createValueByType(s, Types.BIGINT);
|
653 |
|
654 |
return val;
|
655 |
} catch (NumberFormatException e) { |
656 |
} |
657 |
|
658 |
try {
|
659 |
val = ValueFactory.createValueByType(s, Types.FLOAT);
|
660 |
|
661 |
return val;
|
662 |
} catch (NumberFormatException e) { |
663 |
} |
664 |
|
665 |
try {
|
666 |
val = ValueFactory.createValueByType(s, Types.DOUBLE);
|
667 |
|
668 |
return val;
|
669 |
} catch (NumberFormatException e) { |
670 |
} |
671 |
|
672 |
val = ValueFactory.createValueByType(s, Types.LONGVARCHAR);
|
673 |
|
674 |
} catch (ParseException e) { |
675 |
e.printStackTrace(); |
676 |
} |
677 |
|
678 |
return val;
|
679 |
} |
680 |
|
681 |
/**
|
682 |
* Devuelve el valor a partir de su valor en un string.
|
683 |
*
|
684 |
* @param s String con el valor.
|
685 |
*
|
686 |
* @return Value.
|
687 |
*/
|
688 |
private Value getValue(String s,int type) { |
689 |
Value val = new NullUniqueValue();
|
690 |
if (type==Types.OTHER) |
691 |
return val;
|
692 |
try {
|
693 |
val = ValueFactory.createValueByType(s, type); |
694 |
} catch (ParseException e) { |
695 |
e.printStackTrace(); |
696 |
} |
697 |
return val;
|
698 |
} |
699 |
|
700 |
public ILegend cloneLegend() throws XMLException { |
701 |
return LegendFactory.createFromXML(getXMLEntity());
|
702 |
} |
703 |
|
704 |
|
705 |
/* (non-Javadoc)
|
706 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDataSource(com.hardcode.gdbms.engine.data.DataSource)
|
707 |
*/
|
708 |
public void setDataSource(DataSource ds) throws FieldNotFoundException, |
709 |
ReadDriverException { |
710 |
dataSource = ds; |
711 |
ds.start(); |
712 |
fieldId = ds.getFieldIndexByName(fieldName); |
713 |
ds.stop(); |
714 |
} |
715 |
|
716 |
/*
|
717 |
* (non-Javadoc)
|
718 |
*
|
719 |
* @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#getSymbolByValue(com.hardcode.gdbms.engine.values.Value)
|
720 |
*/
|
721 |
public ISymbol getSymbolByValue(Value key) {
|
722 |
boolean auxSorted=sorter;
|
723 |
sorter=true;
|
724 |
ISymbol symbol=(ISymbol) symbols.get(key); |
725 |
sorter=auxSorted; |
726 |
if (symbol!=null) { |
727 |
return symbol;
|
728 |
} else if (useDefaultSymbol) { |
729 |
return getDefaultSymbol();
|
730 |
} |
731 |
return null; |
732 |
|
733 |
} |
734 |
|
735 |
/**
|
736 |
* @return
|
737 |
* @uml.property name="shapeType"
|
738 |
*/
|
739 |
public int getShapeType() { |
740 |
return shapeType;
|
741 |
} |
742 |
|
743 |
public String getLabelHeightField() { |
744 |
return labelFieldHeight;
|
745 |
} |
746 |
|
747 |
public void setLabelHeightField(String str) { |
748 |
labelFieldHeight = str; |
749 |
} |
750 |
|
751 |
public String getLabelRotationField() { |
752 |
return labelFieldRotation;
|
753 |
} |
754 |
|
755 |
public void setLabelRotationField(String str) { |
756 |
labelFieldRotation = str; |
757 |
} |
758 |
|
759 |
public void useDefaultSymbol(boolean b) { |
760 |
useDefaultSymbol = b; |
761 |
} |
762 |
|
763 |
/**
|
764 |
* Devuelve si se utiliza o no el resto de valores para representarse.
|
765 |
* @return True si se utiliza el resto de valores.
|
766 |
* @uml.property name="useDefaultSymbol"
|
767 |
*/
|
768 |
public boolean isUseDefaultSymbol() { |
769 |
return useDefaultSymbol;
|
770 |
} |
771 |
|
772 |
public void delSymbol(Object key) { |
773 |
keys.remove(key); |
774 |
symbols.remove(key); |
775 |
} |
776 |
|
777 |
public String[] getUsedFields() { |
778 |
ArrayList usedFields = new ArrayList(); |
779 |
if (getFieldName() != null) |
780 |
usedFields.add(getFieldName()); |
781 |
if (getLabelField() != null) |
782 |
usedFields.add(getLabelField()); |
783 |
if (getLabelHeightField() != null) |
784 |
usedFields.add(getLabelHeightField()); |
785 |
if (getLabelRotationField() != null) |
786 |
usedFields.add(getLabelRotationField()); |
787 |
|
788 |
return (String[]) usedFields.toArray(new String[0]); |
789 |
|
790 |
} |
791 |
|
792 |
public void setSorter(boolean b) { |
793 |
sorter=b; |
794 |
} |
795 |
|
796 |
public boolean isSorter() { |
797 |
return sorter;
|
798 |
} |
799 |
} |