root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / FLayers.java @ 30187
History | View | Annotate | Download (43.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 org.gvsig.fmap.mapcontext.layers; |
42 |
|
43 |
import java.awt.Graphics2D; |
44 |
import java.awt.Point; |
45 |
import java.awt.image.BufferedImage; |
46 |
import java.util.ArrayList; |
47 |
import java.util.Collections; |
48 |
import java.util.Iterator; |
49 |
import java.util.List; |
50 |
import java.util.Set; |
51 |
import java.util.TreeSet; |
52 |
import java.util.Vector; |
53 |
|
54 |
import org.cresques.cts.ICoordTrans; |
55 |
import org.cresques.cts.IProjection; |
56 |
import org.gvsig.compat.print.PrintAttributes; |
57 |
import org.gvsig.fmap.dal.DataTypes; |
58 |
import org.gvsig.fmap.dal.exception.DataException; |
59 |
import org.gvsig.fmap.dal.exception.ReadException; |
60 |
import org.gvsig.fmap.geom.primitive.Envelope; |
61 |
import org.gvsig.fmap.mapcontext.MapContext; |
62 |
import org.gvsig.fmap.mapcontext.Messages; |
63 |
import org.gvsig.fmap.mapcontext.ViewPort; |
64 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
65 |
import org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer; |
66 |
import org.gvsig.fmap.mapcontext.layers.operations.InfoByPoint; |
67 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection; |
68 |
import org.gvsig.fmap.mapcontext.layers.operations.LayersVisitable; |
69 |
import org.gvsig.fmap.mapcontext.layers.operations.LayersVisitor; |
70 |
import org.gvsig.fmap.mapcontext.layers.operations.XMLItem; |
71 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelable; |
72 |
import org.gvsig.tools.ToolsLocator; |
73 |
import org.gvsig.tools.dynobject.DynClass; |
74 |
import org.gvsig.tools.dynobject.DynObjectManager; |
75 |
import org.gvsig.tools.exception.BaseException; |
76 |
import org.gvsig.tools.persistence.PersistenceException; |
77 |
import org.gvsig.tools.persistence.PersistentState; |
78 |
import org.gvsig.tools.task.Cancellable; |
79 |
import org.gvsig.tools.visitor.NotSupportedOperationException; |
80 |
import org.gvsig.tools.visitor.Visitor; |
81 |
import org.slf4j.Logger; |
82 |
import org.slf4j.LoggerFactory; |
83 |
|
84 |
|
85 |
/**
|
86 |
* <p>Represents a generic collection of layers, that can be represented as a node in a tree of nodes of layers.</p>
|
87 |
*
|
88 |
* <p>Adapts the basic functionality implemented for a layer in the abstract class <code>FLyrDefault</code>, to
|
89 |
* a collection of layers, implementing, as well, specific methods for this kind of object, defined in the
|
90 |
* interfaces <code>VectorialData</code>, <code>LayerCollection</code>, and <code>InfoByPoint</code>.</p>
|
91 |
*
|
92 |
* @see FLyrDefault
|
93 |
*/
|
94 |
public class FLayers extends FLyrDefault implements LayerCollection, |
95 |
InfoByPoint { |
96 |
/**
|
97 |
* List with all listeners registered for this kind of node.
|
98 |
*
|
99 |
* @see #addLayerCollectionListener(LayerCollectionListener)
|
100 |
* @see #removeLayerCollectionListener(LayerCollectionListener)
|
101 |
* @see #callLayerAdded(LayerCollectionEvent)
|
102 |
* @see #callLayerAdding(LayerCollectionEvent)
|
103 |
* @see #callLayerMoved(LayerPositionEvent)
|
104 |
* @see #callLayerMoving(LayerPositionEvent)
|
105 |
* @see #callLayerRemoved(LayerCollectionEvent)
|
106 |
* @see #callLayerRemoving(LayerCollectionEvent)
|
107 |
*/
|
108 |
protected ArrayList layerCollectionListeners = null; |
109 |
|
110 |
/**
|
111 |
* A synchronized list with the layers.
|
112 |
*
|
113 |
* @see #setAllVisibles(boolean)
|
114 |
* @see #addLayer(FLayer)
|
115 |
* @see #addLayer(int, FLayer)
|
116 |
* @see #moveTo(int, int)
|
117 |
* @see #removeLayer(FLayer)
|
118 |
* @see #removeLayer(int)
|
119 |
* @see #removeLayer(String)
|
120 |
* @see #replaceLayer(String, FLayer)
|
121 |
* @see #getVisibles()
|
122 |
* @see #getLayer(int)
|
123 |
* @see #getLayer(String)
|
124 |
* @see #getLayersCount()
|
125 |
* @see #getFullEnvelope()
|
126 |
*/
|
127 |
protected List layers = null; |
128 |
|
129 |
/**
|
130 |
* The model of the layer.
|
131 |
*
|
132 |
* @see #getMapContext()
|
133 |
*/
|
134 |
protected MapContext fmap;
|
135 |
|
136 |
/**
|
137 |
* Useful for debug the problems during the implementation.
|
138 |
*/
|
139 |
private static Logger logger = LoggerFactory.getLogger(FLayers.class); |
140 |
|
141 |
public FLayers() {
|
142 |
super();
|
143 |
layerCollectionListeners = new ArrayList(); |
144 |
layers = Collections.synchronizedList(new ArrayList()); |
145 |
|
146 |
logger = LoggerFactory.getLogger(FLayers.class); |
147 |
} |
148 |
/*
|
149 |
* (non-Javadoc)
|
150 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#addLayerCollectionListener(com.iver.cit.gvsig.fmap.layers.LayerCollectionListener)
|
151 |
*/
|
152 |
public void addLayerCollectionListener(LayerCollectionListener listener) { |
153 |
if (!layerCollectionListeners.contains(listener)) {
|
154 |
layerCollectionListeners.add(listener); |
155 |
} |
156 |
} |
157 |
|
158 |
/*
|
159 |
* (non-Javadoc)
|
160 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#setAllVisibles(boolean)
|
161 |
*/
|
162 |
public void setAllVisibles(boolean visible) { |
163 |
FLayer lyr; |
164 |
|
165 |
for (int i = 0; i < layers.size(); i++) { |
166 |
lyr = ((FLayer) layers.get(i)); |
167 |
lyr.setVisible(visible); |
168 |
|
169 |
if (lyr instanceof LayerCollection) { |
170 |
((LayerCollection) lyr).setAllVisibles(visible); |
171 |
} |
172 |
} |
173 |
} |
174 |
|
175 |
/*
|
176 |
* (non-Javadoc)
|
177 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#removeLayerCollectionListener(com.iver.cit.gvsig.fmap.layers.LayerCollectionListener)
|
178 |
*/
|
179 |
public void removeLayerCollectionListener(LayerCollectionListener listener) { |
180 |
layerCollectionListeners.remove(listener); |
181 |
} |
182 |
|
183 |
/**
|
184 |
* Adds a layer on an specified position in this node.
|
185 |
*
|
186 |
* @param pos position in the inner list where the layer will be added
|
187 |
* @param layer a layer
|
188 |
*/
|
189 |
private void doAddLayer(int pos,FLayer layer) { |
190 |
layers.add(pos,layer); |
191 |
layer.setParentLayer(this);
|
192 |
IProjection layerProj = layer.getProjection(); |
193 |
if(layerProj != null && fmap != null) { |
194 |
IProjection mapContextProj = fmap.getProjection(); |
195 |
// TODO REVISAR ESTO !!!!
|
196 |
// Esta condici?n puede que no fuese exacta para todos los casos
|
197 |
if (!layerProj.getAbrev().equals(mapContextProj.getAbrev())) {
|
198 |
ICoordTrans ct = layerProj.getCT(mapContextProj); |
199 |
layer.setCoordTrans(ct); |
200 |
} else {
|
201 |
layer.setCoordTrans(null);
|
202 |
} |
203 |
} |
204 |
this.updateDrawVersion();
|
205 |
} |
206 |
|
207 |
/*
|
208 |
* (non-Javadoc)
|
209 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#addLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
|
210 |
*/
|
211 |
public void addLayer(FLayer layer) { |
212 |
addLayer(layers.size(),layer); |
213 |
} |
214 |
|
215 |
/**
|
216 |
* Adds a layer in an specified position in this node.
|
217 |
*
|
218 |
* @param layer a layer
|
219 |
*/
|
220 |
public void addLayer(int pos,FLayer layer) { |
221 |
try {
|
222 |
//Notificamos a la capa que va a ser a?adida
|
223 |
if (layer instanceof FLyrDefault) { |
224 |
((FLyrDefault)layer).wakeUp(); |
225 |
} |
226 |
|
227 |
if (layer instanceof FLayers){ |
228 |
FLayers layers=(FLayers)layer; |
229 |
fmap.addAsCollectionListener(layers); |
230 |
} |
231 |
callLayerAdding(LayerCollectionEvent.createLayerAddingEvent(layer)); |
232 |
|
233 |
doAddLayer(pos,layer); |
234 |
|
235 |
callLayerAdded(LayerCollectionEvent.createLayerAddedEvent(layer)); |
236 |
} catch (CancelationException e) {
|
237 |
logger.warn(e.getMessage()); |
238 |
} catch (LoadLayerException e) {
|
239 |
layer.setAvailable(false);
|
240 |
layer.addError(e); |
241 |
} |
242 |
} |
243 |
|
244 |
/*
|
245 |
* (non-Javadoc)
|
246 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#moveTo(int, int)
|
247 |
*/
|
248 |
public void moveTo(int from, int to) throws CancelationException { |
249 |
int newfrom=layers.size()-from-1; |
250 |
int newto=layers.size()-to-1; |
251 |
if ( newfrom < 0 || newfrom >=layers.size() || newto < 0 || newto >= layers.size()) { |
252 |
return;
|
253 |
} |
254 |
FLayer aux = (FLayer) layers.get(newfrom); |
255 |
callLayerMoving(LayerPositionEvent.createLayerMovingEvent(aux, newfrom, newto)); |
256 |
layers.remove(newfrom); |
257 |
layers.add(newto, aux); |
258 |
this.updateDrawVersion();
|
259 |
callLayerMoved(LayerPositionEvent.createLayerMovedEvent(aux, newfrom, newto)); |
260 |
} |
261 |
|
262 |
/**
|
263 |
* Removes an inner layer.
|
264 |
*
|
265 |
* @param lyr a layer
|
266 |
*/
|
267 |
private void doRemoveLayer(FLayer lyr) { |
268 |
layers.remove(lyr); |
269 |
this.updateDrawVersion();
|
270 |
} |
271 |
|
272 |
/*
|
273 |
* (non-Javadoc)
|
274 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#removeLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
|
275 |
*/
|
276 |
public void removeLayer(FLayer lyr) throws CancelationException { |
277 |
callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(lyr)); |
278 |
doRemoveLayer(lyr); |
279 |
callLayerRemoved(LayerCollectionEvent.createLayerRemovedEvent(lyr)); |
280 |
} |
281 |
|
282 |
/*
|
283 |
* (non-Javadoc)
|
284 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#removeLayer(int)
|
285 |
*/
|
286 |
public void removeLayer(int idLayer) { |
287 |
FLayer lyr = (FLayer) layers.get(idLayer); |
288 |
callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(lyr)); |
289 |
layers.remove(idLayer); |
290 |
this.updateDrawVersion();
|
291 |
callLayerRemoved(LayerCollectionEvent.createLayerRemovedEvent(lyr)); |
292 |
} |
293 |
|
294 |
/*
|
295 |
* (non-Javadoc)
|
296 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#removeLayer(java.lang.String)
|
297 |
*/
|
298 |
public void removeLayer(String layerName) { |
299 |
FLayer lyr; |
300 |
|
301 |
for (int i = 0; i < layers.size(); i++) { |
302 |
lyr = ((FLayer) layers.get(i)); |
303 |
|
304 |
if (lyr.getName().compareToIgnoreCase(layerName) == 0) { |
305 |
removeLayer(i); |
306 |
|
307 |
break;
|
308 |
} |
309 |
} |
310 |
} |
311 |
|
312 |
/**
|
313 |
* Replace a layer identified by its name, by another.
|
314 |
*
|
315 |
* @param layerName the name of the layer to be replaced
|
316 |
* @param layer the new layer
|
317 |
*/
|
318 |
public void replaceLayer(String layerName, FLayer layer) throws LoadLayerException |
319 |
{ |
320 |
FLayer lyr; |
321 |
FLayer parent; |
322 |
for (int i = 0; i < layers.size(); i++) { |
323 |
lyr = ((FLayer) layers.get(i)); |
324 |
|
325 |
if (lyr.getName().compareToIgnoreCase(layerName) == 0) { |
326 |
parent = lyr.getParentLayer(); |
327 |
removeLayer(i); |
328 |
if (parent != null) { |
329 |
//Notificamos a la capa que va a ser a?adida
|
330 |
if (layer instanceof FLyrDefault) { |
331 |
((FLyrDefault)layer).wakeUp(); |
332 |
} |
333 |
} |
334 |
|
335 |
if (layer instanceof FLayers){ |
336 |
FLayers layers=(FLayers)layer; |
337 |
fmap.addAsCollectionListener(layers); |
338 |
} |
339 |
callLayerAdding(LayerCollectionEvent.createLayerAddingEvent(layer)); |
340 |
|
341 |
layers.add(i,layer); |
342 |
layer.setParentLayer(this);
|
343 |
|
344 |
callLayerAdded(LayerCollectionEvent.createLayerAddedEvent(layer)); |
345 |
break;
|
346 |
} |
347 |
} |
348 |
} |
349 |
|
350 |
/*
|
351 |
* (non-Javadoc)
|
352 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getVisibles()
|
353 |
*/
|
354 |
public FLayer[] getVisibles() { |
355 |
ArrayList array = new ArrayList(); |
356 |
LayersIterator iter = new LayersIterator(this) { |
357 |
public boolean evaluate(FLayer layer) { |
358 |
return layer.isVisible();
|
359 |
} |
360 |
|
361 |
}; |
362 |
|
363 |
while (iter.hasNext()) {
|
364 |
array.add(iter.nextLayer()); |
365 |
} |
366 |
|
367 |
return (FLayer[]) array.toArray(new FLayer[0]); |
368 |
} |
369 |
|
370 |
/*
|
371 |
* (non-Javadoc)
|
372 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getLayer(int)
|
373 |
*/
|
374 |
public FLayer getLayer(int index) { |
375 |
return (FLayer) layers.get(index);
|
376 |
} |
377 |
|
378 |
/*
|
379 |
* (non-Javadoc)
|
380 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getLayer(java.lang.String)
|
381 |
*/
|
382 |
public FLayer getLayer(String layerName) { |
383 |
FLayer lyr; |
384 |
FLayer lyr2; |
385 |
ArrayList layerList;
|
386 |
|
387 |
for (int i = 0; i < layers.size(); i++) { |
388 |
lyr = ((FLayer) layers.get(i)); |
389 |
|
390 |
if (lyr.getName().compareToIgnoreCase(layerName) == 0) { |
391 |
return lyr;
|
392 |
} |
393 |
|
394 |
layerList = new ArrayList(); |
395 |
splitLayerGroup(lyr,layerList); |
396 |
for(int j = 0; j<layerList.size(); j++ ) |
397 |
{ |
398 |
lyr2 = ((FLayer)layerList.get(j)); |
399 |
if (lyr2.getName().compareToIgnoreCase(layerName) == 0) { |
400 |
return lyr2;
|
401 |
} |
402 |
} |
403 |
} |
404 |
|
405 |
return null; |
406 |
} |
407 |
|
408 |
/**
|
409 |
* <p> Splits up a layer group in order to get a layer by name when there are layer groups</p>
|
410 |
*
|
411 |
* <p>In <code>result</code> always will be at least one layer.</p>
|
412 |
*
|
413 |
* @param layer the layer we are looking for
|
414 |
* @param result an array list that will have the results of the search
|
415 |
*/
|
416 |
private void splitLayerGroup(FLayer layer, ArrayList result) |
417 |
{ |
418 |
int i;
|
419 |
FLayers layerGroup; |
420 |
if (layer instanceof FLayers) |
421 |
{ |
422 |
layerGroup = (FLayers)layer; |
423 |
for (i=0; i < layerGroup.getLayersCount(); i++ ) |
424 |
{ |
425 |
splitLayerGroup(layerGroup.getLayer(i),result); |
426 |
} |
427 |
} |
428 |
else
|
429 |
{ |
430 |
result.add(layer); |
431 |
} |
432 |
} |
433 |
|
434 |
/*
|
435 |
* (non-Javadoc)
|
436 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getLayersCount()
|
437 |
*/
|
438 |
public int getLayersCount() { |
439 |
return layers.size();
|
440 |
} |
441 |
|
442 |
/*
|
443 |
* (non-Javadoc)
|
444 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.utiles.swing.threads.Cancellable, double)
|
445 |
*/
|
446 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
447 |
Cancellable cancel, double scale) throws ReadException { |
448 |
// FIXME Arreglar este error
|
449 |
throw new RuntimeException("Esto no deberia de llamarse"); |
450 |
} |
451 |
|
452 |
/*
|
453 |
* (non-Javadoc)
|
454 |
*
|
455 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
456 |
* com.iver.cit.gvsig.fmap.ViewPort,
|
457 |
* com.iver.utiles.swing.threads.Cancellable, double,
|
458 |
* javax.print.attribute.PrintAttributes)
|
459 |
*/
|
460 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
461 |
double scale, PrintAttributes properties)
|
462 |
throws ReadException {
|
463 |
throw new RuntimeException("No deberia pasar por aqui"); |
464 |
} |
465 |
|
466 |
public void print_old(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
467 |
double scale, PrintAttributes properties)
|
468 |
throws ReadException {
|
469 |
this.print_old(g, viewPort, cancel, scale, properties, null); |
470 |
} |
471 |
|
472 |
/**
|
473 |
* <p>Checks all layers (each one as a sub-node of this node <i>collection of layers</i>) of this collection and draws their requested properties. If a node is
|
474 |
* a group of layers (<code>ComposedLayer</code>), executes it's drawn.</p>
|
475 |
*
|
476 |
* <p>All nodes which could group with the composed layer <code>group</code>, will be drawn together. And once the <code>
|
477 |
* group</code> is drawn, will be set to <code>null</code> if hasn't a parent layer.</p>
|
478 |
*
|
479 |
* <p>The particular implementation depends on the kind of each layer and composed layer. And this process can be cancelled at any
|
480 |
* time by the shared object <code>cancel</code>.</p>
|
481 |
*
|
482 |
* <p>According the print quality, labels will be printed in different resolution:
|
483 |
* <ul>
|
484 |
* <li><b>PrintQuality.DRAFT</b>: 72 dpi (dots per inch).</li>
|
485 |
* <li><b>PrintQuality.NORMAL</b>: 300 dpi (dots per inch).</li>
|
486 |
* <li><b>PrintQuality.HIGH</b>: 600 dpi (dots per inch).</li>
|
487 |
* </ul>
|
488 |
* </p>
|
489 |
*
|
490 |
* @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
|
491 |
* @param viewPort the information for drawing the layers
|
492 |
* @param cancel shared object that determines if this layer can continue being drawn
|
493 |
* @param scale the scale of the view. Must be between {@linkplain FLayer#getMinScale()} and {@linkplain FLayer#getMaxScale()}.
|
494 |
* @param properties properties that will be print
|
495 |
* @param group a composed layer pending to paint; if this parameter is <code>null</code>, the composed layer
|
496 |
*
|
497 |
* @return <code>null</code> if the layers in <code>group</code> had been drawn or were <code>null</code>; otherwise, the <code>group</code>
|
498 |
*
|
499 |
* @see FLayer#print(Graphics2D, ViewPort, Cancellable, double, PrintAttributes)
|
500 |
*
|
501 |
* @throws ReadDriverException if fails the driver reading the data.
|
502 |
*/
|
503 |
public ComposedLayer print_old(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintAttributes properties, ComposedLayer group) |
504 |
throws ReadException {
|
505 |
double dpi = 72; |
506 |
|
507 |
int resolution = properties.getPrintQuality();
|
508 |
if (resolution == PrintAttributes.PRINT_QUALITY_NORMAL) {
|
509 |
dpi = 300;
|
510 |
} else if (resolution == PrintAttributes.PRINT_QUALITY_HIGH){ |
511 |
dpi = 600;
|
512 |
} else if (resolution == PrintAttributes.PRINT_QUALITY_DRAFT){ |
513 |
dpi = 72;
|
514 |
} |
515 |
|
516 |
// TODO: A la hora de imprimir, isWithinScale falla, porque est?
|
517 |
// calculando la escala en pantalla, no para el layout.
|
518 |
// Revisar esto.
|
519 |
|
520 |
// TODO: We have to check when we have to call the drawLabels method when exists a ComposedLayer group.
|
521 |
for (int i=0; i < layers.size(); i++) { |
522 |
FLayer lyr = (FLayer) layers.get(i); |
523 |
if (!lyr.isVisible() || !lyr.isWithinScale(scale)) {
|
524 |
continue;
|
525 |
} |
526 |
|
527 |
try{
|
528 |
|
529 |
///// CHEMA ComposedLayer
|
530 |
// Checks for draw group (ComposedLayer)
|
531 |
if (group != null) { |
532 |
if (lyr instanceof FLayers){ |
533 |
group = ((FLayers)lyr).print_old(g, viewPort, cancel,scale,properties,group); |
534 |
} else {
|
535 |
// If layer can be added to the group, does it
|
536 |
if (lyr instanceof ILabelable |
537 |
&& ((ILabelable) lyr).isLabeled() |
538 |
&& ((ILabelable) lyr).getLabelingStrategy() != null
|
539 |
&& ((ILabelable) lyr).getLabelingStrategy().shouldDrawLabels(scale)) { |
540 |
group.add(lyr); |
541 |
} else {
|
542 |
// draw the 'pending to draw' layer group
|
543 |
group.print(g,viewPort,cancel,scale,properties); |
544 |
|
545 |
// gets a new group instance
|
546 |
if (lyr instanceof ILabelable |
547 |
&& ((ILabelable) lyr).isLabeled() |
548 |
&& ((ILabelable) lyr).getLabelingStrategy() != null
|
549 |
&& ((ILabelable) lyr).getLabelingStrategy().shouldDrawLabels(scale)) { |
550 |
group = lyr.newComposedLayer(); |
551 |
} else {
|
552 |
group = null;
|
553 |
} |
554 |
// if layer hasn't group, draws it inmediately
|
555 |
if (group == null) { |
556 |
if (lyr instanceof FLayers){ |
557 |
group = ((FLayers)lyr).print_old(g, viewPort, cancel,scale,properties,group); |
558 |
} else {
|
559 |
lyr.print(g, viewPort, cancel,scale,properties); |
560 |
if (lyr instanceof ILabelable |
561 |
&& ((ILabelable) lyr).isLabeled() |
562 |
&& ((ILabelable) lyr).getLabelingStrategy() != null
|
563 |
&& ((ILabelable) lyr).getLabelingStrategy().shouldDrawLabels(scale)) { |
564 |
ILabelable lLayer = (ILabelable) lyr; |
565 |
lLayer.drawLabels(null, g, viewPort, cancel, scale, dpi);
|
566 |
} |
567 |
} |
568 |
} else {
|
569 |
// add the layer to the group
|
570 |
group.setMapContext(fmap); |
571 |
group.add(lyr); |
572 |
|
573 |
} |
574 |
|
575 |
} |
576 |
} |
577 |
} else {
|
578 |
// gets a new group instance
|
579 |
group = lyr.newComposedLayer(); |
580 |
// if layer hasn't group, draws it inmediately
|
581 |
if (group == null) { |
582 |
if (lyr instanceof FLayers){ |
583 |
group = ((FLayers)lyr).print_old(g, viewPort, cancel,scale,properties,group); |
584 |
} else {
|
585 |
lyr.print(g, viewPort, cancel,scale,properties); |
586 |
if (lyr instanceof ILabelable && ((ILabelable) lyr).isLabeled()) { |
587 |
ILabelable lLayer = (ILabelable) lyr; |
588 |
|
589 |
lLayer.drawLabels(null, g, viewPort, cancel, scale, dpi);
|
590 |
} |
591 |
} |
592 |
} else {
|
593 |
// add the layer to the group
|
594 |
group.setMapContext(fmap); |
595 |
group.add(lyr); |
596 |
|
597 |
} |
598 |
} |
599 |
///// CHEMA ComposedLayer
|
600 |
|
601 |
} catch (Exception e){ |
602 |
String mesg = Messages.getString("error_printing_layer")+" "+ lyr.getName() + ": " + e.getMessage(); |
603 |
fmap.addLayerError(mesg); |
604 |
logger.error(mesg, e); |
605 |
} |
606 |
|
607 |
} |
608 |
|
609 |
///// CHEMA ComposedLayer
|
610 |
if (group != null && this.getParentLayer() == null) { |
611 |
//si tenemos un grupo pendiente de pintar, pintamos
|
612 |
group.print(g, viewPort, cancel,scale,properties); |
613 |
group = null;
|
614 |
|
615 |
} |
616 |
///// CHEMA ComposedLayer
|
617 |
|
618 |
// if (getVirtualLayers() != null) {
|
619 |
// getVirtualLayers().print( g, viewPort, cancel, scale, properties);
|
620 |
// }
|
621 |
|
622 |
///// CHEMA ComposedLayer
|
623 |
return group;
|
624 |
///// CHEMA ComposedLayer
|
625 |
} |
626 |
|
627 |
/*
|
628 |
* (non-Javadoc)
|
629 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
630 |
*/
|
631 |
public Envelope getFullEnvelope() {
|
632 |
Envelope rAux = null;
|
633 |
boolean first = true; |
634 |
|
635 |
|
636 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
637 |
FLayer capa = (FLayer) iter.next(); |
638 |
try{
|
639 |
if (first) {
|
640 |
rAux = capa.getFullEnvelope(); |
641 |
first=false;
|
642 |
} else {
|
643 |
rAux.add(capa.getFullEnvelope()); |
644 |
} |
645 |
}catch (Exception e) { |
646 |
e.printStackTrace();//TODO hay que revisar para determinar el comportamiento que espera el usuario.
|
647 |
} |
648 |
} |
649 |
|
650 |
return rAux;
|
651 |
} |
652 |
|
653 |
/**
|
654 |
* Notifies all listeners associated to this collection of layers,
|
655 |
* that another layer is going to be added or replaced in the internal
|
656 |
* list of layers.
|
657 |
*
|
658 |
* @param e a layer collection event with the new layer
|
659 |
*/
|
660 |
protected void callLayerAdding(LayerCollectionEvent event) |
661 |
throws CancelationException {
|
662 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
663 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
664 |
((LayerCollectionListener) iter.next()).layerAdding(event); |
665 |
} |
666 |
} |
667 |
|
668 |
/**
|
669 |
* Notifies all listeners associated to this collection of layers,
|
670 |
* that a layer is going to be removed from the internal list of layers.
|
671 |
*
|
672 |
* @param event a layer collection event with the layer being removed
|
673 |
*
|
674 |
* @throws CancelationException any exception produced during the cancellation of the driver.
|
675 |
*/
|
676 |
protected void callLayerRemoving(LayerCollectionEvent event) |
677 |
throws CancelationException {
|
678 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
679 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
680 |
((LayerCollectionListener) iter.next()).layerRemoving(event); |
681 |
} |
682 |
} |
683 |
|
684 |
/**
|
685 |
* Notifies all listeners associated to this collection of layers,
|
686 |
* that a layer is going to be moved in the internal list of layers.
|
687 |
*
|
688 |
* @param event a layer collection event with the layer being moved, and the initial and final positions
|
689 |
*
|
690 |
* @throws CancelationException any exception produced during the cancellation of the driver.
|
691 |
*/
|
692 |
protected void callLayerMoving(LayerPositionEvent event) |
693 |
throws CancelationException {
|
694 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
695 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
696 |
((LayerCollectionListener) iter.next()).layerMoving(event); |
697 |
} |
698 |
} |
699 |
|
700 |
/**
|
701 |
* Notifies all listeners associated to this collection of layers,
|
702 |
* that another layer has been added or replaced in the internal
|
703 |
* list of layers.
|
704 |
*
|
705 |
* @param e a layer collection event with the new layer
|
706 |
*/
|
707 |
protected void callLayerAdded(LayerCollectionEvent event) { |
708 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
709 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
710 |
((LayerCollectionListener) iter.next()).layerAdded(event); |
711 |
} |
712 |
} |
713 |
|
714 |
/**
|
715 |
* Notifies all listeners associated to this collection of layers,
|
716 |
* that another layer has been removed from the internal list of layers.
|
717 |
*
|
718 |
* @param e a layer collection event with the layer removed
|
719 |
*/
|
720 |
protected void callLayerRemoved(LayerCollectionEvent event) { |
721 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
722 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
723 |
((LayerCollectionListener) iter.next()).layerRemoved(event); |
724 |
} |
725 |
} |
726 |
|
727 |
/**
|
728 |
* Notifies all listeners associated to this collection of layers,
|
729 |
* that another layer has been moved in the internal list of layers.
|
730 |
*
|
731 |
* @param e a layer collection event with the layer moved, and the initial and final positions
|
732 |
*/
|
733 |
protected void callLayerMoved(LayerPositionEvent event) { |
734 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
735 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
736 |
((LayerCollectionListener) iter.next()).layerMoved(event); |
737 |
} |
738 |
} |
739 |
|
740 |
public void saveToState(PersistentState state) throws PersistenceException { |
741 |
|
742 |
super.saveToState(state);
|
743 |
state.set("numLayers", layers.size());
|
744 |
state.set("layers", layers.iterator());
|
745 |
} |
746 |
|
747 |
public void loadFromState(PersistentState state) throws PersistenceException { |
748 |
|
749 |
super.loadFromState(state);
|
750 |
|
751 |
Iterator iter = state.getIterator("layers"); |
752 |
while (iter.hasNext()) {
|
753 |
FLayer item = (FLayer) iter.next(); |
754 |
layers.add(item); |
755 |
} |
756 |
|
757 |
} |
758 |
|
759 |
/*
|
760 |
* (non-Javadoc)
|
761 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getMapContext()
|
762 |
*/
|
763 |
public MapContext getMapContext() {
|
764 |
return fmap;
|
765 |
} |
766 |
/*
|
767 |
* (non-Javadoc)
|
768 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setCoordTrans(org.cresques.cts.ICoordTrans)
|
769 |
*/
|
770 |
public void setCoordTrans(ICoordTrans ct) { |
771 |
super.setCoordTrans(ct);
|
772 |
|
773 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
774 |
FLayer layer = (FLayer) iter.next(); |
775 |
layer.setCoordTrans(ct); |
776 |
} |
777 |
} |
778 |
/*
|
779 |
* (non-Javadoc)
|
780 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#setAllActives(boolean)
|
781 |
*/
|
782 |
public void setAllActives(boolean active) { |
783 |
FLayer lyr; |
784 |
|
785 |
for (int i = 0; i < layers.size(); i++) { |
786 |
lyr = ((FLayer) layers.get(i)); |
787 |
lyr.setActive(active); |
788 |
|
789 |
if (lyr instanceof LayerCollection) { |
790 |
((LayerCollection) lyr).setAllActives(active); |
791 |
} |
792 |
} |
793 |
} |
794 |
|
795 |
/*
|
796 |
* (non-Javadoc)
|
797 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getActives()
|
798 |
*/
|
799 |
public FLayer[] getActives() { |
800 |
ArrayList ret = new ArrayList(); |
801 |
LayersIterator it = new LayersIterator(this) { |
802 |
|
803 |
public boolean evaluate(FLayer layer) { |
804 |
return layer.isActive();
|
805 |
} |
806 |
|
807 |
}; |
808 |
|
809 |
while (it.hasNext())
|
810 |
{ |
811 |
ret.add(it.next()); |
812 |
} |
813 |
return (FLayer[]) ret.toArray(new FLayer[0]); |
814 |
} |
815 |
|
816 |
/*
|
817 |
* (non-Javadoc)
|
818 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getMinScale()
|
819 |
*/
|
820 |
public double getMinScale() { |
821 |
return -1; // La visibilidad o no la controla cada capa |
822 |
// dentro de una colecci?n
|
823 |
} |
824 |
/*
|
825 |
* (non-Javadoc)
|
826 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getMaxScale()
|
827 |
*/
|
828 |
public double getMaxScale() { |
829 |
return -1; |
830 |
} |
831 |
/*
|
832 |
* (non-Javadoc)
|
833 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setMinScale(double)
|
834 |
*/
|
835 |
public void setMinScale(double minScale) |
836 |
{ |
837 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
838 |
FLayer lyr = (FLayer) iter.next(); |
839 |
lyr.setMinScale(minScale); |
840 |
} |
841 |
} |
842 |
/*
|
843 |
* (non-Javadoc)
|
844 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setMaxScale(double)
|
845 |
*/
|
846 |
public void setMaxScale(double maxScale) |
847 |
{ |
848 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
849 |
FLayer lyr = (FLayer) iter.next(); |
850 |
lyr.setMinScale(maxScale); |
851 |
} |
852 |
} |
853 |
/*
|
854 |
* (non-Javadoc)
|
855 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setActive(boolean)
|
856 |
*/
|
857 |
public void setActive(boolean b){ |
858 |
super.setActive(b);
|
859 |
for (int i=0;i<layers.size();i++){ |
860 |
((FLayer)layers.get(i)).setActive(b); |
861 |
} |
862 |
} |
863 |
/* (non-Javadoc)
|
864 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#addLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
|
865 |
*/
|
866 |
public boolean addLayerListener(LayerListener o) { |
867 |
for (int i = 0; i < layers.size(); i++) { |
868 |
((FLayer) layers.get(i)).addLayerListener(o); |
869 |
} |
870 |
return true; |
871 |
} |
872 |
/*
|
873 |
* (non-Javadoc)
|
874 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#getInfo(java.awt.Point, double, com.iver.utiles.swing.threads.Cancellable)
|
875 |
*/
|
876 |
// public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws LoadLayerException, DataException {
|
877 |
// int i;
|
878 |
// Vector items = new Vector();
|
879 |
// FLayer layer;
|
880 |
// XMLItem[] aux;
|
881 |
// for (i = 0; i < this.layers.size(); i++){
|
882 |
// layer = (FLayer)layers.get(i);
|
883 |
// if (layer instanceof InfoByPoint){
|
884 |
// InfoByPoint queryable_layer = (InfoByPoint) layer;
|
885 |
// aux = queryable_layer.getInfo(p, tolerance, null);
|
886 |
// if (!(queryable_layer instanceof FLayers)){
|
887 |
// for(int j = 0; j < aux.length; j++){
|
888 |
// items.add(aux[j]);
|
889 |
// }
|
890 |
// }
|
891 |
// }
|
892 |
// }
|
893 |
// return (XMLItem[])items.toArray(new XMLItem[0]);
|
894 |
//
|
895 |
// }
|
896 |
public Iterator getInfo(Point p, double tolerance, |
897 |
Cancellable cancel) throws LoadLayerException, DataException {
|
898 |
int i;
|
899 |
FLayer layer; |
900 |
ArrayList res = new ArrayList(); |
901 |
for (i = 0; i < this.layers.size(); i++){ |
902 |
layer = (FLayer)layers.get(i); |
903 |
if (layer instanceof InfoByPoint){ |
904 |
InfoByPoint queryable_layer = (InfoByPoint) layer; |
905 |
Iterator it = queryable_layer.getInfo(p, tolerance, null); |
906 |
// Please be careful we add iterators, not the Dynobjects
|
907 |
// we don't make the list flat so trees are supported
|
908 |
res.add(it); |
909 |
} |
910 |
} |
911 |
return res.iterator();
|
912 |
|
913 |
} |
914 |
|
915 |
|
916 |
/*
|
917 |
* (non-Javadoc)
|
918 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getTocImageIcon()
|
919 |
*/
|
920 |
public String getTocImageIcon() { |
921 |
return "toc-layer-group"; |
922 |
} |
923 |
|
924 |
/**
|
925 |
* <p>Adds the layer with the information in an XML entity and the specified name, to this collection of layers. And
|
926 |
* returns <code>true</code> if there hasn't been errors.</p>
|
927 |
*
|
928 |
* @see CopyOfFLayers#addLayerFromXML(XMLEntity, String)
|
929 |
*
|
930 |
* @param xml tree-node structure with information about layers
|
931 |
* @param name name of the layer to add
|
932 |
* @return <code>true</code> if there were no errors adding the layer, <code>false</code> otherwise
|
933 |
*
|
934 |
* @throws LoadLayerException if fails loading this layer.
|
935 |
*/
|
936 |
// public boolean addLayerFromXMLEntity(XMLEntity xml, String name) throws LoadLayerException {
|
937 |
// fmap.clearErrors();
|
938 |
// this.addLayerFromXML(xml,name);
|
939 |
//
|
940 |
// return (fmap.getLayersError().size() == 0);
|
941 |
//
|
942 |
// }
|
943 |
|
944 |
// /**
|
945 |
// * <p>Adds the layer with the information in an XML entity and the specified name, to this collection of layers.</p>
|
946 |
// *
|
947 |
// * <p>This method really executes the addition, considering the kind of layer (<code>FLyrVect</code>,
|
948 |
// * <code>FLyrAnnotation</code>, <code>FLyrRaster</code>, a collection of layers (<code>FLayers</code>),
|
949 |
// * or another kind of layer (<code>FLayer</code>)), and the driver in the layer.</p>
|
950 |
// *
|
951 |
// * @param xml tree-node structure with information about layers
|
952 |
// * @param name name of the layer to add
|
953 |
// *
|
954 |
// * @throws LoadLayerException if fails loading this layer.
|
955 |
// */
|
956 |
// private void addLayerFromXML(XMLEntity xml, String name) throws LoadLayerException {
|
957 |
// FLayer layer = null;
|
958 |
//
|
959 |
// try {
|
960 |
// if (name == null) {
|
961 |
// name = xml.getName();
|
962 |
// }
|
963 |
//
|
964 |
//
|
965 |
// String className = xml.getStringProperty("className");
|
966 |
// Class clase = Class.forName(className);
|
967 |
// layer = (FLayer) clase.newInstance();
|
968 |
// if (FLayers.class.isAssignableFrom(clase)) {
|
969 |
// ((FLayers)layer).setMapContext(getMapContext());
|
970 |
// ((FLayers)layer).setParentLayer(this);
|
971 |
// // layer = new FLayers(getMapContext(),this);
|
972 |
// layer.setXMLEntity(xml);
|
973 |
// } else {
|
974 |
// // Capas Nuevas (externas)
|
975 |
// layer.setName(name);
|
976 |
// layer.setXMLEntity(xml);
|
977 |
// layer.load();
|
978 |
// }
|
979 |
//
|
980 |
// // //TODO VCN FLyrAnnotation es un parche para no tener que duplicar todo el c?digo de aq? y de los diferentes m?todos de LayerFactory,
|
981 |
// // //ya que los drivers de una FLyrAnnotation no sabemos cual es puede ser cualquier Driver Vectorial.
|
982 |
// // if (className.equals(FLyrVect.class.getName())){// || className.equals(FLyrAnnotation.class.getName())) {
|
983 |
// // String type = xml.getStringProperty("type");
|
984 |
// // if ("vectorial".equals(type)){
|
985 |
// // //String recordsetName = xml.getChild(i).getStringProperty("recordset-name");
|
986 |
// // IProjection proj = null;
|
987 |
// // if (xml.contains("proj")) {
|
988 |
// // proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
|
989 |
// // }
|
990 |
// // else
|
991 |
// // {
|
992 |
// // proj = this.getMapContext().getViewPort().getProjection();
|
993 |
// // }
|
994 |
// // if (xml.contains("file")) {
|
995 |
// // Driver d;
|
996 |
// // try {
|
997 |
// // d = LayerFactory.getDM().getDriver(xml.getStringProperty("driverName"));
|
998 |
// // } catch (DriverLoadException e1) {
|
999 |
// // throw new DriverLayerException(name,e1);
|
1000 |
// // }
|
1001 |
// // layer = LayerFactory.createLayer(name, (VectorialFileDriver) d,
|
1002 |
// // new File(xml.getStringProperty("file")),
|
1003 |
// // proj);
|
1004 |
// //
|
1005 |
// //
|
1006 |
// // }
|
1007 |
// // if (xml.contains("db")) {
|
1008 |
// //
|
1009 |
// // String driverName = xml.getStringProperty("db");
|
1010 |
// // IVectorialDatabaseDriver driver;
|
1011 |
// // try {
|
1012 |
// // driver = (IVectorialDatabaseDriver) LayerFactory.getDM().getDriver(driverName);
|
1013 |
// // //Hay que separar la carga de los datos del XMLEntity del load.
|
1014 |
// // driver.setXMLEntity(xml.getChild(2));
|
1015 |
// //
|
1016 |
// // boolean loadOk = false;
|
1017 |
// // ((DefaultJDBCDriver)driver).load();
|
1018 |
// // if (((DefaultJDBCDriver)driver).getConnection() != null) {
|
1019 |
// // loadOk = true;
|
1020 |
// // }
|
1021 |
// // layer = LayerFactory.createDBLayer(driver, name, proj);
|
1022 |
// // if (!loadOk) {
|
1023 |
// // layer.setAvailable(false);
|
1024 |
// // }
|
1025 |
// //
|
1026 |
// // } catch (DriverLoadException e) {
|
1027 |
// // throw new DriverLayerException(name,e);
|
1028 |
// // } catch (XMLException e) {
|
1029 |
// // throw new DriverLayerException(name,e);
|
1030 |
// // } catch (ReadException e) {
|
1031 |
// // throw new DriverLayerException(name,e);
|
1032 |
// // }
|
1033 |
// //
|
1034 |
// // }
|
1035 |
// // // Clases con algun driver gen?rico creado por otro
|
1036 |
// // // programador
|
1037 |
// // if (xml.contains("other")) {
|
1038 |
// //
|
1039 |
// // String driverName = xml.getStringProperty("other");
|
1040 |
// // VectorialDriver driver = null;
|
1041 |
// // try {
|
1042 |
// // driver = (VectorialDriver) LayerFactory.getDM().getDriver(driverName);
|
1043 |
// // } catch (DriverLoadException e) {
|
1044 |
// // // Si no existe ese driver, no pasa nada.
|
1045 |
// // // Puede que el desarrollador no quiera que
|
1046 |
// // // aparezca en el cuadro de di?logo y ha metido
|
1047 |
// // // el jar con sus clases en nuestro directorio lib.
|
1048 |
// // // Intentamos cargar esa clase "a pelo".
|
1049 |
// // if (xml.getChild(2).contains("className"))
|
1050 |
// // {
|
1051 |
// // String className2 = xml.getChild(2).getStringProperty("className");
|
1052 |
// // try {
|
1053 |
// // driver = (VectorialDriver) Class.forName(className2).newInstance();
|
1054 |
// // } catch (Exception e1) {
|
1055 |
// // throw new DriverLayerException(name,e);
|
1056 |
// // }
|
1057 |
// // }
|
1058 |
// // } catch (NullPointerException npe) {
|
1059 |
// // // Si no existe ese driver, no pasa nada.
|
1060 |
// // // Puede que el desarrollador no quiera que
|
1061 |
// // // aparezca en el cuadro de di?logo y ha metido
|
1062 |
// // // el jar con sus clases en nuestro directorio lib.
|
1063 |
// // // Intentamos cargar esa clase "a pelo".
|
1064 |
// // if (xml.getChild(2).contains("className"))
|
1065 |
// // {
|
1066 |
// // String className2 = xml.getChild(2).getStringProperty("className");
|
1067 |
// // try {
|
1068 |
// // driver = (VectorialDriver) Class.forName(className2).newInstance();
|
1069 |
// // } catch (Exception e1) {
|
1070 |
// // throw new DriverLayerException(name,e1);
|
1071 |
// // }
|
1072 |
// // }
|
1073 |
// // }
|
1074 |
// // if (driver instanceof IPersistence)
|
1075 |
// // {
|
1076 |
// // IPersistence persist = (IPersistence) driver;
|
1077 |
// // persist.setXMLEntity(xml.getChild(2));
|
1078 |
// // }
|
1079 |
// // layer = LayerFactory.createLayer(name, driver, proj);
|
1080 |
// // }
|
1081 |
// //
|
1082 |
// // }
|
1083 |
// //
|
1084 |
// // //TODO VCN FLyrAnnotation es un parche para no tener que duplicar todo el c?digo de aq? y de los diferentes m?todos de LayerFactory,
|
1085 |
// // //ya que los drivers de una FLyrAnnotation no sabemos cual es puede ser cualquier Driver Vectorial.
|
1086 |
// // if (className.equals(FLyrAnnotation.class.getName())){
|
1087 |
// // layer=FLyrAnnotation.createLayerFromVect((FLyrVect)layer);
|
1088 |
// // }
|
1089 |
// //
|
1090 |
// //
|
1091 |
// // layer.setXMLEntity(xml);
|
1092 |
// //
|
1093 |
// // } else {
|
1094 |
// // Class clase = LayerFactory.getLayerClassForLayerClassName(className);
|
1095 |
// // layer = (FLayer) clase.newInstance();
|
1096 |
// // if (clase.isAssignableFrom(FLayers.class)) {
|
1097 |
// // ((FLayers)layer).setMapContext(getMapContext());
|
1098 |
// // ((FLayers)layer).setParentLayer(this);
|
1099 |
// //// layer = new FLayers(getMapContext(),this);
|
1100 |
// // layer.setXMLEntity(xml);
|
1101 |
// // } else {
|
1102 |
// // // Capas Nuevas (externas)
|
1103 |
// // layer.setName(name);
|
1104 |
// // layer.setXMLEntity(xml);
|
1105 |
// // layer.load();
|
1106 |
// // }
|
1107 |
// // }
|
1108 |
// this.addLayer(layer);
|
1109 |
// logger.debug("layer: "+ layer.getName() +" loaded");
|
1110 |
// // Comprobar que la proyecci?n es la misma que la de FMap
|
1111 |
// // Si no lo es, es una capa que est? reproyectada al vuelo
|
1112 |
// IProjection proj = layer.getProjection();
|
1113 |
// if ((proj != null)) {
|
1114 |
// if (!proj.getFullCode().equals(getMapContext().getProjection().getFullCode()))
|
1115 |
// {
|
1116 |
// ICoordTrans ct = proj.getCT(getMapContext().getProjection());
|
1117 |
// // TODO: REVISAR CON LUIS
|
1118 |
// // Se lo fijamos a todas, luego cada una que se reproyecte
|
1119 |
// // si puede, o que no haga nada
|
1120 |
//
|
1121 |
// layer.setCoordTrans(ct);
|
1122 |
// }
|
1123 |
// }
|
1124 |
// } catch (XMLException e) {
|
1125 |
// fmap.addLayerError(xml.getStringProperty("name"));
|
1126 |
// throw new LoadLayerException(name,e);
|
1127 |
// } catch (ClassNotFoundException e) {
|
1128 |
// fmap.addLayerError(xml.getStringProperty("name"));
|
1129 |
// throw new LoadLayerException(name,e);
|
1130 |
// } catch (InstantiationException e) {
|
1131 |
// fmap.addLayerError(xml.getStringProperty("name"));
|
1132 |
// throw new LoadLayerException(name,e);
|
1133 |
// } catch (IllegalAccessException e) {
|
1134 |
// fmap.addLayerError(xml.getStringProperty("name"));
|
1135 |
// throw new LoadLayerException(name,e);
|
1136 |
// } catch (LoadLayerException e){
|
1137 |
// fmap.addLayerError(xml.getStringProperty("name"));
|
1138 |
// throw e;
|
1139 |
// }
|
1140 |
// }
|
1141 |
|
1142 |
/**
|
1143 |
* <p>Sets the <code>MapContext</code> that contains this layer node.</p>
|
1144 |
*
|
1145 |
* @param mapContext the <code>MapContext</code> that contains this layer node
|
1146 |
*/
|
1147 |
public void setMapContext(MapContext mapContext) { |
1148 |
this.fmap = mapContext;
|
1149 |
} |
1150 |
|
1151 |
// /**
|
1152 |
// * <p>Creates a new layer of the same class as the property <i>className</i> of the XML, after, adds the XML entity to that layer
|
1153 |
// * and loads the layer. Then, adds the layer to this collection of layers, and if there is a projection defined,
|
1154 |
// * inserts the transformation coordinates to the layer.</p>
|
1155 |
// *
|
1156 |
// * <p>If the new layer is an instance of <code>FLyrVect</code>, and has a label field, creates a label layer on the layer.</p>
|
1157 |
// *
|
1158 |
// * @param xml tree-node structure with information about layers
|
1159 |
// * @param name name of the layer to add
|
1160 |
// */
|
1161 |
// private void addLayerFromXMLNew(XMLEntity xml, String name) {
|
1162 |
// // FLayer layer = null;
|
1163 |
// //
|
1164 |
// //
|
1165 |
// // try {
|
1166 |
// // String className = xml.getStringProperty("className");
|
1167 |
// // Class clazz = Class.forName(className);
|
1168 |
// // if (clazz.isAssignableFrom(FLayers.class)) {
|
1169 |
// // layer = (FLayer) clazz.newInstance();
|
1170 |
// // ((FLayers)layer).setMapContext(getMapContext());
|
1171 |
// // ((FLayers)layer).setParentLayer(this);
|
1172 |
// // // if (className.equals((FLayers.class.getName()))){
|
1173 |
// // // layer = new FLayers(getMapContext(),this);
|
1174 |
// // } else {
|
1175 |
// // // Por compatibilidad
|
1176 |
// // if (className.equals(FLyrVect.class.getName())) {
|
1177 |
// // if (xml.contains("file")) {
|
1178 |
// // layer = new FLayerFileVectorial();
|
1179 |
// // } else if (xml.contains("db")) {
|
1180 |
// // try {
|
1181 |
// // layer = (FLayer)((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create("com.iver.cit.gvsig.fmap.layers.FLayerJDBCVectorial");
|
1182 |
// // } catch (Exception e) {
|
1183 |
// // throw new XMLException(new Exception("No se tiene registrada la capa de tipo JDBC"));
|
1184 |
// // }
|
1185 |
// // //className = FLayerJDBCVectorial.class.getName();
|
1186 |
// // } else if (xml.contains("other")){
|
1187 |
// // layer = new FLayerGenericVectorial();
|
1188 |
// // } else {
|
1189 |
// // throw new XMLException(new Exception("Capa vectorial de tipo no reconocido"));
|
1190 |
// // }
|
1191 |
// // // Fin por compatibilidad
|
1192 |
// // } else {
|
1193 |
// // try {
|
1194 |
// // layer = (FLayer)(((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create(className));
|
1195 |
// // } catch (Exception e) {
|
1196 |
// // //puende que no este registrada como punto de extension
|
1197 |
// // Class clase = Class.forName(className);
|
1198 |
// // layer = (FLayer) clase.newInstance();
|
1199 |
// // // FIXME: Hacemos algo aqui o dejamos que suba el error?
|
1200 |
// // }
|
1201 |
// // }
|
1202 |
// //
|
1203 |
// // }
|
1204 |
// // layer.setXMLEntity(xml);
|
1205 |
// // if (name != null) layer.setName(name);
|
1206 |
// // layer.load();
|
1207 |
// //
|
1208 |
// // this.addLayer(layer);
|
1209 |
// // logger.debug("layer: "+ layer.getName() +" loaded");
|
1210 |
// // // Comprobar que la proyecci?n es la misma que la de FMap
|
1211 |
// // // Si no lo es, es una capa que est? reproyectada al vuelo
|
1212 |
// // IProjection proj = layer.getProjection();
|
1213 |
// // if ((proj != null))
|
1214 |
// // if (proj != getMapContext().getProjection())
|
1215 |
// // {
|
1216 |
// // ICoordTrans ct = proj.getCT(getMapContext().getProjection());
|
1217 |
// // // TODO: REVISAR CON LUIS
|
1218 |
// // // Se lo fijamos a todas, luego cada una que se reproyecte
|
1219 |
// // // si puede, o que no haga nada
|
1220 |
// // layer.setCoordTrans(ct);
|
1221 |
// //
|
1222 |
// // }
|
1223 |
// // }catch (Exception e) {
|
1224 |
// // fmap.addLayerError(xml.getStringProperty("name"));
|
1225 |
// // logger.debug(Messages.getString("could_not_load_layer")+": "+xml.getStringProperty("name") + ".\n"
|
1226 |
// // +Messages.getString("reason")+":", e);
|
1227 |
// // }
|
1228 |
// }
|
1229 |
|
1230 |
public void accept(Visitor visitor) throws BaseException { |
1231 |
throw new NotSupportedOperationException(visitor, this); |
1232 |
} |
1233 |
|
1234 |
public void accept(LayersVisitor visitor) throws BaseException { |
1235 |
for (int i = 0; i < this.getLayersCount(); i++) { |
1236 |
FLayer layer = this.getLayer(i);
|
1237 |
if (layer instanceof LayersVisitable) { |
1238 |
((LayersVisitable) layer).accept(visitor); |
1239 |
} else {
|
1240 |
visitor.visit(layer); |
1241 |
} |
1242 |
} |
1243 |
} |
1244 |
|
1245 |
/*
|
1246 |
* (non-Javadoc)
|
1247 |
*
|
1248 |
* @see org.gvsig.metadata.Metadata#getMetadataID()
|
1249 |
*/
|
1250 |
public Object getMetadataID() { |
1251 |
StringBuffer strb = new StringBuffer(); |
1252 |
strb.append("Layers(");
|
1253 |
strb.append(this.getName());
|
1254 |
strb.append("):{");
|
1255 |
Iterator iter = this.layers.iterator(); |
1256 |
while (iter.hasNext()) {
|
1257 |
strb.append(((FLayer) iter.next()).getMetadataID()); |
1258 |
strb.append(",");
|
1259 |
} |
1260 |
strb.append("}");
|
1261 |
return strb.toString();
|
1262 |
|
1263 |
} |
1264 |
|
1265 |
/*
|
1266 |
* (non-Javadoc)
|
1267 |
*
|
1268 |
* @see org.gvsig.metadata.Metadata#getMetadataChildren()
|
1269 |
*/
|
1270 |
public Set getMetadataChildren() { |
1271 |
Set ret = new TreeSet(); |
1272 |
Iterator iter = this.layers.iterator(); |
1273 |
while (iter.hasNext()) {
|
1274 |
ret.add(iter.next()); |
1275 |
} |
1276 |
return ret;
|
1277 |
} |
1278 |
|
1279 |
/*
|
1280 |
* (non-Javadoc)
|
1281 |
*
|
1282 |
* @see org.gvsig.metadata.Metadata#getMetadataName()
|
1283 |
*/
|
1284 |
public String getMetadataName() { |
1285 |
StringBuffer strb = new StringBuffer(); |
1286 |
strb.append("Layer Group '");
|
1287 |
strb.append(this.getName());
|
1288 |
strb.append("': {");
|
1289 |
Iterator iter = this.layers.iterator(); |
1290 |
while (iter.hasNext()) {
|
1291 |
strb.append(((FLayer) iter.next()).getMetadataName()); |
1292 |
strb.append(",");
|
1293 |
} |
1294 |
strb.append("}");
|
1295 |
return strb.toString();
|
1296 |
} |
1297 |
|
1298 |
|
1299 |
public void beginDraw(Graphics2D g, ViewPort viewPort) { |
1300 |
LayerDrawEvent beforeEvent = new LayerDrawEvent(this, g, viewPort, LayerDrawEvent.LAYER_BEFORE_DRAW); |
1301 |
fmap.fireLayerDrawingEvent(beforeEvent); |
1302 |
} |
1303 |
|
1304 |
public void endDraw(Graphics2D g, ViewPort viewPort) { |
1305 |
LayerDrawEvent afterEvent = new LayerDrawEvent(this, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW); |
1306 |
fmap.fireLayerDrawingEvent(afterEvent); |
1307 |
} |
1308 |
|
1309 |
public static void registerPersistent() { |
1310 |
|
1311 |
DynObjectManager dynMan = ToolsLocator.getDynObjectManager(); |
1312 |
DynClass dynClass = dynMan.createDynClass( |
1313 |
"FLayers_Persistent",
|
1314 |
"FLayers Persistent definition");
|
1315 |
|
1316 |
FLyrDefault.registerPersistent(); |
1317 |
dynClass.extend("FLyrDefault_Persistent");
|
1318 |
|
1319 |
dynClass.addDynFieldSingle("numLayers", DataTypes.INT, null, true, true); |
1320 |
dynClass.addDynFieldSingle("layers", DataTypes.LIST, null, true, true); |
1321 |
dynMan.add(dynClass); |
1322 |
|
1323 |
ToolsLocator.getPersistenceManager().registerClass(FLayers.class, dynClass); |
1324 |
} |
1325 |
|
1326 |
} |