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