root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrDefault.java @ 4144
History | View | Annotate | Download (11.8 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.layers; |
42 |
|
43 |
import java.util.ArrayList; |
44 |
import java.util.Iterator; |
45 |
|
46 |
import org.apache.log4j.Logger; |
47 |
import org.cresques.cts.ICoordTrans; |
48 |
import org.cresques.cts.IProjection; |
49 |
import org.cresques.cts.ProjectionPool; |
50 |
import org.cresques.cts.gt2.CoordSys; |
51 |
import org.cresques.cts.gt2.CoordTrans; |
52 |
|
53 |
import com.iver.cit.gvsig.fmap.DriverException; |
54 |
import com.iver.cit.gvsig.fmap.FMap; |
55 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
56 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
57 |
import com.iver.utiles.XMLEntity; |
58 |
|
59 |
|
60 |
/**
|
61 |
* Implementaci?n de las caracter?sticas de alto nivel de las capas:
|
62 |
* visibilidad, activaci?n, nombre, ...
|
63 |
*/
|
64 |
public abstract class FLyrDefault implements FLayer { |
65 |
//private PropertyChangeSupport lnkPropertyChangeSupport;
|
66 |
private static Logger logger = Logger.getLogger(FLyrDefault.class); |
67 |
/** Path de la capa en el arbol de capas */
|
68 |
private FLayers parentLayer = null; |
69 |
private FLayers virtualLayers = null; |
70 |
private FLyrText layerText = null; |
71 |
private String name; |
72 |
private IProjection projection;
|
73 |
private boolean visible = true; |
74 |
private boolean active; |
75 |
private int transparency = 0; |
76 |
private ICoordTrans ct;
|
77 |
private double minScale = -1; // -1 indica que no se usa |
78 |
private double maxScale = -1; |
79 |
protected ArrayList layerListeners = new ArrayList(); |
80 |
|
81 |
private Strategy privateStrategy = null; |
82 |
private boolean isediting; |
83 |
/**
|
84 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setActive(boolean)
|
85 |
*/
|
86 |
public void setActive(boolean selected) { |
87 |
active = selected; |
88 |
callActivationChanged(LayerEvent.createActivationChangedEvent(this, "active")); |
89 |
} |
90 |
|
91 |
/**
|
92 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#isActive()
|
93 |
*/
|
94 |
public boolean isActive() { |
95 |
return active;
|
96 |
} |
97 |
|
98 |
/**
|
99 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setName(java.lang.String)
|
100 |
*/
|
101 |
public void setName(String name) { |
102 |
this.name = name;
|
103 |
callNameChanged(LayerEvent.createNameChangedEvent(this, "name")); |
104 |
} |
105 |
|
106 |
/**
|
107 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getName()
|
108 |
*/
|
109 |
public String getName() { |
110 |
return name;
|
111 |
} |
112 |
|
113 |
/*
|
114 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
|
115 |
*/
|
116 |
public void load() throws DriverIOException { |
117 |
} |
118 |
|
119 |
/**
|
120 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setVisible(boolean)
|
121 |
*/
|
122 |
public void setVisible(boolean visibility) { |
123 |
visible = visibility; |
124 |
callVisibilityChanged(LayerEvent.createVisibilityChangedEvent(this, "visible")); |
125 |
} |
126 |
|
127 |
/**
|
128 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#isVisible()
|
129 |
*/
|
130 |
public boolean isVisible() { |
131 |
return visible;
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* Devuelve la capa padre de la actual.
|
136 |
*
|
137 |
* @return FLayers padre.
|
138 |
*/
|
139 |
public FLayers getParentLayer() {
|
140 |
return parentLayer;
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* Inserta la capa padre.
|
145 |
*
|
146 |
* @param root capa padre.
|
147 |
*/
|
148 |
public void setParentLayer(FLayers root) { |
149 |
this.parentLayer = root;
|
150 |
} |
151 |
|
152 |
/**
|
153 |
* Inserta una proyecci?n.
|
154 |
*
|
155 |
* @param proj Proyecci?n.
|
156 |
*/
|
157 |
public void setProjection(IProjection proj) { |
158 |
projection = proj; |
159 |
// Comprobar que la proyecci?n es la misma que la de FMap
|
160 |
// Si no lo es, es una capa que est? reproyectada al vuelo
|
161 |
if ((proj != null) && (getFMap() != null)) |
162 |
if (proj != getFMap().getProjection())
|
163 |
{ |
164 |
ICoordTrans ct = new CoordTrans((CoordSys) proj,
|
165 |
(CoordSys) getFMap().getProjection()); |
166 |
setCoordTrans(ct); |
167 |
logger.debug("Cambio proyecci?n: FMap con " + getFMap().getProjection().getAbrev()
|
168 |
+ " y capa " + getName() + " con " + proj.getAbrev()); |
169 |
} |
170 |
} |
171 |
|
172 |
/**
|
173 |
* @see org.cresques.geo.Projected#getProjection()
|
174 |
*/
|
175 |
public IProjection getProjection() {
|
176 |
return projection;
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* @see org.cresques.geo.Projected#reProject(org.cresques.cts.ICoordTrans)
|
181 |
*/
|
182 |
public void reProject(ICoordTrans arg0) { |
183 |
} |
184 |
|
185 |
/**
|
186 |
* Devuelve el nivel de transparencia de la capa.
|
187 |
*
|
188 |
* @return Entero que representa el nivel de transparencia.
|
189 |
*/
|
190 |
public int getTransparency() { |
191 |
return transparency;
|
192 |
} |
193 |
|
194 |
/**
|
195 |
* Inserta el nivel de transparencia de la capa.
|
196 |
*
|
197 |
* @param trans Nivel de transparencia.
|
198 |
*/
|
199 |
public void setTransparency(int trans) { |
200 |
transparency = trans; |
201 |
} |
202 |
|
203 |
/**
|
204 |
* Devuelve el XMLEntity a partir del objeto.
|
205 |
*
|
206 |
* @return XMLEntity.
|
207 |
* @throws XMLException
|
208 |
*/
|
209 |
public XMLEntity getXMLEntity() throws XMLException { |
210 |
XMLEntity xml = new XMLEntity();
|
211 |
xml.putProperty("className",this.getClass().getName()); |
212 |
|
213 |
if (this instanceof FLayers) { |
214 |
} |
215 |
|
216 |
xml.putProperty("active", active);
|
217 |
xml.putProperty("name", name);
|
218 |
xml.putProperty("minScale",minScale);
|
219 |
xml.putProperty("maxScale",maxScale);
|
220 |
|
221 |
//TODO xml.addChild(parentLayer.getXMLEntity());
|
222 |
xml.putProperty("visible", visible);
|
223 |
if (projection != null) { |
224 |
xml.putProperty("proj", projection.getAbrev());
|
225 |
} |
226 |
xml.putProperty("transparency", transparency);
|
227 |
|
228 |
return xml;
|
229 |
} |
230 |
|
231 |
/*
|
232 |
* Inserta los valores de los atributos del XMLEntity al objeto.
|
233 |
*
|
234 |
* @param xml XMLEntity.
|
235 |
*
|
236 |
* @throws XMLException
|
237 |
* @throws DriverException
|
238 |
* @throws DriverIOException
|
239 |
*
|
240 |
public void setXMLEntity03(XMLEntity xml)
|
241 |
throws XMLException {
|
242 |
active = xml.getBooleanProperty("active");
|
243 |
name = xml.getStringProperty("name");
|
244 |
minScale=xml.getDoubleProperty("minScale");
|
245 |
maxScale=xml.getDoubleProperty("maxScale");
|
246 |
visible = xml.getBooleanProperty("visible");
|
247 |
if (xml.contains("proj")) {
|
248 |
setProjection(ProjectionPool.get(xml.getStringProperty("proj")));
|
249 |
}
|
250 |
if (xml.contains("transparency"))
|
251 |
transparency = xml.getIntProperty("transparency");
|
252 |
}*/
|
253 |
|
254 |
/**
|
255 |
* Inserta los valores de los atributos del XMLEntity al objeto.
|
256 |
*
|
257 |
* @param xml XMLEntity.
|
258 |
*
|
259 |
* @throws XMLException
|
260 |
* @throws DriverException
|
261 |
* @throws DriverIOException
|
262 |
*/
|
263 |
public void setXMLEntity(XMLEntity xml) |
264 |
throws XMLException {
|
265 |
active = xml.getBooleanProperty("active");
|
266 |
name = xml.getStringProperty("name");
|
267 |
minScale=xml.getDoubleProperty("minScale");
|
268 |
maxScale=xml.getDoubleProperty("maxScale");
|
269 |
visible = xml.getBooleanProperty("visible");
|
270 |
if (xml.contains("proj")) { |
271 |
setProjection(ProjectionPool.get(xml.getStringProperty("proj")));
|
272 |
} |
273 |
if (xml.contains("transparency")) |
274 |
transparency = xml.getIntProperty("transparency");
|
275 |
} |
276 |
|
277 |
/**
|
278 |
* Inserta los valores de los atributos del XMLEntity al objeto.
|
279 |
*
|
280 |
* @param xml XMLEntity.
|
281 |
*
|
282 |
* @throws XMLException
|
283 |
* @throws DriverException
|
284 |
* @throws DriverIOException
|
285 |
*/
|
286 |
public void setXMLEntity03(XMLEntity xml) |
287 |
throws XMLException {
|
288 |
active = xml.getBooleanProperty("active");
|
289 |
name = xml.getStringProperty("name");
|
290 |
minScale=xml.getDoubleProperty("minScale");
|
291 |
maxScale=xml.getDoubleProperty("maxScale");
|
292 |
visible = xml.getBooleanProperty("visible");
|
293 |
if (xml.contains("proj")) { |
294 |
setProjection(ProjectionPool.get(xml.getStringProperty("proj")));
|
295 |
} |
296 |
if (xml.contains("transparency")) |
297 |
transparency = xml.getIntProperty("transparency");
|
298 |
} |
299 |
|
300 |
/**
|
301 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFMap()
|
302 |
*/
|
303 |
public FMap getFMap() {
|
304 |
if (getParentLayer() != null) { |
305 |
return getParentLayer().getFMap();
|
306 |
} else {
|
307 |
return null; |
308 |
} |
309 |
} |
310 |
|
311 |
/**
|
312 |
* A?ade a la lista de listener un nuevo LayerListener.
|
313 |
*
|
314 |
* @param o LayerListener.
|
315 |
*
|
316 |
* @return boolean.
|
317 |
*/
|
318 |
public boolean addLayerListener(LayerListener o) { |
319 |
return layerListeners.add(o);
|
320 |
} |
321 |
|
322 |
/**
|
323 |
* Borra de la lista de listeners el que se pasa como par?metro.
|
324 |
*
|
325 |
* @param o LayerListener a borrar.
|
326 |
*
|
327 |
* @return True si ha sido correcto el borrado del Listener.
|
328 |
*/
|
329 |
public boolean removeLayerListener(LayerListener o) { |
330 |
return layerListeners.remove(o);
|
331 |
} |
332 |
|
333 |
/**
|
334 |
* Llamada al metodo nameChanged de los Listeners dados de alta.
|
335 |
*
|
336 |
* @param e LayerEvent.
|
337 |
*/
|
338 |
private void callNameChanged(LayerEvent e) { |
339 |
for (Iterator iter = layerListeners.iterator(); iter.hasNext();) { |
340 |
LayerListener listener = (LayerListener) iter.next(); |
341 |
|
342 |
listener.nameChanged(e); |
343 |
} |
344 |
} |
345 |
|
346 |
/**
|
347 |
* Llamada al m?todo visibilityChanged de los Listeners.
|
348 |
*
|
349 |
* @param e LayerEvent.
|
350 |
*/
|
351 |
private void callVisibilityChanged(LayerEvent e) { |
352 |
for (Iterator iter = layerListeners.iterator(); iter.hasNext();) { |
353 |
LayerListener listener = (LayerListener) iter.next(); |
354 |
|
355 |
listener.visibilityChanged(e); |
356 |
} |
357 |
} |
358 |
|
359 |
/**
|
360 |
* Llamada al m?todo activationChanged de los Listener.
|
361 |
*
|
362 |
* @param e LayerEvent.
|
363 |
*/
|
364 |
private void callActivationChanged(LayerEvent e) { |
365 |
for (Iterator iter = layerListeners.iterator(); iter.hasNext();) { |
366 |
LayerListener listener = (LayerListener) iter.next(); |
367 |
|
368 |
listener.activationChanged(e); |
369 |
} |
370 |
} |
371 |
|
372 |
/**
|
373 |
* Devuelve las capas virtuales.
|
374 |
*
|
375 |
* @return FLayers.
|
376 |
*/
|
377 |
public FLayers getVirtualLayers() {
|
378 |
return virtualLayers;
|
379 |
} |
380 |
|
381 |
/**
|
382 |
* Inserta las capas virtuales.
|
383 |
*
|
384 |
* @param virtualLayers FLayers.
|
385 |
*/
|
386 |
public void setVirtualLayers(FLayers virtualLayers) { |
387 |
this.virtualLayers = virtualLayers;
|
388 |
} |
389 |
|
390 |
/**
|
391 |
* Devuelve la capa de texto.
|
392 |
*
|
393 |
* @return capa de texto.
|
394 |
*/
|
395 |
public FLyrText getLayerText() {
|
396 |
return layerText;
|
397 |
} |
398 |
|
399 |
/**
|
400 |
* Inserta la capa de texto.
|
401 |
*
|
402 |
* @param layerText Capa de texto.
|
403 |
*/
|
404 |
public void setLayerText(FLyrText layerText) { |
405 |
this.layerText = layerText;
|
406 |
} |
407 |
|
408 |
/**
|
409 |
* Inserta las coordenadas de transformaci?n.
|
410 |
*
|
411 |
* @param ct Cooredenadas de transformaci?n.
|
412 |
*/
|
413 |
public void setCoordTrans(ICoordTrans ct) { |
414 |
this.ct = ct;
|
415 |
} |
416 |
|
417 |
/**
|
418 |
* Devuelve las coordenadas de transformaci?n.
|
419 |
*
|
420 |
* @return Coordenadas de transformaci?n.
|
421 |
*/
|
422 |
public ICoordTrans getCoordTrans() {
|
423 |
return ct;
|
424 |
} |
425 |
|
426 |
public double getMinScale() { |
427 |
return minScale;
|
428 |
} |
429 |
|
430 |
/* (non-Javadoc)
|
431 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getMaxScale()
|
432 |
*/
|
433 |
public double getMaxScale() { |
434 |
return maxScale;
|
435 |
} |
436 |
|
437 |
public void setMinScale(double minScale) |
438 |
{ |
439 |
this.minScale = minScale;
|
440 |
} |
441 |
public void setMaxScale(double maxScale) |
442 |
{ |
443 |
this.maxScale = maxScale;
|
444 |
} |
445 |
|
446 |
public boolean isWithinScale(double scale) |
447 |
{ |
448 |
|
449 |
boolean bVisible = true; |
450 |
if (getMinScale() != -1) |
451 |
{ |
452 |
if (scale < getMinScale())
|
453 |
bVisible = false;
|
454 |
} |
455 |
if (getMaxScale() != -1) |
456 |
{ |
457 |
if (scale > getMaxScale())
|
458 |
bVisible = false;
|
459 |
} |
460 |
|
461 |
return bVisible;
|
462 |
} |
463 |
|
464 |
public Strategy getStrategy()
|
465 |
{ |
466 |
return privateStrategy;
|
467 |
} |
468 |
public void setStrategy(Strategy s) |
469 |
{ |
470 |
privateStrategy = s; |
471 |
} |
472 |
|
473 |
public void setEditing(boolean b) { |
474 |
isediting=b; |
475 |
callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
476 |
} |
477 |
private void callEditionChanged(LayerEvent e) { |
478 |
for (Iterator iter = layerListeners.iterator(); iter.hasNext();) { |
479 |
LayerListener listener = (LayerListener) iter.next(); |
480 |
|
481 |
listener.editionChanged(e); |
482 |
} |
483 |
} |
484 |
|
485 |
public boolean isEditing(){ |
486 |
return isediting;
|
487 |
} |
488 |
|
489 |
|
490 |
} |