svn-gvsig-desktop / tags / v1_1_Build_1009 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / VectorialIntervalLegend.java @ 12649
History | View | Annotate | Download (23.3 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 | 9885 | caballero | NullIntervalValue niv=new NullIntervalValue();
|
328 | if (symbols.containsKey(niv))
|
||
329 | return (ISymbol)symbols.get(niv);
|
||
330 | 2796 | caballero | return defaultSymbol;
|
331 | } |
||
332 | 10536 | caballero | |
333 | 8765 | jjdelcerro | /**
|
334 | * creates the SLD String that defines this legend type.
|
||
335 | */
|
||
336 | 4567 | ldiaz | public String getSLDString(String layerName) { |
337 | 10536 | caballero | |
338 | 4111 | ldiaz | try{
|
339 | 10536 | caballero | |
340 | 4111 | ldiaz | 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 | 4567 | ldiaz | xmlBuilder.writeTag(SLDTags.NAME,layerName); |
345 | 4111 | ldiaz | xmlBuilder.openTag(SLDTags.USERSTYLE); |
346 | xmlBuilder.openTag(SLDTags.FEATURETYPESTYLE); |
||
347 | xmlBuilder.writeTag(SLDTags.FEATURETYPENAME,fieldName); |
||
348 | 10536 | caballero | |
349 | ISymbol[] symbols = this.getSymbols(); |
||
350 | Object[] values = this.getValues(); |
||
351 | |||
352 | 4111 | ldiaz | FInterval interval; |
353 | for(int i = 0; i < symbols.length; i++ ) |
||
354 | { |
||
355 | 10536 | caballero | interval = (FInterval)values[i]; |
356 | 4111 | ldiaz | //interval = (FInterval)getInterval(ValueFactory.createValue(valueDbl.doubleValue()));
|
357 | xmlBuilder.openTag(SLDTags.RULE); |
||
358 | 8765 | jjdelcerro | xmlBuilder.writeTag(SLDTags.NAME, ""+interval.getMin() +" - " +interval.getMax()); |
359 | 4111 | ldiaz | 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 | 10536 | caballero | xmlBuilder.closeTag(); |
369 | xmlBuilder.closeTag(); |
||
370 | 8765 | jjdelcerro | 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 | 4111 | ldiaz | xmlBuilder.closeTag(); |
378 | xmlBuilder.closeTag(); |
||
379 | } |
||
380 | 10536 | caballero | |
381 | 4111 | ldiaz | xmlBuilder.closeTag(); |
382 | xmlBuilder.closeTag(); |
||
383 | xmlBuilder.closeTag(); |
||
384 | 10536 | caballero | xmlBuilder.closeTag(); |
385 | return xmlBuilder.getXML();
|
||
386 | |||
387 | 4111 | ldiaz | }catch(Exception e) |
388 | { |
||
389 | 10536 | caballero | e.printStackTrace(); |
390 | 4111 | ldiaz | return null; |
391 | } |
||
392 | 3632 | ldiaz | } |
393 | 10536 | caballero | |
394 | 3632 | ldiaz | /**
|
395 | * DOCUMENT ME!
|
||
396 | *
|
||
397 | * @return DOCUMENT ME!
|
||
398 | *
|
||
399 | 2796 | caballero | * @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 | 9885 | caballero | xml.putProperty("useDefaultSymbolB", useDefaultSymbol);
|
405 | 2796 | caballero | if (getDefaultSymbol() == null) { |
406 | xml.putProperty("useDefaultSymbol", 0); |
||
407 | } else {
|
||
408 | xml.putProperty("useDefaultSymbol", 1); |
||
409 | xml.addChild(getDefaultSymbol().getXMLEntity()); |
||
410 | } |
||
411 | 1034 | vcaballero | |
412 | 2796 | caballero | xml.putProperty("fieldName", fieldName);
|
413 | xml.putProperty("index", index);
|
||
414 | xml.putProperty("labelfield", labelFieldName);
|
||
415 | 3035 | fjp | xml.putProperty("labelfield", labelFieldName);
|
416 | xml.putProperty("labelFieldHeight", labelFieldHeight);
|
||
417 | xml.putProperty("labelFieldRotation", labelFieldRotation);
|
||
418 | 10536 | caballero | |
419 | 2796 | caballero | xml.putProperty("intervalType", intervalType);
|
420 | xml.putProperty("numKeys", keys.size());
|
||
421 | 1034 | vcaballero | |
422 | 2796 | caballero | if (keys.size() > 0) { |
423 | xml.putProperty("tipoValueKeys", keys.get(0).getClass().getName()); |
||
424 | 532 | vcaballero | |
425 | 2796 | caballero | String[] sk = new String[keys.size()]; |
426 | 2183 | fernando | |
427 | 2796 | caballero | for (int i = 0; i < keys.size(); i++) { |
428 | sk[i] = ((IInterval) keys.get(i)).toString(); |
||
429 | } |
||
430 | 2183 | fernando | |
431 | 2796 | caballero | xml.putProperty("keys", getValues());
|
432 | 2183 | fernando | |
433 | 2796 | caballero | for (int i = 0; i < keys.size(); i++) { |
434 | xml.addChild(getSymbols()[i].getXMLEntity()); |
||
435 | } |
||
436 | } |
||
437 | 2183 | fernando | |
438 | 2796 | caballero | xml.putProperty("startColor", StringUtilities.color2String(startColor));
|
439 | xml.putProperty("endColor", StringUtilities.color2String(endColor));
|
||
440 | 2183 | fernando | |
441 | 2796 | caballero | ///xml.putProperty("numSymbols", symbols.size());
|
442 | ///xml.putProperty("indexs", getIndexs());
|
||
443 | ///xml.putProperty("values", getValues());
|
||
444 | return xml;
|
||
445 | } |
||
446 | 2183 | fernando | |
447 | 2796 | caballero | /**
|
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 | 1034 | vcaballero | |
457 | 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. |
458 | intervalType = xml.getIntProperty("intervalType");
|
||
459 | } |
||
460 | 1034 | vcaballero | |
461 | 2796 | caballero | int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol"); |
462 | 1034 | vcaballero | |
463 | 2796 | caballero | if (useDefaultSymbol == 1) { |
464 | setDefaultSymbol(FSymbol.createFromXML03(xml.getChild(0)));
|
||
465 | } else {
|
||
466 | setDefaultSymbol(null);
|
||
467 | } |
||
468 | 1034 | vcaballero | |
469 | 2796 | caballero | int numKeys = xml.getIntProperty("numKeys"); |
470 | 1034 | vcaballero | |
471 | 2796 | caballero | if (numKeys > 0) { |
472 | String className = xml.getStringProperty("tipoValueKeys"); |
||
473 | String[] sk = xml.getStringArrayProperty("keys"); |
||
474 | IInterval auxInterval; |
||
475 | 532 | vcaballero | |
476 | 2796 | caballero | 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 | 532 | vcaballero | |
487 | 2796 | caballero | startColor = StringUtilities.string2Color(xml.getStringProperty( |
488 | "startColor"));
|
||
489 | endColor = StringUtilities.string2Color(xml.getStringProperty( |
||
490 | "endColor"));
|
||
491 | } |
||
492 | 1034 | vcaballero | |
493 | 2796 | caballero | /**
|
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 | 3035 | fjp | if (xml.contains("labelFieldHeight")) { |
503 | setLabelHeightField(xml.getStringProperty("labelFieldHeight"));
|
||
504 | } |
||
505 | 1034 | vcaballero | |
506 | 3035 | fjp | if (xml.contains("labelFieldRotation")) { |
507 | setLabelRotationField(xml.getStringProperty("labelFieldRotation"));
|
||
508 | } |
||
509 | |||
510 | 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. |
511 | intervalType = xml.getIntProperty("intervalType");
|
||
512 | } |
||
513 | 10536 | caballero | if (xml.contains("useDefaultSymbolB")){ |
514 | useDefaultSymbol = xml.getBooleanProperty("useDefaultSymbolB");
|
||
515 | } |
||
516 | 9885 | caballero | int hasDefaultSymbol = xml.getIntProperty("useDefaultSymbol"); |
517 | 1034 | vcaballero | |
518 | 9885 | caballero | if (hasDefaultSymbol == 1) { |
519 | 2796 | caballero | setDefaultSymbol(FSymbol.createFromXML(xml.getChild(0)));
|
520 | } else {
|
||
521 | setDefaultSymbol(null);
|
||
522 | } |
||
523 | 1034 | vcaballero | |
524 | 2796 | caballero | int numKeys = xml.getIntProperty("numKeys"); |
525 | 1034 | vcaballero | |
526 | 2796 | caballero | if (numKeys > 0) { |
527 | String className = xml.getStringProperty("tipoValueKeys"); |
||
528 | String[] sk = xml.getStringArrayProperty("keys"); |
||
529 | IInterval auxInterval; |
||
530 | 1034 | vcaballero | |
531 | 2796 | caballero | for (int i = 0; i < numKeys; i++) { |
532 | auxInterval = FInterval.create(sk[i]); |
||
533 | symbols.put(auxInterval, |
||
534 | 9885 | caballero | FSymbol.createFromXML(xml.getChild(i + hasDefaultSymbol))); |
535 | 2796 | caballero | keys.add(auxInterval); |
536 | System.out.println("auxInterval =" + auxInterval + "Symbol =" + |
||
537 | 9885 | caballero | FSymbol.createFromXML(xml.getChild(i + hasDefaultSymbol)) |
538 | 2796 | caballero | .getDescription()); |
539 | } |
||
540 | } |
||
541 | 1034 | vcaballero | |
542 | 2796 | caballero | startColor = StringUtilities.string2Color(xml.getStringProperty( |
543 | "startColor"));
|
||
544 | endColor = StringUtilities.string2Color(xml.getStringProperty( |
||
545 | "endColor"));
|
||
546 | } |
||
547 | 1034 | vcaballero | |
548 | 2796 | caballero | /**
|
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 | 1034 | vcaballero | |
555 | 2796 | caballero | /* (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 | 1034 | vcaballero | |
570 | 2796 | caballero | /**
|
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 | 1034 | vcaballero | |
587 | 2796 | caballero | return null; |
588 | } |
||
589 | 1034 | vcaballero | |
590 | 2796 | caballero | /**
|
591 | * Devuelve el color final.
|
||
592 | *
|
||
593 | * @return color final.
|
||
594 | */
|
||
595 | public Color getEndColor() { |
||
596 | return endColor;
|
||
597 | } |
||
598 | 801 | fjp | |
599 | 2796 | caballero | /**
|
600 | * Inserta el color final.
|
||
601 | *
|
||
602 | * @param endColor Color final.
|
||
603 | */
|
||
604 | public void setEndColor(Color endColor) { |
||
605 | this.endColor = endColor;
|
||
606 | } |
||
607 | 1034 | vcaballero | |
608 | 2796 | caballero | /**
|
609 | * Devuelve el color inicial.
|
||
610 | *
|
||
611 | * @return Color inicial.
|
||
612 | */
|
||
613 | public Color getStartColor() { |
||
614 | return startColor;
|
||
615 | } |
||
616 | 1034 | vcaballero | |
617 | 2796 | caballero | /**
|
618 | * Inserta el color inicial.
|
||
619 | *
|
||
620 | * @param startColor Color inicial.
|
||
621 | */
|
||
622 | public void setStartColor(Color startColor) { |
||
623 | this.startColor = startColor;
|
||
624 | } |
||
625 | 801 | fjp | |
626 | 2796 | caballero | /* (non-Javadoc)
|
627 | * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getShapeType()
|
||
628 | */
|
||
629 | public int getShapeType() { |
||
630 | return shapeType;
|
||
631 | } |
||
632 | 2183 | fernando | |
633 | 2796 | caballero | /* (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 | 2200 | vcaballero | |
642 | 2796 | caballero | break;
|
643 | 2200 | vcaballero | |
644 | 2796 | caballero | case FShape.LINE:
|
645 | defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE);
|
||
646 | 2413 | caballero | |
647 | 2796 | caballero | break;
|
648 | 2600 | caballero | |
649 | 2796 | caballero | case FShape.POLYGON:
|
650 | defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL);
|
||
651 | 2600 | caballero | |
652 | 2796 | caballero | 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 | 3035 | fjp | /* public boolean isBWithHeightText() {
|
736 | 2796 | caballero | return bWithHeightText;
|
737 | 3035 | fjp | } */
|
738 | 2796 | caballero | |
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 | 3035 | fjp | /* public void setBWithHeightText(boolean withHeightText) {
|
746 | 2796 | caballero | bWithHeightText = withHeightText;
|
747 | 3035 | fjp | } */
|
748 | 2796 | caballero | |
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 | 3268 | fjp | |
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 | 10536 | caballero | usedFields.add(getFieldName()); |
766 | 3268 | fjp | if (getLabelField() != null) |
767 | usedFields.add(getLabelField()); |
||
768 | if (getLabelHeightField() != null) |
||
769 | usedFields.add(getLabelHeightField()); |
||
770 | if (getLabelRotationField() != null) |
||
771 | usedFields.add(getLabelRotationField()); |
||
772 | 10536 | caballero | |
773 | 3268 | fjp | return (String[]) usedFields.toArray(new String[0]); |
774 | |||
775 | } |
||
776 | 322 | fernando | } |