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