root / tags / v1_0_1_RELEASE / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / VectorialIntervalLegend.java @ 9531
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.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 |
return defaultSymbol;
|
328 |
} |
329 |
|
330 |
/**
|
331 |
* creates the SLD String that defines this legend type.
|
332 |
*/
|
333 |
public String getSLDString(String layerName) { |
334 |
|
335 |
try{
|
336 |
|
337 |
XmlBuilder xmlBuilder = new XmlBuilder();
|
338 |
xmlBuilder.writeHeader(); |
339 |
xmlBuilder.openTag(SLDTags.SLD_ROOT, SLDTags.VERSION_ATTR, SLDTags.VERSION_1_0_0); |
340 |
xmlBuilder.openTag(SLDTags.NAMEDLAYER); |
341 |
xmlBuilder.writeTag(SLDTags.NAME,layerName); |
342 |
xmlBuilder.openTag(SLDTags.USERSTYLE); |
343 |
xmlBuilder.openTag(SLDTags.FEATURETYPESTYLE); |
344 |
xmlBuilder.writeTag(SLDTags.FEATURETYPENAME,fieldName); |
345 |
|
346 |
ISymbol[] symbols = this.getSymbols(); |
347 |
Object[] values = this.getValues(); |
348 |
|
349 |
FInterval interval; |
350 |
for(int i = 0; i < symbols.length; i++ ) |
351 |
{ |
352 |
interval = (FInterval)values[i]; |
353 |
//interval = (FInterval)getInterval(ValueFactory.createValue(valueDbl.doubleValue()));
|
354 |
xmlBuilder.openTag(SLDTags.RULE); |
355 |
xmlBuilder.writeTag(SLDTags.NAME, ""+interval.getMin() +" - " +interval.getMax()); |
356 |
xmlBuilder.openTag(SLDTags.FILTER); |
357 |
xmlBuilder.openTag(SLDTags.AND); |
358 |
xmlBuilder.openTag(SLDTags.PROPERTYISGREATEROREQUALTHAN); |
359 |
xmlBuilder.writeTag(SLDTags.PROPERTYNAME,fieldName); |
360 |
xmlBuilder.writeTag(SLDTags.LITERAL, ""+interval.getMin());
|
361 |
xmlBuilder.closeTag(); |
362 |
xmlBuilder.openTag(SLDTags.PROPERTYISLESSOREQUALTHAN); |
363 |
xmlBuilder.writeTag(SLDTags.PROPERTYNAME,fieldName); |
364 |
xmlBuilder.writeTag(SLDTags.LITERAL, ""+interval.getMax());
|
365 |
xmlBuilder.closeTag(); |
366 |
xmlBuilder.closeTag(); |
367 |
if (symbols[i] instanceof ISLDCompatible) |
368 |
{ |
369 |
ISLDCompatible symSLD = (ISLDCompatible) symbols[i]; |
370 |
xmlBuilder.writeRaw(symSLD.toSLD()); |
371 |
} |
372 |
else
|
373 |
throw new RuntimeException("Cannot convert Symbol " + i + " " + symbols[i].getDescription() + " to SLD"); |
374 |
xmlBuilder.closeTag(); |
375 |
xmlBuilder.closeTag(); |
376 |
} |
377 |
|
378 |
xmlBuilder.closeTag(); |
379 |
xmlBuilder.closeTag(); |
380 |
xmlBuilder.closeTag(); |
381 |
xmlBuilder.closeTag(); |
382 |
return xmlBuilder.getXML();
|
383 |
|
384 |
}catch(Exception e) |
385 |
{ |
386 |
e.printStackTrace(); |
387 |
return null; |
388 |
} |
389 |
} |
390 |
|
391 |
/**
|
392 |
* DOCUMENT ME!
|
393 |
*
|
394 |
* @return DOCUMENT ME!
|
395 |
*
|
396 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#getXMLEntity()
|
397 |
*/
|
398 |
public XMLEntity getXMLEntity() {
|
399 |
XMLEntity xml = new XMLEntity();
|
400 |
xml.putProperty("className", this.getClass().getName()); |
401 |
|
402 |
if (getDefaultSymbol() == null) { |
403 |
xml.putProperty("useDefaultSymbol", 0); |
404 |
} else {
|
405 |
xml.putProperty("useDefaultSymbol", 1); |
406 |
xml.addChild(getDefaultSymbol().getXMLEntity()); |
407 |
} |
408 |
|
409 |
xml.putProperty("fieldName", fieldName);
|
410 |
xml.putProperty("index", index);
|
411 |
xml.putProperty("labelfield", labelFieldName);
|
412 |
xml.putProperty("labelfield", labelFieldName);
|
413 |
xml.putProperty("labelFieldHeight", labelFieldHeight);
|
414 |
xml.putProperty("labelFieldRotation", labelFieldRotation);
|
415 |
|
416 |
xml.putProperty("intervalType", intervalType);
|
417 |
xml.putProperty("numKeys", keys.size());
|
418 |
|
419 |
if (keys.size() > 0) { |
420 |
xml.putProperty("tipoValueKeys", keys.get(0).getClass().getName()); |
421 |
|
422 |
String[] sk = new String[keys.size()]; |
423 |
|
424 |
for (int i = 0; i < keys.size(); i++) { |
425 |
sk[i] = ((IInterval) keys.get(i)).toString(); |
426 |
} |
427 |
|
428 |
xml.putProperty("keys", getValues());
|
429 |
|
430 |
for (int i = 0; i < keys.size(); i++) { |
431 |
xml.addChild(getSymbols()[i].getXMLEntity()); |
432 |
} |
433 |
} |
434 |
|
435 |
xml.putProperty("startColor", StringUtilities.color2String(startColor));
|
436 |
xml.putProperty("endColor", StringUtilities.color2String(endColor));
|
437 |
|
438 |
///xml.putProperty("numSymbols", symbols.size());
|
439 |
///xml.putProperty("indexs", getIndexs());
|
440 |
///xml.putProperty("values", getValues());
|
441 |
return xml;
|
442 |
} |
443 |
|
444 |
/**
|
445 |
* Inserta los atributos del XMLEntity.
|
446 |
*
|
447 |
* @param xml XMLEntity.
|
448 |
*/
|
449 |
public void setXMLEntity03(XMLEntity xml) { |
450 |
fieldName = xml.getStringProperty("fieldName");
|
451 |
index = xml.getIntProperty("index");
|
452 |
labelFieldName = xml.getStringProperty("labelfield");
|
453 |
|
454 |
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. |
455 |
intervalType = xml.getIntProperty("intervalType");
|
456 |
} |
457 |
|
458 |
int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol"); |
459 |
|
460 |
if (useDefaultSymbol == 1) { |
461 |
setDefaultSymbol(FSymbol.createFromXML03(xml.getChild(0)));
|
462 |
} else {
|
463 |
setDefaultSymbol(null);
|
464 |
} |
465 |
|
466 |
int numKeys = xml.getIntProperty("numKeys"); |
467 |
|
468 |
if (numKeys > 0) { |
469 |
String className = xml.getStringProperty("tipoValueKeys"); |
470 |
String[] sk = xml.getStringArrayProperty("keys"); |
471 |
IInterval auxInterval; |
472 |
|
473 |
for (int i = 0; i < numKeys; i++) { |
474 |
auxInterval = FInterval.create(sk[i]); |
475 |
symbols.put(auxInterval, |
476 |
FSymbol.createFromXML03(xml.getChild(i + useDefaultSymbol))); |
477 |
keys.add(auxInterval); |
478 |
System.out.println("auxInterval =" + auxInterval + "Symbol =" + |
479 |
FSymbol.createFromXML03(xml.getChild(i + useDefaultSymbol)) |
480 |
.getDescription()); |
481 |
} |
482 |
} |
483 |
|
484 |
startColor = StringUtilities.string2Color(xml.getStringProperty( |
485 |
"startColor"));
|
486 |
endColor = StringUtilities.string2Color(xml.getStringProperty( |
487 |
"endColor"));
|
488 |
} |
489 |
|
490 |
/**
|
491 |
* Inserta los atributos del XMLEntity.
|
492 |
*
|
493 |
* @param xml XMLEntity.
|
494 |
*/
|
495 |
public void setXMLEntity(XMLEntity xml) { |
496 |
fieldName = xml.getStringProperty("fieldName");
|
497 |
index = xml.getIntProperty("index");
|
498 |
labelFieldName = xml.getStringProperty("labelfield");
|
499 |
if (xml.contains("labelFieldHeight")) { |
500 |
setLabelHeightField(xml.getStringProperty("labelFieldHeight"));
|
501 |
} |
502 |
|
503 |
if (xml.contains("labelFieldRotation")) { |
504 |
setLabelRotationField(xml.getStringProperty("labelFieldRotation"));
|
505 |
} |
506 |
|
507 |
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. |
508 |
intervalType = xml.getIntProperty("intervalType");
|
509 |
} |
510 |
|
511 |
int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol"); |
512 |
|
513 |
if (useDefaultSymbol == 1) { |
514 |
setDefaultSymbol(FSymbol.createFromXML(xml.getChild(0)));
|
515 |
this.useDefaultSymbol=true; |
516 |
} else {
|
517 |
setDefaultSymbol(null);
|
518 |
this.useDefaultSymbol=false; |
519 |
} |
520 |
|
521 |
int numKeys = xml.getIntProperty("numKeys"); |
522 |
|
523 |
if (numKeys > 0) { |
524 |
String className = xml.getStringProperty("tipoValueKeys"); |
525 |
String[] sk = xml.getStringArrayProperty("keys"); |
526 |
IInterval auxInterval; |
527 |
|
528 |
for (int i = 0; i < numKeys; i++) { |
529 |
auxInterval = FInterval.create(sk[i]); |
530 |
symbols.put(auxInterval, |
531 |
FSymbol.createFromXML(xml.getChild(i + useDefaultSymbol))); |
532 |
keys.add(auxInterval); |
533 |
System.out.println("auxInterval =" + auxInterval + "Symbol =" + |
534 |
FSymbol.createFromXML(xml.getChild(i + useDefaultSymbol)) |
535 |
.getDescription()); |
536 |
} |
537 |
} |
538 |
|
539 |
startColor = StringUtilities.string2Color(xml.getStringProperty( |
540 |
"startColor"));
|
541 |
endColor = StringUtilities.string2Color(xml.getStringProperty( |
542 |
"endColor"));
|
543 |
} |
544 |
|
545 |
/**
|
546 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#cloneLegend()
|
547 |
*/
|
548 |
public Legend cloneLegend() throws XMLException { |
549 |
return (Legend) LegendFactory.createFromXML(getXMLEntity());
|
550 |
} |
551 |
|
552 |
/* (non-Javadoc)
|
553 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDataSource(com.hardcode.gdbms.engine.data.DataSource)
|
554 |
*/
|
555 |
public void setDataSource(DataSource ds) |
556 |
throws FieldNotFoundException, DriverException {
|
557 |
try {
|
558 |
dataSource = ds; |
559 |
ds.start(); |
560 |
fieldId = ds.getFieldIndexByName(fieldName); |
561 |
ds.stop(); |
562 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
563 |
throw new DriverException(e); |
564 |
} |
565 |
} |
566 |
|
567 |
/**
|
568 |
* Devuelve el intervalo a partir del valor.
|
569 |
*
|
570 |
* @param v valor.
|
571 |
*
|
572 |
* @return intervalo.
|
573 |
*/
|
574 |
public IInterval getInterval(Value v) {
|
575 |
/*if (v instanceof NullValue){
|
576 |
System.out.println("Si");
|
577 |
}*/
|
578 |
for (int i = 0; i < keys.size(); i++) { |
579 |
if (((IInterval) keys.get(i)).isInInterval(v)) {
|
580 |
return (IInterval) keys.get(i);
|
581 |
} |
582 |
} |
583 |
|
584 |
return null; |
585 |
} |
586 |
|
587 |
/**
|
588 |
* Devuelve el color final.
|
589 |
*
|
590 |
* @return color final.
|
591 |
*/
|
592 |
public Color getEndColor() { |
593 |
return endColor;
|
594 |
} |
595 |
|
596 |
/**
|
597 |
* Inserta el color final.
|
598 |
*
|
599 |
* @param endColor Color final.
|
600 |
*/
|
601 |
public void setEndColor(Color endColor) { |
602 |
this.endColor = endColor;
|
603 |
} |
604 |
|
605 |
/**
|
606 |
* Devuelve el color inicial.
|
607 |
*
|
608 |
* @return Color inicial.
|
609 |
*/
|
610 |
public Color getStartColor() { |
611 |
return startColor;
|
612 |
} |
613 |
|
614 |
/**
|
615 |
* Inserta el color inicial.
|
616 |
*
|
617 |
* @param startColor Color inicial.
|
618 |
*/
|
619 |
public void setStartColor(Color startColor) { |
620 |
this.startColor = startColor;
|
621 |
} |
622 |
|
623 |
/* (non-Javadoc)
|
624 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getShapeType()
|
625 |
*/
|
626 |
public int getShapeType() { |
627 |
return shapeType;
|
628 |
} |
629 |
|
630 |
/* (non-Javadoc)
|
631 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setShapeType(int)
|
632 |
*/
|
633 |
public void setShapeType(int shapeType) { |
634 |
if (this.shapeType != shapeType) { |
635 |
switch (shapeType) {
|
636 |
case FShape.POINT:
|
637 |
defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT);
|
638 |
|
639 |
break;
|
640 |
|
641 |
case FShape.LINE:
|
642 |
defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE);
|
643 |
|
644 |
break;
|
645 |
|
646 |
case FShape.POLYGON:
|
647 |
defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL);
|
648 |
|
649 |
break;
|
650 |
|
651 |
default:
|
652 |
defaultSymbol = new FSymbol(shapeType);
|
653 |
} |
654 |
|
655 |
this.shapeType = shapeType;
|
656 |
} |
657 |
} |
658 |
|
659 |
/* (non-Javadoc)
|
660 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getLabelHeightField()
|
661 |
*/
|
662 |
public String getLabelHeightField() { |
663 |
return labelFieldHeight;
|
664 |
} |
665 |
|
666 |
/**
|
667 |
* Inserta el alto del campo.
|
668 |
*
|
669 |
* @param str alto.
|
670 |
*/
|
671 |
public void setLabelHeightField(String str) { |
672 |
labelFieldHeight = str; |
673 |
} |
674 |
|
675 |
/* (non-Javadoc)
|
676 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getLabelRotationField()
|
677 |
*/
|
678 |
public String getLabelRotationField() { |
679 |
return labelFieldRotation;
|
680 |
} |
681 |
|
682 |
/**
|
683 |
* Inserta la rotaci?n del campo.
|
684 |
*
|
685 |
* @param str Rotaci?n.
|
686 |
*/
|
687 |
public void setLabelRotationField(String str) { |
688 |
labelFieldRotation = str; |
689 |
} |
690 |
|
691 |
/**
|
692 |
* Inserta el tipo de clasificaci?n de los intervalos.
|
693 |
*
|
694 |
* @param tipoClasificacion Tipo de clasificaci?n.
|
695 |
*/
|
696 |
public void setIntervalType(int tipoClasificacion) { |
697 |
intervalType = tipoClasificacion; |
698 |
} |
699 |
|
700 |
/**
|
701 |
* Devuelve el tipo de clasificaci?n de los intervalos.
|
702 |
*
|
703 |
* @return Tipo de clasificaci?n.
|
704 |
*/
|
705 |
public int getIntervalType() { |
706 |
return intervalType;
|
707 |
} |
708 |
|
709 |
/**
|
710 |
* Inserta si se representan el resto de valores o no.
|
711 |
*
|
712 |
* @param b True si se tienen que representar el resto de valores.
|
713 |
*/
|
714 |
public void useDefaultSymbol(boolean b) { |
715 |
useDefaultSymbol = b; |
716 |
} |
717 |
|
718 |
/**
|
719 |
* Devuelve si se utiliza o no el resto de valores para representarse.
|
720 |
*
|
721 |
* @return True si se utiliza el resto de valores.
|
722 |
*/
|
723 |
public boolean isUseDefaultSymbol() { |
724 |
return useDefaultSymbol;
|
725 |
} |
726 |
|
727 |
/**
|
728 |
* Devuelve si ha sido modificado el etiquetado de la capa.
|
729 |
*
|
730 |
* @return True si el etiquetado de la capa ha sido modificado.
|
731 |
*/
|
732 |
/* public boolean isBWithHeightText() {
|
733 |
return bWithHeightText;
|
734 |
} */
|
735 |
|
736 |
/**
|
737 |
* Introduce si el etiquetado de la capa ha sido modificado.
|
738 |
*
|
739 |
* @param withHeightText Boolean que indica si el etiquetado de la capa ha
|
740 |
* sido modificado.
|
741 |
*/
|
742 |
/* public void setBWithHeightText(boolean withHeightText) {
|
743 |
bWithHeightText = withHeightText;
|
744 |
} */
|
745 |
|
746 |
/**
|
747 |
* Elimina un s?mbolo a partir de su clave.
|
748 |
*
|
749 |
* @param obj clave.
|
750 |
*/
|
751 |
public void delSymbol(Object obj) { |
752 |
keys.remove(obj); |
753 |
symbols.remove(obj); |
754 |
} |
755 |
|
756 |
/* (non-Javadoc)
|
757 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getUsedFields()
|
758 |
*/
|
759 |
public String[] getUsedFields() { |
760 |
ArrayList usedFields = new ArrayList(); |
761 |
if (getFieldName() != null) |
762 |
usedFields.add(getFieldName()); |
763 |
if (getLabelField() != null) |
764 |
usedFields.add(getLabelField()); |
765 |
if (getLabelHeightField() != null) |
766 |
usedFields.add(getLabelHeightField()); |
767 |
if (getLabelRotationField() != null) |
768 |
usedFields.add(getLabelRotationField()); |
769 |
|
770 |
return (String[]) usedFields.toArray(new String[0]); |
771 |
|
772 |
} |
773 |
} |