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