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