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