svn-gvsig-desktop / tags / v1_0_RELEASE / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / VectorialIntervalLegend.java @ 9167
History | View | Annotate | Download (23.1 KB)
1 | 1100 | fjp | /* 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 | 322 | fernando | package com.iver.cit.gvsig.fmap.rendering; |
42 | |||
43 | 8765 | jjdelcerro | import java.awt.Color; |
44 | import java.util.ArrayList; |
||
45 | import java.util.Comparator; |
||
46 | import java.util.TreeMap; |
||
47 | |||
48 | 532 | vcaballero | import com.hardcode.gdbms.engine.data.DataSource; |
49 | import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
||
50 | import com.hardcode.gdbms.engine.values.Value; |
||
51 | 651 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
52 | 801 | fjp | import com.iver.cit.gvsig.fmap.core.FShape; |
53 | 2183 | fernando | import com.iver.cit.gvsig.fmap.core.IFeature; |
54 | 8765 | jjdelcerro | import com.iver.cit.gvsig.fmap.core.ISLDCompatible; |
55 | import com.iver.cit.gvsig.fmap.core.ISymbol; |
||
56 | 4111 | ldiaz | import com.iver.cit.gvsig.fmap.core.SLDTags; |
57 | 801 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
58 | 458 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
59 | 490 | fernando | import com.iver.cit.gvsig.fmap.layers.XMLException; |
60 | 532 | vcaballero | import com.iver.utiles.StringUtilities; |
61 | 435 | vcaballero | import com.iver.utiles.XMLEntity; |
62 | 322 | fernando | |
63 | |||
64 | /**
|
||
65 | 1034 | vcaballero | * Leyenda Vectorial por intervalos.
|
66 | 322 | fernando | *
|
67 | * @author Vicente Caballero Navarro
|
||
68 | */
|
||
69 | 334 | fernando | public class VectorialIntervalLegend implements IntervalLegend, VectorialLegend { |
70 | 2796 | caballero | 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 | 1034 | vcaballero | |
81 | 2796 | caballero | if (o2 instanceof NullIntervalValue) { |
82 | return 1; |
||
83 | } |
||
84 | 1034 | vcaballero | |
85 | 2796 | caballero | if (o1 instanceof NullIntervalValue) { |
86 | return -1; |
||
87 | } |
||
88 | 435 | vcaballero | |
89 | 2796 | caballero | FInterval i2 = (FInterval) o2; |
90 | FInterval i1 = (FInterval) o1; |
||
91 | 1034 | vcaballero | |
92 | 2796 | caballero | if (i1.getMin() > i2.getMin()) {
|
93 | return 1; |
||
94 | } |
||
95 | 435 | vcaballero | |
96 | 2796 | caballero | if (i1.getMin() < i2.getMin()) {
|
97 | return -1; |
||
98 | } |
||
99 | } |
||
100 | 435 | vcaballero | |
101 | 2796 | caballero | 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 | 8765 | jjdelcerro | private ISymbol defaultSymbol;
|
112 | 2796 | caballero | 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 | 3035 | fjp | // private boolean bWithHeightText;
|
119 | 322 | fernando | |
120 | 2796 | caballero | /**
|
121 | * Crea un nuevo VectorialIntervalLegend.
|
||
122 | */
|
||
123 | public VectorialIntervalLegend() {
|
||
124 | //defaultSymbol = LegendFactory.DEFAULT_POLYGON_SYMBOL;
|
||
125 | } |
||
126 | 1034 | vcaballero | |
127 | 2796 | caballero | /**
|
128 | * Crea un nuevo VectorialIntervalLegend.
|
||
129 | *
|
||
130 | * @param type tipo de shape.
|
||
131 | */
|
||
132 | public VectorialIntervalLegend(int type) { |
||
133 | setShapeType(type); |
||
134 | } |
||
135 | 435 | vcaballero | |
136 | 2796 | caballero | /**
|
137 | * @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#addSymbol(java.lang.Object,
|
||
138 | 8765 | jjdelcerro | * ISymbol)
|
139 | 2796 | caballero | */
|
140 | 8765 | jjdelcerro | public void addSymbol(Object key, ISymbol symbol) { |
141 | 2796 | caballero | //TODO guardar los intervalos.
|
142 | Object resul;
|
||
143 | resul = symbols.put(key, symbol); |
||
144 | 435 | vcaballero | |
145 | 2796 | caballero | /*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 | 322 | fernando | |
154 | 2796 | caballero | //}
|
155 | } |
||
156 | 2183 | fernando | |
157 | 2796 | caballero | /*
|
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 | 1034 | vcaballero | |
167 | 2796 | caballero | /**
|
168 | * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getSymbol(int)
|
||
169 | */
|
||
170 | 8765 | jjdelcerro | public ISymbol getSymbol(int recordIndex) throws DriverException { |
171 | 2796 | caballero | try {
|
172 | Value val = dataSource.getFieldValue(recordIndex, fieldId); |
||
173 | IInterval interval = getInterval(val); |
||
174 | FSymbol theSymbol = getSymbolByInterval(interval); |
||
175 | 322 | fernando | |
176 | 2796 | caballero | if (theSymbol != null) { |
177 | return theSymbol;
|
||
178 | } else if (useDefaultSymbol) { |
||
179 | return getDefaultSymbol();
|
||
180 | } |
||
181 | 322 | fernando | |
182 | 2796 | caballero | return null; |
183 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
184 | throw new DriverException(e); |
||
185 | } |
||
186 | } |
||
187 | 322 | fernando | |
188 | 2796 | caballero | /**
|
189 | * Devuelve un s?mbolo a partir de una IFeature.
|
||
190 | 3347 | fjp | * 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 | 2796 | caballero | *
|
194 | * @param feat IFeature.
|
||
195 | *
|
||
196 | * @return S?mbolo.
|
||
197 | */
|
||
198 | 8765 | jjdelcerro | public ISymbol getSymbolByFeature(IFeature feat) {
|
199 | 3347 | fjp | Value val = feat.getAttribute(fieldId); |
200 | 2796 | caballero | IInterval interval = getInterval(val); |
201 | FSymbol theSymbol = getSymbolByInterval(interval); |
||
202 | 322 | fernando | |
203 | 2796 | caballero | if (theSymbol != null) { |
204 | return theSymbol;
|
||
205 | } else {
|
||
206 | return getDefaultSymbol();
|
||
207 | } |
||
208 | } |
||
209 | 322 | fernando | |
210 | 2796 | caballero | /**
|
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 | 322 | fernando | |
222 | 2796 | caballero | if (symbols.containsKey(key)) {
|
223 | return (FSymbol) symbols.get(key);
|
||
224 | } |
||
225 | 435 | vcaballero | |
226 | 2796 | caballero | return null; |
227 | } |
||
228 | 435 | vcaballero | |
229 | 2796 | caballero | /**
|
230 | * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getDescriptions()
|
||
231 | */
|
||
232 | public String[] getDescriptions() { |
||
233 | String[] descriptions = new String[symbols.size()]; |
||
234 | 8765 | jjdelcerro | ISymbol[] auxSym = getSymbols();
|
235 | 435 | vcaballero | |
236 | 2796 | caballero | for (int i = 0; i < descriptions.length; i++) |
237 | descriptions[i] = auxSym[i].getDescription(); |
||
238 | 435 | vcaballero | |
239 | 2796 | caballero | return descriptions;
|
240 | } |
||
241 | 435 | vcaballero | |
242 | 2796 | caballero | /**
|
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 | 532 | vcaballero | |
249 | 2796 | caballero | /**
|
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 | 532 | vcaballero | |
260 | 2796 | caballero | /**
|
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 | 532 | vcaballero | |
272 | 2796 | caballero | /**
|
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 | 532 | vcaballero | |
281 | 2796 | caballero | /**
|
282 | * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#getSymbols()
|
||
283 | */
|
||
284 | 8765 | jjdelcerro | public ISymbol[] getSymbols() { |
285 | 2796 | caballero | return (FSymbol[]) symbols.values().toArray(new FSymbol[0]); |
286 | } |
||
287 | 532 | vcaballero | |
288 | 2796 | caballero | /**
|
289 | * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#getFieldName()
|
||
290 | */
|
||
291 | public String getFieldName() { |
||
292 | return fieldName;
|
||
293 | } |
||
294 | 532 | vcaballero | |
295 | 2796 | caballero | /**
|
296 | 8765 | jjdelcerro | * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDefaultSymbol(ISymbol)
|
297 | 2796 | caballero | */
|
298 | 8765 | jjdelcerro | public void setDefaultSymbol(ISymbol s) { |
299 | 2796 | caballero | defaultSymbol = s; |
300 | } |
||
301 | 1034 | vcaballero | |
302 | 2796 | caballero | /**
|
303 | * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#setFieldName(String)
|
||
304 | */
|
||
305 | public void setFieldName(String str) { |
||
306 | fieldName = str; |
||
307 | } |
||
308 | 1034 | vcaballero | |
309 | 2796 | caballero | /**
|
310 | * @see com.iver.cit.gvsig.fmap.rendering.Legend#setLabelField(int)
|
||
311 | */
|
||
312 | public void setLabelField(String fieldName) { |
||
313 | labelFieldName = fieldName; |
||
314 | } |
||
315 | 1034 | vcaballero | |
316 | 2796 | caballero | /**
|
317 | * @see com.iver.cit.gvsig.fmap.rendering.Legend#getLabelField()
|
||
318 | */
|
||
319 | public String getLabelField() { |
||
320 | return labelFieldName;
|
||
321 | } |
||
322 | 1034 | vcaballero | |
323 | 2796 | caballero | /**
|
324 | * @see com.iver.cit.gvsig.fmap.rendering.Legend#getDefaultSymbol()
|
||
325 | */
|
||
326 | 8765 | jjdelcerro | public ISymbol getDefaultSymbol() {
|
327 | 2796 | caballero | return defaultSymbol;
|
328 | } |
||
329 | 3632 | ldiaz | |
330 | 8765 | jjdelcerro | /**
|
331 | * creates the SLD String that defines this legend type.
|
||
332 | */
|
||
333 | 4567 | ldiaz | public String getSLDString(String layerName) { |
334 | 4111 | ldiaz | |
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 | 4567 | ldiaz | xmlBuilder.writeTag(SLDTags.NAME,layerName); |
342 | 4111 | ldiaz | xmlBuilder.openTag(SLDTags.USERSTYLE); |
343 | xmlBuilder.openTag(SLDTags.FEATURETYPESTYLE); |
||
344 | xmlBuilder.writeTag(SLDTags.FEATURETYPENAME,fieldName); |
||
345 | |||
346 | 8765 | jjdelcerro | ISymbol[] symbols = this.getSymbols(); |
347 | 4111 | ldiaz | Object[] values = this.getValues(); |
348 | |||
349 | FInterval interval; |
||
350 | for(int i = 0; i < symbols.length; i++ ) |
||
351 | { |
||
352 | 8765 | jjdelcerro | interval = (FInterval)values[i]; |
353 | 4111 | ldiaz | //interval = (FInterval)getInterval(ValueFactory.createValue(valueDbl.doubleValue()));
|
354 | xmlBuilder.openTag(SLDTags.RULE); |
||
355 | 8765 | jjdelcerro | xmlBuilder.writeTag(SLDTags.NAME, ""+interval.getMin() +" - " +interval.getMax()); |
356 | 4111 | ldiaz | 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 | 8765 | jjdelcerro | 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 | 4111 | ldiaz | 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 | 3632 | ldiaz | } |
390 | |||
391 | /**
|
||
392 | * DOCUMENT ME!
|
||
393 | *
|
||
394 | * @return DOCUMENT ME!
|
||
395 | *
|
||
396 | 2796 | caballero | * @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 | 1034 | vcaballero | |
402 | 2796 | caballero | if (getDefaultSymbol() == null) { |
403 | xml.putProperty("useDefaultSymbol", 0); |
||
404 | } else {
|
||
405 | xml.putProperty("useDefaultSymbol", 1); |
||
406 | xml.addChild(getDefaultSymbol().getXMLEntity()); |
||
407 | } |
||
408 | 1034 | vcaballero | |
409 | 2796 | caballero | xml.putProperty("fieldName", fieldName);
|
410 | xml.putProperty("index", index);
|
||
411 | xml.putProperty("labelfield", labelFieldName);
|
||
412 | 3035 | fjp | xml.putProperty("labelfield", labelFieldName);
|
413 | xml.putProperty("labelFieldHeight", labelFieldHeight);
|
||
414 | xml.putProperty("labelFieldRotation", labelFieldRotation);
|
||
415 | |||
416 | 2796 | caballero | xml.putProperty("intervalType", intervalType);
|
417 | xml.putProperty("numKeys", keys.size());
|
||
418 | 1034 | vcaballero | |
419 | 2796 | caballero | if (keys.size() > 0) { |
420 | xml.putProperty("tipoValueKeys", keys.get(0).getClass().getName()); |
||
421 | 532 | vcaballero | |
422 | 2796 | caballero | String[] sk = new String[keys.size()]; |
423 | 2183 | fernando | |
424 | 2796 | caballero | for (int i = 0; i < keys.size(); i++) { |
425 | sk[i] = ((IInterval) keys.get(i)).toString(); |
||
426 | } |
||
427 | 2183 | fernando | |
428 | 2796 | caballero | xml.putProperty("keys", getValues());
|
429 | 2183 | fernando | |
430 | 2796 | caballero | for (int i = 0; i < keys.size(); i++) { |
431 | xml.addChild(getSymbols()[i].getXMLEntity()); |
||
432 | } |
||
433 | } |
||
434 | 2183 | fernando | |
435 | 2796 | caballero | xml.putProperty("startColor", StringUtilities.color2String(startColor));
|
436 | xml.putProperty("endColor", StringUtilities.color2String(endColor));
|
||
437 | 2183 | fernando | |
438 | 2796 | caballero | ///xml.putProperty("numSymbols", symbols.size());
|
439 | ///xml.putProperty("indexs", getIndexs());
|
||
440 | ///xml.putProperty("values", getValues());
|
||
441 | return xml;
|
||
442 | } |
||
443 | 2183 | fernando | |
444 | 2796 | caballero | /**
|
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 | 1034 | vcaballero | |
454 | 2796 | caballero | 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 | 1034 | vcaballero | |
458 | 2796 | caballero | int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol"); |
459 | 1034 | vcaballero | |
460 | 2796 | caballero | if (useDefaultSymbol == 1) { |
461 | setDefaultSymbol(FSymbol.createFromXML03(xml.getChild(0)));
|
||
462 | } else {
|
||
463 | setDefaultSymbol(null);
|
||
464 | } |
||
465 | 1034 | vcaballero | |
466 | 2796 | caballero | int numKeys = xml.getIntProperty("numKeys"); |
467 | 1034 | vcaballero | |
468 | 2796 | caballero | if (numKeys > 0) { |
469 | String className = xml.getStringProperty("tipoValueKeys"); |
||
470 | String[] sk = xml.getStringArrayProperty("keys"); |
||
471 | IInterval auxInterval; |
||
472 | 532 | vcaballero | |
473 | 2796 | caballero | 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 | 532 | vcaballero | |
484 | 2796 | caballero | startColor = StringUtilities.string2Color(xml.getStringProperty( |
485 | "startColor"));
|
||
486 | endColor = StringUtilities.string2Color(xml.getStringProperty( |
||
487 | "endColor"));
|
||
488 | } |
||
489 | 1034 | vcaballero | |
490 | 2796 | caballero | /**
|
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 | 3035 | fjp | if (xml.contains("labelFieldHeight")) { |
500 | setLabelHeightField(xml.getStringProperty("labelFieldHeight"));
|
||
501 | } |
||
502 | 1034 | vcaballero | |
503 | 3035 | fjp | if (xml.contains("labelFieldRotation")) { |
504 | setLabelRotationField(xml.getStringProperty("labelFieldRotation"));
|
||
505 | } |
||
506 | |||
507 | 2796 | caballero | 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 | 1034 | vcaballero | |
511 | 2796 | caballero | int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol"); |
512 | 1034 | vcaballero | |
513 | 2796 | caballero | 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 | 1034 | vcaballero | |
521 | 2796 | caballero | int numKeys = xml.getIntProperty("numKeys"); |
522 | 1034 | vcaballero | |
523 | 2796 | caballero | if (numKeys > 0) { |
524 | String className = xml.getStringProperty("tipoValueKeys"); |
||
525 | String[] sk = xml.getStringArrayProperty("keys"); |
||
526 | IInterval auxInterval; |
||
527 | 1034 | vcaballero | |
528 | 2796 | caballero | 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 | 1034 | vcaballero | |
539 | 2796 | caballero | startColor = StringUtilities.string2Color(xml.getStringProperty( |
540 | "startColor"));
|
||
541 | endColor = StringUtilities.string2Color(xml.getStringProperty( |
||
542 | "endColor"));
|
||
543 | } |
||
544 | 1034 | vcaballero | |
545 | 2796 | caballero | /**
|
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 | 1034 | vcaballero | |
552 | 2796 | caballero | /* (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 | 1034 | vcaballero | |
567 | 2796 | caballero | /**
|
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 | 1034 | vcaballero | |
584 | 2796 | caballero | return null; |
585 | } |
||
586 | 1034 | vcaballero | |
587 | 2796 | caballero | /**
|
588 | * Devuelve el color final.
|
||
589 | *
|
||
590 | * @return color final.
|
||
591 | */
|
||
592 | public Color getEndColor() { |
||
593 | return endColor;
|
||
594 | } |
||
595 | 801 | fjp | |
596 | 2796 | caballero | /**
|
597 | * Inserta el color final.
|
||
598 | *
|
||
599 | * @param endColor Color final.
|
||
600 | */
|
||
601 | public void setEndColor(Color endColor) { |
||
602 | this.endColor = endColor;
|
||
603 | } |
||
604 | 1034 | vcaballero | |
605 | 2796 | caballero | /**
|
606 | * Devuelve el color inicial.
|
||
607 | *
|
||
608 | * @return Color inicial.
|
||
609 | */
|
||
610 | public Color getStartColor() { |
||
611 | return startColor;
|
||
612 | } |
||
613 | 1034 | vcaballero | |
614 | 2796 | caballero | /**
|
615 | * Inserta el color inicial.
|
||
616 | *
|
||
617 | * @param startColor Color inicial.
|
||
618 | */
|
||
619 | public void setStartColor(Color startColor) { |
||
620 | this.startColor = startColor;
|
||
621 | } |
||
622 | 801 | fjp | |
623 | 2796 | caballero | /* (non-Javadoc)
|
624 | * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getShapeType()
|
||
625 | */
|
||
626 | public int getShapeType() { |
||
627 | return shapeType;
|
||
628 | } |
||
629 | 2183 | fernando | |
630 | 2796 | caballero | /* (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 | 2200 | vcaballero | |
639 | 2796 | caballero | break;
|
640 | 2200 | vcaballero | |
641 | 2796 | caballero | case FShape.LINE:
|
642 | defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE);
|
||
643 | 2413 | caballero | |
644 | 2796 | caballero | break;
|
645 | 2600 | caballero | |
646 | 2796 | caballero | case FShape.POLYGON:
|
647 | defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL);
|
||
648 | 2600 | caballero | |
649 | 2796 | caballero | 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 | 3035 | fjp | /* public boolean isBWithHeightText() {
|
733 | 2796 | caballero | return bWithHeightText;
|
734 | 3035 | fjp | } */
|
735 | 2796 | caballero | |
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 | 3035 | fjp | /* public void setBWithHeightText(boolean withHeightText) {
|
743 | 2796 | caballero | bWithHeightText = withHeightText;
|
744 | 3035 | fjp | } */
|
745 | 2796 | caballero | |
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 | 3268 | fjp | |
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 | 322 | fernando | } |