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