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