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