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