root / tags / v1_0_2_Build_910 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / VectorialIntervalLegend.java @ 11275
History | View | Annotate | Download (23.3 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.awt.Color; |
44 |
import java.util.ArrayList; |
45 |
import java.util.Comparator; |
46 |
import java.util.TreeMap; |
47 |
|
48 |
import com.hardcode.gdbms.engine.data.DataSource; |
49 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
50 |
import com.hardcode.gdbms.engine.values.Value; |
51 |
import com.iver.cit.gvsig.fmap.DriverException; |
52 |
import com.iver.cit.gvsig.fmap.core.FShape; |
53 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
54 |
import com.iver.cit.gvsig.fmap.core.ISLDCompatible; |
55 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
56 |
import com.iver.cit.gvsig.fmap.core.SLDTags; |
57 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
58 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
59 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
60 |
import com.iver.utiles.StringUtilities; |
61 |
import com.iver.utiles.XMLEntity; |
62 |
|
63 |
|
64 |
/**
|
65 |
* Leyenda Vectorial por intervalos.
|
66 |
*
|
67 |
* @author Vicente Caballero Navarro
|
68 |
*/
|
69 |
public class VectorialIntervalLegend implements IntervalLegend, VectorialLegend { |
70 |
public final static int EQUAL_INTERVALS = 0; |
71 |
public final static int NATURAL_INTERVALS = 1; |
72 |
public final static int QUANTILE_INTERVALS = 2; |
73 |
private TreeMap symbols = new TreeMap(new Comparator() { |
74 |
public int compare(Object o1, Object o2) { |
75 |
if ((o1 != null) && (o2 != null)) { |
76 |
if (o1 instanceof NullIntervalValue && |
77 |
o2 instanceof NullIntervalValue) {
|
78 |
return 0; |
79 |
} |
80 |
|
81 |
if (o2 instanceof NullIntervalValue) { |
82 |
return 1; |
83 |
} |
84 |
|
85 |
if (o1 instanceof NullIntervalValue) { |
86 |
return -1; |
87 |
} |
88 |
|
89 |
FInterval i2 = (FInterval) o2; |
90 |
FInterval i1 = (FInterval) o1; |
91 |
|
92 |
if (i1.getMin() > i2.getMin()) {
|
93 |
return 1; |
94 |
} |
95 |
|
96 |
if (i1.getMin() < i2.getMin()) {
|
97 |
return -1; |
98 |
} |
99 |
} |
100 |
|
101 |
return 0; |
102 |
} |
103 |
}); // Para poder ordenar
|
104 |
private ArrayList keys = new ArrayList(); // En lugar de un HashSet, para tener acceso por ?ndice |
105 |
private int index = 0; |
106 |
private String fieldName; |
107 |
private int fieldId; |
108 |
private String labelFieldName; |
109 |
private String labelFieldHeight; |
110 |
private String labelFieldRotation; |
111 |
private ISymbol defaultSymbol;
|
112 |
private DataSource dataSource; |
113 |
private Color startColor = Color.red; |
114 |
private Color endColor = Color.blue; |
115 |
private int shapeType; |
116 |
private int intervalType = NATURAL_INTERVALS; |
117 |
private boolean useDefaultSymbol = false; |
118 |
// private boolean bWithHeightText;
|
119 |
|
120 |
/**
|
121 |
* Crea un nuevo VectorialIntervalLegend.
|
122 |
*/
|
123 |
public VectorialIntervalLegend() {
|
124 |
//defaultSymbol = LegendFactory.DEFAULT_POLYGON_SYMBOL;
|
125 |
} |
126 |
|
127 |
/**
|
128 |
* Crea un nuevo VectorialIntervalLegend.
|
129 |
*
|
130 |
* @param type tipo de shape.
|
131 |
*/
|
132 |
public VectorialIntervalLegend(int type) { |
133 |
setShapeType(type); |
134 |
} |
135 |
|
136 |
/**
|
137 |
* @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#addSymbol(java.lang.Object,
|
138 |
* ISymbol)
|
139 |
*/
|
140 |
public void addSymbol(Object key, ISymbol symbol) { |
141 |
//TODO guardar los intervalos.
|
142 |
Object resul;
|
143 |
resul = symbols.put(key, symbol); |
144 |
|
145 |
/*if (resul != null) {
|
146 |
System.err.println("Error: la clave " + key +
|
147 |
" ya exist?a. Resul = " + resul);
|
148 |
System.err.println("symbol nuevo:" + symbol.m_Descrip +
|
149 |
" Sviejo= " + ((FSymbol) resul).m_Descrip);
|
150 |
} else {
|
151 |
*/
|
152 |
keys.add(key); |
153 |
|
154 |
//}
|
155 |
} |
156 |
|
157 |
/*
|
158 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#getSymbol(java.lang.Object)
|
159 |
*
|
160 |
public FStyle2D getSymbol(Object value) {
|
161 |
return (FStyle2D) symbols.get(value);
|
162 |
}
|
163 |
// TODO transformar la funci?n anterior en la siguiente
|
164 |
*
|
165 |
*/
|
166 |
|
167 |
/**
|
168 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getSymbol(int)
|
169 |
*/
|
170 |
public ISymbol getSymbol(int recordIndex) throws DriverException { |
171 |
try {
|
172 |
Value val = dataSource.getFieldValue(recordIndex, fieldId); |
173 |
IInterval interval = getInterval(val); |
174 |
FSymbol theSymbol = getSymbolByInterval(interval); |
175 |
|
176 |
if (theSymbol != null) { |
177 |
return theSymbol;
|
178 |
} else if (useDefaultSymbol) { |
179 |
return getDefaultSymbol();
|
180 |
} |
181 |
|
182 |
return null; |
183 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
184 |
throw new DriverException(e); |
185 |
} |
186 |
} |
187 |
|
188 |
/**
|
189 |
* Devuelve un s?mbolo a partir de una IFeature.
|
190 |
* OJO!! Cuando usamos un feature iterator de base de datos
|
191 |
* el ?nico campo que vendr? rellenado es el de fieldID.
|
192 |
* Los dem?s vendr?n a nulos para ahorra tiempo de creaci?n.
|
193 |
*
|
194 |
* @param feat IFeature.
|
195 |
*
|
196 |
* @return S?mbolo.
|
197 |
*/
|
198 |
public ISymbol getSymbolByFeature(IFeature feat) {
|
199 |
Value val = feat.getAttribute(fieldId); |
200 |
IInterval interval = getInterval(val); |
201 |
FSymbol theSymbol = getSymbolByInterval(interval); |
202 |
|
203 |
if (theSymbol != null) { |
204 |
return theSymbol;
|
205 |
} else {
|
206 |
return getDefaultSymbol();
|
207 |
} |
208 |
} |
209 |
|
210 |
/**
|
211 |
* Devuelve el s?mbolo a partir del intervalo.
|
212 |
*
|
213 |
* @param key intervalo.
|
214 |
*
|
215 |
* @return s?mbolo.
|
216 |
*/
|
217 |
public FSymbol getSymbolByInterval(IInterval key) {
|
218 |
if (key == null) { |
219 |
return null; |
220 |
} |
221 |
|
222 |
if (symbols.containsKey(key)) {
|
223 |
return (FSymbol) symbols.get(key);
|
224 |
} |
225 |
|
226 |
return null; |
227 |
} |
228 |
|
229 |
/**
|
230 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getDescriptions()
|
231 |
*/
|
232 |
public String[] getDescriptions() { |
233 |
String[] descriptions = new String[symbols.size()]; |
234 |
ISymbol[] auxSym = getSymbols();
|
235 |
|
236 |
for (int i = 0; i < descriptions.length; i++) |
237 |
descriptions[i] = auxSym[i].getDescription(); |
238 |
|
239 |
return descriptions;
|
240 |
} |
241 |
|
242 |
/**
|
243 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getValues()
|
244 |
*/
|
245 |
public Object[] getValues() { |
246 |
return (Object[]) symbols.keySet().toArray(new Object[0]); |
247 |
} |
248 |
|
249 |
/**
|
250 |
* @see com.iver.cit.gvsig.fmap.rendering.IntervalLegend#setIntervalSymbol(com.iver.cit.gvsig.fmap.rendering.FInterval,
|
251 |
* org.geotools.renderer.style.Style2D)
|
252 |
*/
|
253 |
public void setIntervalSymbol(IInterval interval, FSymbol symbol) { |
254 |
/*symbols.put(interval, symbol);
|
255 |
values.put(new Integer(index), interval);
|
256 |
index++;
|
257 |
*/
|
258 |
} |
259 |
|
260 |
/**
|
261 |
* @see com.iver.cit.gvsig.fmap.rendering.IntervalLegend#changeInterval(int,
|
262 |
* com.iver.cit.gvsig.fmap.rendering.FInterval)
|
263 |
*/
|
264 |
public void changeInterval(int index, IInterval newInterval) { |
265 |
/*Object value = values.remove(new Integer(index));
|
266 |
Object symbol = symbols.remove(value);
|
267 |
values.put(new Integer(index), newInterval);
|
268 |
symbols.put(newInterval, symbol);
|
269 |
*/
|
270 |
} |
271 |
|
272 |
/**
|
273 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#clear()
|
274 |
*/
|
275 |
public void clear() { |
276 |
index = 0;
|
277 |
keys.clear(); |
278 |
symbols.clear(); |
279 |
} |
280 |
|
281 |
/**
|
282 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#getSymbols()
|
283 |
*/
|
284 |
public ISymbol[] getSymbols() { |
285 |
return (FSymbol[]) symbols.values().toArray(new FSymbol[0]); |
286 |
} |
287 |
|
288 |
/**
|
289 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#getFieldName()
|
290 |
*/
|
291 |
public String getFieldName() { |
292 |
return fieldName;
|
293 |
} |
294 |
|
295 |
/**
|
296 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDefaultSymbol(ISymbol)
|
297 |
*/
|
298 |
public void setDefaultSymbol(ISymbol s) { |
299 |
defaultSymbol = s; |
300 |
} |
301 |
|
302 |
/**
|
303 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#setFieldName(String)
|
304 |
*/
|
305 |
public void setFieldName(String str) { |
306 |
fieldName = str; |
307 |
} |
308 |
|
309 |
/**
|
310 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#setLabelField(int)
|
311 |
*/
|
312 |
public void setLabelField(String fieldName) { |
313 |
labelFieldName = fieldName; |
314 |
} |
315 |
|
316 |
/**
|
317 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#getLabelField()
|
318 |
*/
|
319 |
public String getLabelField() { |
320 |
return labelFieldName;
|
321 |
} |
322 |
|
323 |
/**
|
324 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#getDefaultSymbol()
|
325 |
*/
|
326 |
public ISymbol getDefaultSymbol() {
|
327 |
NullIntervalValue niv=new NullIntervalValue();
|
328 |
if (symbols.containsKey(niv))
|
329 |
return (ISymbol)symbols.get(niv);
|
330 |
return defaultSymbol;
|
331 |
} |
332 |
|
333 |
/**
|
334 |
* creates the SLD String that defines this legend type.
|
335 |
*/
|
336 |
public String getSLDString(String layerName) { |
337 |
|
338 |
try{
|
339 |
|
340 |
XmlBuilder xmlBuilder = new XmlBuilder();
|
341 |
xmlBuilder.writeHeader(); |
342 |
xmlBuilder.openTag(SLDTags.SLD_ROOT, SLDTags.VERSION_ATTR, SLDTags.VERSION_1_0_0); |
343 |
xmlBuilder.openTag(SLDTags.NAMEDLAYER); |
344 |
xmlBuilder.writeTag(SLDTags.NAME,layerName); |
345 |
xmlBuilder.openTag(SLDTags.USERSTYLE); |
346 |
xmlBuilder.openTag(SLDTags.FEATURETYPESTYLE); |
347 |
xmlBuilder.writeTag(SLDTags.FEATURETYPENAME,fieldName); |
348 |
|
349 |
ISymbol[] symbols = this.getSymbols(); |
350 |
Object[] values = this.getValues(); |
351 |
|
352 |
FInterval interval; |
353 |
for(int i = 0; i < symbols.length; i++ ) |
354 |
{ |
355 |
interval = (FInterval)values[i]; |
356 |
//interval = (FInterval)getInterval(ValueFactory.createValue(valueDbl.doubleValue()));
|
357 |
xmlBuilder.openTag(SLDTags.RULE); |
358 |
xmlBuilder.writeTag(SLDTags.NAME, ""+interval.getMin() +" - " +interval.getMax()); |
359 |
xmlBuilder.openTag(SLDTags.FILTER); |
360 |
xmlBuilder.openTag(SLDTags.AND); |
361 |
xmlBuilder.openTag(SLDTags.PROPERTYISGREATEROREQUALTHAN); |
362 |
xmlBuilder.writeTag(SLDTags.PROPERTYNAME,fieldName); |
363 |
xmlBuilder.writeTag(SLDTags.LITERAL, ""+interval.getMin());
|
364 |
xmlBuilder.closeTag(); |
365 |
xmlBuilder.openTag(SLDTags.PROPERTYISLESSOREQUALTHAN); |
366 |
xmlBuilder.writeTag(SLDTags.PROPERTYNAME,fieldName); |
367 |
xmlBuilder.writeTag(SLDTags.LITERAL, ""+interval.getMax());
|
368 |
xmlBuilder.closeTag(); |
369 |
xmlBuilder.closeTag(); |
370 |
if (symbols[i] instanceof ISLDCompatible) |
371 |
{ |
372 |
ISLDCompatible symSLD = (ISLDCompatible) symbols[i]; |
373 |
xmlBuilder.writeRaw(symSLD.toSLD()); |
374 |
} |
375 |
else
|
376 |
throw new RuntimeException("Cannot convert Symbol " + i + " " + symbols[i].getDescription() + " to SLD"); |
377 |
xmlBuilder.closeTag(); |
378 |
xmlBuilder.closeTag(); |
379 |
} |
380 |
|
381 |
xmlBuilder.closeTag(); |
382 |
xmlBuilder.closeTag(); |
383 |
xmlBuilder.closeTag(); |
384 |
xmlBuilder.closeTag(); |
385 |
return xmlBuilder.getXML();
|
386 |
|
387 |
}catch(Exception e) |
388 |
{ |
389 |
e.printStackTrace(); |
390 |
return null; |
391 |
} |
392 |
} |
393 |
|
394 |
/**
|
395 |
* DOCUMENT ME!
|
396 |
*
|
397 |
* @return DOCUMENT ME!
|
398 |
*
|
399 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#getXMLEntity()
|
400 |
*/
|
401 |
public XMLEntity getXMLEntity() {
|
402 |
XMLEntity xml = new XMLEntity();
|
403 |
xml.putProperty("className", this.getClass().getName()); |
404 |
xml.putProperty("useDefaultSymbolB", useDefaultSymbol);
|
405 |
if (getDefaultSymbol() == null) { |
406 |
xml.putProperty("useDefaultSymbol", 0); |
407 |
} else {
|
408 |
xml.putProperty("useDefaultSymbol", 1); |
409 |
xml.addChild(getDefaultSymbol().getXMLEntity()); |
410 |
} |
411 |
|
412 |
xml.putProperty("fieldName", fieldName);
|
413 |
xml.putProperty("index", index);
|
414 |
xml.putProperty("labelfield", labelFieldName);
|
415 |
xml.putProperty("labelfield", labelFieldName);
|
416 |
xml.putProperty("labelFieldHeight", labelFieldHeight);
|
417 |
xml.putProperty("labelFieldRotation", labelFieldRotation);
|
418 |
|
419 |
xml.putProperty("intervalType", intervalType);
|
420 |
xml.putProperty("numKeys", keys.size());
|
421 |
|
422 |
if (keys.size() > 0) { |
423 |
xml.putProperty("tipoValueKeys", keys.get(0).getClass().getName()); |
424 |
|
425 |
String[] sk = new String[keys.size()]; |
426 |
|
427 |
for (int i = 0; i < keys.size(); i++) { |
428 |
sk[i] = ((IInterval) keys.get(i)).toString(); |
429 |
} |
430 |
|
431 |
xml.putProperty("keys", getValues());
|
432 |
|
433 |
for (int i = 0; i < keys.size(); i++) { |
434 |
xml.addChild(getSymbols()[i].getXMLEntity()); |
435 |
} |
436 |
} |
437 |
|
438 |
xml.putProperty("startColor", StringUtilities.color2String(startColor));
|
439 |
xml.putProperty("endColor", StringUtilities.color2String(endColor));
|
440 |
|
441 |
///xml.putProperty("numSymbols", symbols.size());
|
442 |
///xml.putProperty("indexs", getIndexs());
|
443 |
///xml.putProperty("values", getValues());
|
444 |
return xml;
|
445 |
} |
446 |
|
447 |
/**
|
448 |
* Inserta los atributos del XMLEntity.
|
449 |
*
|
450 |
* @param xml XMLEntity.
|
451 |
*/
|
452 |
public void setXMLEntity03(XMLEntity xml) { |
453 |
fieldName = xml.getStringProperty("fieldName");
|
454 |
index = xml.getIntProperty("index");
|
455 |
labelFieldName = xml.getStringProperty("labelfield");
|
456 |
|
457 |
if (xml.contains("intervalType")) { //TODO Esta condici?n es para poder cargar la versi?n 0.3, se puede eliminar cuando ya no queramos soportar esta versi?n. |
458 |
intervalType = xml.getIntProperty("intervalType");
|
459 |
} |
460 |
|
461 |
int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol"); |
462 |
|
463 |
if (useDefaultSymbol == 1) { |
464 |
setDefaultSymbol(FSymbol.createFromXML03(xml.getChild(0)));
|
465 |
} else {
|
466 |
setDefaultSymbol(null);
|
467 |
} |
468 |
|
469 |
int numKeys = xml.getIntProperty("numKeys"); |
470 |
|
471 |
if (numKeys > 0) { |
472 |
String className = xml.getStringProperty("tipoValueKeys"); |
473 |
String[] sk = xml.getStringArrayProperty("keys"); |
474 |
IInterval auxInterval; |
475 |
|
476 |
for (int i = 0; i < numKeys; i++) { |
477 |
auxInterval = FInterval.create(sk[i]); |
478 |
symbols.put(auxInterval, |
479 |
FSymbol.createFromXML03(xml.getChild(i + useDefaultSymbol))); |
480 |
keys.add(auxInterval); |
481 |
System.out.println("auxInterval =" + auxInterval + "Symbol =" + |
482 |
FSymbol.createFromXML03(xml.getChild(i + useDefaultSymbol)) |
483 |
.getDescription()); |
484 |
} |
485 |
} |
486 |
|
487 |
startColor = StringUtilities.string2Color(xml.getStringProperty( |
488 |
"startColor"));
|
489 |
endColor = StringUtilities.string2Color(xml.getStringProperty( |
490 |
"endColor"));
|
491 |
} |
492 |
|
493 |
/**
|
494 |
* Inserta los atributos del XMLEntity.
|
495 |
*
|
496 |
* @param xml XMLEntity.
|
497 |
*/
|
498 |
public void setXMLEntity(XMLEntity xml) { |
499 |
fieldName = xml.getStringProperty("fieldName");
|
500 |
index = xml.getIntProperty("index");
|
501 |
labelFieldName = xml.getStringProperty("labelfield");
|
502 |
if (xml.contains("labelFieldHeight")) { |
503 |
setLabelHeightField(xml.getStringProperty("labelFieldHeight"));
|
504 |
} |
505 |
|
506 |
if (xml.contains("labelFieldRotation")) { |
507 |
setLabelRotationField(xml.getStringProperty("labelFieldRotation"));
|
508 |
} |
509 |
|
510 |
if (xml.contains("intervalType")) { //TODO Esta condici?n es para poder cargar la versi?n 0.3, se puede eliminar cuando ya no queramos soportar esta versi?n. |
511 |
intervalType = xml.getIntProperty("intervalType");
|
512 |
} |
513 |
if (xml.contains("useDefaultSymbolB")){ |
514 |
useDefaultSymbol = xml.getBooleanProperty("useDefaultSymbolB");
|
515 |
} |
516 |
int hasDefaultSymbol = xml.getIntProperty("useDefaultSymbol"); |
517 |
|
518 |
if (hasDefaultSymbol == 1) { |
519 |
setDefaultSymbol(FSymbol.createFromXML(xml.getChild(0)));
|
520 |
} else {
|
521 |
setDefaultSymbol(null);
|
522 |
} |
523 |
|
524 |
int numKeys = xml.getIntProperty("numKeys"); |
525 |
|
526 |
if (numKeys > 0) { |
527 |
String className = xml.getStringProperty("tipoValueKeys"); |
528 |
String[] sk = xml.getStringArrayProperty("keys"); |
529 |
IInterval auxInterval; |
530 |
|
531 |
for (int i = 0; i < numKeys; i++) { |
532 |
auxInterval = FInterval.create(sk[i]); |
533 |
symbols.put(auxInterval, |
534 |
FSymbol.createFromXML(xml.getChild(i + hasDefaultSymbol))); |
535 |
keys.add(auxInterval); |
536 |
System.out.println("auxInterval =" + auxInterval + "Symbol =" + |
537 |
FSymbol.createFromXML(xml.getChild(i + hasDefaultSymbol)) |
538 |
.getDescription()); |
539 |
} |
540 |
} |
541 |
|
542 |
startColor = StringUtilities.string2Color(xml.getStringProperty( |
543 |
"startColor"));
|
544 |
endColor = StringUtilities.string2Color(xml.getStringProperty( |
545 |
"endColor"));
|
546 |
} |
547 |
|
548 |
/**
|
549 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#cloneLegend()
|
550 |
*/
|
551 |
public Legend cloneLegend() throws XMLException { |
552 |
return (Legend) LegendFactory.createFromXML(getXMLEntity());
|
553 |
} |
554 |
|
555 |
/* (non-Javadoc)
|
556 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDataSource(com.hardcode.gdbms.engine.data.DataSource)
|
557 |
*/
|
558 |
public void setDataSource(DataSource ds) |
559 |
throws FieldNotFoundException, DriverException {
|
560 |
try {
|
561 |
dataSource = ds; |
562 |
ds.start(); |
563 |
fieldId = ds.getFieldIndexByName(fieldName); |
564 |
ds.stop(); |
565 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
566 |
throw new DriverException(e); |
567 |
} |
568 |
} |
569 |
|
570 |
/**
|
571 |
* Devuelve el intervalo a partir del valor.
|
572 |
*
|
573 |
* @param v valor.
|
574 |
*
|
575 |
* @return intervalo.
|
576 |
*/
|
577 |
public IInterval getInterval(Value v) {
|
578 |
/*if (v instanceof NullValue){
|
579 |
System.out.println("Si");
|
580 |
}*/
|
581 |
for (int i = 0; i < keys.size(); i++) { |
582 |
if (((IInterval) keys.get(i)).isInInterval(v)) {
|
583 |
return (IInterval) keys.get(i);
|
584 |
} |
585 |
} |
586 |
|
587 |
return null; |
588 |
} |
589 |
|
590 |
/**
|
591 |
* Devuelve el color final.
|
592 |
*
|
593 |
* @return color final.
|
594 |
*/
|
595 |
public Color getEndColor() { |
596 |
return endColor;
|
597 |
} |
598 |
|
599 |
/**
|
600 |
* Inserta el color final.
|
601 |
*
|
602 |
* @param endColor Color final.
|
603 |
*/
|
604 |
public void setEndColor(Color endColor) { |
605 |
this.endColor = endColor;
|
606 |
} |
607 |
|
608 |
/**
|
609 |
* Devuelve el color inicial.
|
610 |
*
|
611 |
* @return Color inicial.
|
612 |
*/
|
613 |
public Color getStartColor() { |
614 |
return startColor;
|
615 |
} |
616 |
|
617 |
/**
|
618 |
* Inserta el color inicial.
|
619 |
*
|
620 |
* @param startColor Color inicial.
|
621 |
*/
|
622 |
public void setStartColor(Color startColor) { |
623 |
this.startColor = startColor;
|
624 |
} |
625 |
|
626 |
/* (non-Javadoc)
|
627 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getShapeType()
|
628 |
*/
|
629 |
public int getShapeType() { |
630 |
return shapeType;
|
631 |
} |
632 |
|
633 |
/* (non-Javadoc)
|
634 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setShapeType(int)
|
635 |
*/
|
636 |
public void setShapeType(int shapeType) { |
637 |
if (this.shapeType != shapeType) { |
638 |
switch (shapeType) {
|
639 |
case FShape.POINT:
|
640 |
defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT);
|
641 |
|
642 |
break;
|
643 |
|
644 |
case FShape.LINE:
|
645 |
defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE);
|
646 |
|
647 |
break;
|
648 |
|
649 |
case FShape.POLYGON:
|
650 |
defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL);
|
651 |
|
652 |
break;
|
653 |
|
654 |
default:
|
655 |
defaultSymbol = new FSymbol(shapeType);
|
656 |
} |
657 |
|
658 |
this.shapeType = shapeType;
|
659 |
} |
660 |
} |
661 |
|
662 |
/* (non-Javadoc)
|
663 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getLabelHeightField()
|
664 |
*/
|
665 |
public String getLabelHeightField() { |
666 |
return labelFieldHeight;
|
667 |
} |
668 |
|
669 |
/**
|
670 |
* Inserta el alto del campo.
|
671 |
*
|
672 |
* @param str alto.
|
673 |
*/
|
674 |
public void setLabelHeightField(String str) { |
675 |
labelFieldHeight = str; |
676 |
} |
677 |
|
678 |
/* (non-Javadoc)
|
679 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getLabelRotationField()
|
680 |
*/
|
681 |
public String getLabelRotationField() { |
682 |
return labelFieldRotation;
|
683 |
} |
684 |
|
685 |
/**
|
686 |
* Inserta la rotaci?n del campo.
|
687 |
*
|
688 |
* @param str Rotaci?n.
|
689 |
*/
|
690 |
public void setLabelRotationField(String str) { |
691 |
labelFieldRotation = str; |
692 |
} |
693 |
|
694 |
/**
|
695 |
* Inserta el tipo de clasificaci?n de los intervalos.
|
696 |
*
|
697 |
* @param tipoClasificacion Tipo de clasificaci?n.
|
698 |
*/
|
699 |
public void setIntervalType(int tipoClasificacion) { |
700 |
intervalType = tipoClasificacion; |
701 |
} |
702 |
|
703 |
/**
|
704 |
* Devuelve el tipo de clasificaci?n de los intervalos.
|
705 |
*
|
706 |
* @return Tipo de clasificaci?n.
|
707 |
*/
|
708 |
public int getIntervalType() { |
709 |
return intervalType;
|
710 |
} |
711 |
|
712 |
/**
|
713 |
* Inserta si se representan el resto de valores o no.
|
714 |
*
|
715 |
* @param b True si se tienen que representar el resto de valores.
|
716 |
*/
|
717 |
public void useDefaultSymbol(boolean b) { |
718 |
useDefaultSymbol = b; |
719 |
} |
720 |
|
721 |
/**
|
722 |
* Devuelve si se utiliza o no el resto de valores para representarse.
|
723 |
*
|
724 |
* @return True si se utiliza el resto de valores.
|
725 |
*/
|
726 |
public boolean isUseDefaultSymbol() { |
727 |
return useDefaultSymbol;
|
728 |
} |
729 |
|
730 |
/**
|
731 |
* Devuelve si ha sido modificado el etiquetado de la capa.
|
732 |
*
|
733 |
* @return True si el etiquetado de la capa ha sido modificado.
|
734 |
*/
|
735 |
/* public boolean isBWithHeightText() {
|
736 |
return bWithHeightText;
|
737 |
} */
|
738 |
|
739 |
/**
|
740 |
* Introduce si el etiquetado de la capa ha sido modificado.
|
741 |
*
|
742 |
* @param withHeightText Boolean que indica si el etiquetado de la capa ha
|
743 |
* sido modificado.
|
744 |
*/
|
745 |
/* public void setBWithHeightText(boolean withHeightText) {
|
746 |
bWithHeightText = withHeightText;
|
747 |
} */
|
748 |
|
749 |
/**
|
750 |
* Elimina un s?mbolo a partir de su clave.
|
751 |
*
|
752 |
* @param obj clave.
|
753 |
*/
|
754 |
public void delSymbol(Object obj) { |
755 |
keys.remove(obj); |
756 |
symbols.remove(obj); |
757 |
} |
758 |
|
759 |
/* (non-Javadoc)
|
760 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getUsedFields()
|
761 |
*/
|
762 |
public String[] getUsedFields() { |
763 |
ArrayList usedFields = new ArrayList(); |
764 |
if (getFieldName() != null) |
765 |
usedFields.add(getFieldName()); |
766 |
if (getLabelField() != null) |
767 |
usedFields.add(getLabelField()); |
768 |
if (getLabelHeightField() != null) |
769 |
usedFields.add(getLabelHeightField()); |
770 |
if (getLabelRotationField() != null) |
771 |
usedFields.add(getLabelRotationField()); |
772 |
|
773 |
return (String[]) usedFields.toArray(new String[0]); |
774 |
|
775 |
} |
776 |
} |