svn-gvsig-desktop / trunk / extensions / extAnnotations / src / com / iver / cit / gvsig / fmap / rendering / Annotation_Legend.java @ 26937
History | View | Annotate | Download (11.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 |
|
46 |
import com.hardcode.gdbms.engine.data.DataSource; |
47 |
import com.hardcode.gdbms.engine.values.Value; |
48 |
import com.iver.cit.gvsig.fmap.core.CartographicSupportToolkit; |
49 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
50 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
51 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
52 |
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol; |
53 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleTextSymbol; |
54 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
55 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
56 |
import com.iver.utiles.XMLEntity; |
57 |
|
58 |
/**
|
59 |
* Leyenda vectorial para labels.
|
60 |
*
|
61 |
* @author Vicente Caballero Navarro
|
62 |
*/
|
63 |
public class Annotation_Legend extends AbstractLegend implements IVectorLegend{ |
64 |
private String fieldName; |
65 |
|
66 |
protected int fieldId = -1; |
67 |
|
68 |
private String labelFieldName; |
69 |
|
70 |
private String labelFieldHeight; |
71 |
|
72 |
private String labelFieldRotation; |
73 |
|
74 |
private ITextSymbol defaultSymbol = SymbologyFactory.createDefaultTextSymbol();
|
75 |
|
76 |
private int shapeType; |
77 |
|
78 |
private boolean useDefaultSymbol = false; |
79 |
|
80 |
// private boolean overwrite=true;
|
81 |
|
82 |
private boolean avoidoverlapping=false; |
83 |
|
84 |
private boolean deloverlapping=false; |
85 |
|
86 |
private boolean isFontInPixels; |
87 |
|
88 |
private boolean pointVisible=true; |
89 |
|
90 |
private int units = CartographicSupportToolkit.DefaultMeasureUnit; |
91 |
|
92 |
public Annotation_Legend() {
|
93 |
isFontInPixels=true;
|
94 |
defaultSymbol.setTextColor(Color.black);
|
95 |
((SimpleTextSymbol)defaultSymbol).setRotation(0);
|
96 |
defaultSymbol.setFontSize(10);
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#addSymbol(java.lang.Object,
|
101 |
* ISymbol)
|
102 |
*/
|
103 |
public void addSymbol(Object key, ISymbol symbol) { |
104 |
} |
105 |
|
106 |
/**
|
107 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#clear()
|
108 |
*/
|
109 |
public void clear() { |
110 |
} |
111 |
|
112 |
/**
|
113 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#getDescriptions()
|
114 |
*/
|
115 |
public String[] getDescriptions() { |
116 |
return null; |
117 |
} |
118 |
|
119 |
/**
|
120 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#getSymbols()
|
121 |
*/
|
122 |
public ISymbol[] getSymbols() { |
123 |
return null; |
124 |
} |
125 |
|
126 |
/**
|
127 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#getFieldName()
|
128 |
*/
|
129 |
public String getFieldName() { |
130 |
return fieldName;
|
131 |
} |
132 |
|
133 |
/**
|
134 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDefaultSymbol(ISymbol)
|
135 |
*/
|
136 |
public void setDefaultSymbol(ISymbol s) { |
137 |
defaultSymbol = (ITextSymbol) s; |
138 |
} |
139 |
|
140 |
/*
|
141 |
* (non-Javadoc)
|
142 |
*
|
143 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getLabelField()
|
144 |
*/
|
145 |
public String getLabelField() { |
146 |
return labelFieldName;
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#setLabelField(int)
|
151 |
*/
|
152 |
public void setLabelField(String fieldName) { |
153 |
labelFieldName = fieldName; |
154 |
} |
155 |
|
156 |
/**
|
157 |
* @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#setField()
|
158 |
*/
|
159 |
public void setFieldName(String str) { |
160 |
fieldName = str; |
161 |
} |
162 |
|
163 |
/**
|
164 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getSymbol(int)
|
165 |
*/
|
166 |
public ISymbol getSymbol(int recordIndex){ |
167 |
return null; |
168 |
} |
169 |
|
170 |
/**
|
171 |
* Devuelve un s?mbolo a partir de una IFeature. OJO!! Cuando usamos un
|
172 |
* feature iterator de base de datos el ?nico campo que vendr? rellenado es
|
173 |
* el de fieldID. Los dem?s vendr?n a nulos para ahorra tiempo de creaci?n.
|
174 |
*
|
175 |
* @param feat
|
176 |
* IFeature
|
177 |
*
|
178 |
* @return S?mbolo.
|
179 |
*/
|
180 |
public ISymbol getSymbolByFeature(IFeature feat) {
|
181 |
return null; |
182 |
} |
183 |
|
184 |
/**
|
185 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#getDefaultSymbol()
|
186 |
*/
|
187 |
public ISymbol getDefaultSymbol() {
|
188 |
return defaultSymbol;
|
189 |
} |
190 |
|
191 |
/**
|
192 |
* @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#getValues()
|
193 |
*/
|
194 |
public Object[] getValues() { |
195 |
// return symbols.keySet().toArray(new Object[0]);
|
196 |
return null; |
197 |
} |
198 |
|
199 |
/**
|
200 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#getXMLEntity()
|
201 |
*/
|
202 |
public XMLEntity getXMLEntity() {
|
203 |
XMLEntity xml = new XMLEntity();
|
204 |
xml.putProperty("className", this.getClass().getName()); |
205 |
xml.putProperty("fieldName", fieldName);
|
206 |
xml.putProperty("labelfield", labelFieldName);
|
207 |
xml.putProperty("labelFieldHeight", labelFieldHeight);
|
208 |
xml.putProperty("labelFieldRotation", labelFieldRotation);
|
209 |
xml.putProperty("avoidoverlapping",avoidoverlapping);
|
210 |
xml.putProperty("deloverlapping",deloverlapping);
|
211 |
|
212 |
// xml.putProperty("overwrite",overwrite);
|
213 |
xml.putProperty("units", units);
|
214 |
xml.putProperty("isFontInPixels",isFontInPixels);
|
215 |
xml.putProperty("pointVisible",pointVisible);
|
216 |
|
217 |
xml.putProperty("useDefaultSymbol", useDefaultSymbol);
|
218 |
xml.addChild(getDefaultSymbol().getXMLEntity()); |
219 |
return xml;
|
220 |
} |
221 |
|
222 |
/**
|
223 |
* Inserta el XMLEntity.
|
224 |
*
|
225 |
* @param xml
|
226 |
* XMLEntity.
|
227 |
*/
|
228 |
public void setXMLEntity03(XMLEntity xml) { |
229 |
|
230 |
} |
231 |
|
232 |
/**
|
233 |
* Inserta el XMLEntity.
|
234 |
*
|
235 |
* @param xml
|
236 |
* XMLEntity.
|
237 |
*/
|
238 |
public void setXMLEntity(XMLEntity xml) { |
239 |
clear(); |
240 |
setFieldName(xml.getStringProperty("fieldName"));
|
241 |
setLabelField(xml.getStringProperty("labelfield"));
|
242 |
|
243 |
if (xml.contains("labelFieldHeight")) { |
244 |
setLabelHeightField(xml.getStringProperty("labelFieldHeight"));
|
245 |
} |
246 |
|
247 |
if (xml.contains("labelFieldRotation")) { |
248 |
setLabelRotationField(xml.getStringProperty("labelFieldRotation"));
|
249 |
} |
250 |
|
251 |
useDefaultSymbol = xml.getBooleanProperty("useDefaultSymbol");
|
252 |
if (xml.contains("avoidoverlapping")){ |
253 |
avoidoverlapping=xml.getBooleanProperty("avoidoverlapping");
|
254 |
deloverlapping=xml.getBooleanProperty("deloverlapping");
|
255 |
} |
256 |
if (xml.contains("pointVisible")) { |
257 |
pointVisible = xml.getBooleanProperty("pointVisible");
|
258 |
} |
259 |
if (xml.contains("units")) { |
260 |
units = xml.getIntProperty("units");
|
261 |
} |
262 |
if (xml.contains("isFontInPixels")) { |
263 |
isFontInPixels=xml.getBooleanProperty("isFontInPixels");
|
264 |
defaultSymbol = (ITextSymbol)SymbologyFactory.createSymbolFromXML(xml.getChild(0),"default symbol"); |
265 |
|
266 |
} |
267 |
else {
|
268 |
FSymbol symbol=(FSymbol)SymbologyFactory.createSymbolFromXML(xml.getChild(0),"default symbol"); |
269 |
isFontInPixels =symbol.isFontSizeInPixels(); |
270 |
pointVisible=symbol.isShapeVisible(); |
271 |
defaultSymbol=(SimpleTextSymbol)SymbologyFactory.createDefaultTextSymbol(); |
272 |
} |
273 |
|
274 |
|
275 |
} |
276 |
|
277 |
/**
|
278 |
* @see com.iver.cit.gvsig.fmap.rendering.Legend#cloneLegend()
|
279 |
*/
|
280 |
public ILegend cloneLegend() throws XMLException { |
281 |
return LegendFactory.createFromXML(getXMLEntity());
|
282 |
} |
283 |
|
284 |
/*
|
285 |
* (non-Javadoc)
|
286 |
*
|
287 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDataSource(com.hardcode.gdbms.engine.data.DataSource)
|
288 |
*/
|
289 |
public void setDataSource(DataSource ds) { |
290 |
// try {
|
291 |
// dataSource = ds;
|
292 |
// ds.start();
|
293 |
// fieldId = ds.getFieldIndexByName(fieldName);
|
294 |
// ds.stop();
|
295 |
// } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
296 |
// throw new DriverException(e);
|
297 |
// }
|
298 |
} |
299 |
|
300 |
/*
|
301 |
* (non-Javadoc)
|
302 |
*
|
303 |
* @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#getSymbolByValue(com.hardcode.gdbms.engine.values.Value)
|
304 |
*/
|
305 |
public ISymbol getSymbolByValue(Value key) {
|
306 |
return null; |
307 |
} |
308 |
|
309 |
/*
|
310 |
* (non-Javadoc)
|
311 |
*
|
312 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getShapeType()
|
313 |
*/
|
314 |
public int getShapeType() { |
315 |
return shapeType;
|
316 |
} |
317 |
|
318 |
/*
|
319 |
* (non-Javadoc)
|
320 |
*
|
321 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getLabelHeightField()
|
322 |
*/
|
323 |
public String getLabelHeightField() { |
324 |
return labelFieldHeight;
|
325 |
} |
326 |
|
327 |
/**
|
328 |
* Inserta el alto de campo.
|
329 |
*
|
330 |
* @param str
|
331 |
* alto.
|
332 |
*/
|
333 |
public void setLabelHeightField(String str) { |
334 |
labelFieldHeight = str; |
335 |
} |
336 |
|
337 |
/*
|
338 |
* (non-Javadoc)
|
339 |
*
|
340 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getLabelRotationField()
|
341 |
*/
|
342 |
public String getLabelRotationField() { |
343 |
return labelFieldRotation;
|
344 |
} |
345 |
|
346 |
/**
|
347 |
* Inserta rotaci?n.
|
348 |
*
|
349 |
* @param str
|
350 |
* Rotaci?n.
|
351 |
*/
|
352 |
public void setLabelRotationField(String str) { |
353 |
labelFieldRotation = str; |
354 |
} |
355 |
|
356 |
/**
|
357 |
* Introduce si se tiene que representar el resto de valores o no.
|
358 |
*
|
359 |
* @param b
|
360 |
* True si se utiliza el resto de valores.
|
361 |
*/
|
362 |
public void useDefaultSymbol(boolean b) { |
363 |
useDefaultSymbol = b; |
364 |
} |
365 |
|
366 |
/**
|
367 |
* Devuelve si se utiliza o no el resto de valores para representarse.
|
368 |
*
|
369 |
* @return True si se utiliza el resto de valores.
|
370 |
*/
|
371 |
public boolean isUseDefaultSymbol() { |
372 |
return useDefaultSymbol;
|
373 |
} |
374 |
|
375 |
/**
|
376 |
* Elimina el s?mbolo que tiene como clave el valor que se pasa como
|
377 |
* par?metro.
|
378 |
*
|
379 |
* @param key
|
380 |
* clave.
|
381 |
*/
|
382 |
public void delSymbol(Object key) { |
383 |
} |
384 |
|
385 |
/*
|
386 |
* (non-Javadoc)
|
387 |
*
|
388 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getUsedFields()
|
389 |
*/
|
390 |
public String[] getUsedFields() { |
391 |
ArrayList usedFields = new ArrayList(); |
392 |
if (getFieldName() != null) |
393 |
usedFields.add(getFieldName()); |
394 |
if (getLabelField() != null) |
395 |
usedFields.add(getLabelField()); |
396 |
if (getLabelHeightField() != null) |
397 |
usedFields.add(getLabelHeightField()); |
398 |
if (getLabelRotationField() != null) |
399 |
usedFields.add(getLabelRotationField()); |
400 |
|
401 |
return (String[]) usedFields.toArray(new String[0]); |
402 |
|
403 |
} |
404 |
|
405 |
public void setShapeType(int shapeType) { |
406 |
// TODO Auto-generated method stub
|
407 |
|
408 |
} |
409 |
|
410 |
public String getSLDString(String layerName) { |
411 |
// TODO Auto-generated method stub
|
412 |
return null; |
413 |
} |
414 |
// public void setIsOverWrite(boolean b) {
|
415 |
// overwrite=b;
|
416 |
//
|
417 |
// }
|
418 |
|
419 |
// public boolean isOverWrite() {
|
420 |
// return overwrite;
|
421 |
// }
|
422 |
|
423 |
public boolean isAvoidOverLapping() { |
424 |
return avoidoverlapping;
|
425 |
} |
426 |
|
427 |
public void setAvoidOverLapping(boolean avoidoverlapping) { |
428 |
this.avoidoverlapping = avoidoverlapping;
|
429 |
} |
430 |
|
431 |
public boolean isDelOverLapping() { |
432 |
return deloverlapping;
|
433 |
} |
434 |
|
435 |
public void setDelOverLapping(boolean deloverlapping) { |
436 |
this.deloverlapping = deloverlapping;
|
437 |
} |
438 |
|
439 |
public ZSort getZSort() {
|
440 |
// TODO Auto-generated method stub
|
441 |
return null; |
442 |
} |
443 |
|
444 |
public void setZSort(ZSort zSort) { |
445 |
// TODO Auto-generated method stub
|
446 |
|
447 |
} |
448 |
public String getClassName() { |
449 |
return this.getClass().getName(); |
450 |
} |
451 |
|
452 |
public boolean isFontSizeInPixels() { |
453 |
return isFontInPixels;
|
454 |
} |
455 |
|
456 |
public void setFontInPixels(boolean isFontInPixels) { |
457 |
this.isFontInPixels = isFontInPixels;
|
458 |
} |
459 |
|
460 |
public int getUnits() { |
461 |
return units;
|
462 |
} |
463 |
|
464 |
public void setUnits(int units) { |
465 |
if(units == -1){ |
466 |
this.isFontInPixels = true; |
467 |
} |
468 |
this.units = units;
|
469 |
} |
470 |
|
471 |
public void setPointVisible(boolean b) { |
472 |
this.pointVisible=b;
|
473 |
|
474 |
} |
475 |
|
476 |
public boolean isPointVisible() { |
477 |
return pointVisible;
|
478 |
} |
479 |
|
480 |
public boolean isSuitableForShapeType(int shapeType) { |
481 |
return this.shapeType == shapeType; |
482 |
} |
483 |
} |