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