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