svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLayers.java @ 373
History | View | Annotate | Download (11.5 KB)
1 | 214 | fernando | /* Generated by Together */
|
---|---|---|---|
2 | package com.iver.cit.gvsig.fmap.layers; |
||
3 | |||
4 | 287 | vcaballero | import com.iver.cit.gvsig.fmap.ViewPort; |
5 | import com.iver.cit.gvsig.fmap.XMLEntity; |
||
6 | 305 | fjp | import com.iver.cit.gvsig.fmap.core.IGeometry; |
7 | 287 | vcaballero | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
8 | import com.iver.cit.gvsig.fmap.operations.Cancellable; |
||
9 | import com.iver.cit.gvsig.fmap.operations.QueriedPoint; |
||
10 | 214 | fernando | |
11 | 353 | fernando | import org.cresques.cts.ICoordTrans; |
12 | import org.cresques.cts.IProjection; |
||
13 | |||
14 | 296 | fernando | import java.awt.Graphics2D; |
15 | import java.awt.geom.Rectangle2D; |
||
16 | import java.awt.image.BufferedImage; |
||
17 | 287 | vcaballero | |
18 | 296 | fernando | import java.util.ArrayList; |
19 | import java.util.Iterator; |
||
20 | |||
21 | |||
22 | 214 | fernando | /**
|
23 | * Representa un nodo interno en el ?rbol de capas
|
||
24 | */
|
||
25 | 228 | fernando | public class FLayers extends FLyrDefault implements FLayer { |
26 | 247 | vcaballero | //ArrayList de Listener registrados.
|
27 | 257 | vcaballero | private ArrayList layerListeners = new ArrayList(); |
28 | 242 | vcaballero | private ArrayList layers = new ArrayList(4); |
29 | 214 | fernando | |
30 | 257 | vcaballero | /**
|
31 | * Crea un nuevo FLayers.
|
||
32 | */
|
||
33 | public FLayers() {
|
||
34 | setRoot(this);
|
||
35 | 247 | vcaballero | } |
36 | 257 | vcaballero | |
37 | 242 | vcaballero | /**
|
38 | * A?ade un listener de los eventos de la colecci?n de capas
|
||
39 | *
|
||
40 | * @param listener DOCUMENT ME!
|
||
41 | */
|
||
42 | public void addLayerCollectionListener(LayerCollectionListener listener) { |
||
43 | 257 | vcaballero | layerListeners.add(listener); |
44 | 242 | vcaballero | } |
45 | 214 | fernando | |
46 | 242 | vcaballero | /**
|
47 | * ELimina un listener de los eventos de la colecci?n de capas
|
||
48 | *
|
||
49 | * @param listener DOCUMENT ME!
|
||
50 | */
|
||
51 | public void removeLayerCollectionListener(LayerCollectionListener listener) { |
||
52 | 257 | vcaballero | layerListeners.remove(listener); |
53 | 242 | vcaballero | } |
54 | 214 | fernando | |
55 | 353 | fernando | private void doAddLayer(LayerPath parent, FLayer layer){ |
56 | if (parent.isEmpty()) {
|
||
57 | LayerPath nuevo = new LayerPath(getLayerPath(), layers.size());
|
||
58 | layer.setLayerPath(nuevo); |
||
59 | layer.setRoot(this.getRoot());
|
||
60 | layers.add(layer); |
||
61 | } else {
|
||
62 | int index = parent.popIndex();
|
||
63 | if (layers.get(index) instanceof FLayers) { |
||
64 | ((FLayers) layers.get(index)).doAddLayer(parent, layer); |
||
65 | } else {
|
||
66 | throw new ChildrenNotAllowedException(); |
||
67 | } |
||
68 | } |
||
69 | } |
||
70 | |||
71 | 242 | vcaballero | /**
|
72 | * A?ade una capa en el arbol en la posici?n indicada por el path que se
|
||
73 | * pasa como par?metro
|
||
74 | *
|
||
75 | * @param parent DOCUMENT ME!
|
||
76 | * @param layer DOCUMENT ME!
|
||
77 | 353 | fernando | * @param proj DOCUMENT ME!
|
78 | 242 | vcaballero | *
|
79 | * @throws ChildrenNotAllowedException
|
||
80 | 270 | vcaballero | * @throws ProjectionMismatchException DOCUMENT ME!
|
81 | 346 | fernando | * @throws CancelationException
|
82 | 242 | vcaballero | */
|
83 | public void addLayer(LayerPath parent, FLayer layer) |
||
84 | 353 | fernando | throws ChildrenNotAllowedException, ProjectionMismatchException,
|
85 | CancelationException { |
||
86 | |||
87 | LayerCollectionEvent event = new LayerCollectionEvent(layer);
|
||
88 | 346 | fernando | |
89 | 353 | fernando | callLayerAdding(event); |
90 | |||
91 | doAddLayer(parent, layer); |
||
92 | |||
93 | callLayerAdded(event); |
||
94 | |||
95 | 242 | vcaballero | } |
96 | 214 | fernando | |
97 | 242 | vcaballero | /**
|
98 | * Mueve una capa de la posici?n from a la posici?n to.
|
||
99 | *
|
||
100 | * @param from DOCUMENT ME!
|
||
101 | * @param to DOCUMENT ME!
|
||
102 | 346 | fernando | *
|
103 | 342 | fjp | * @throws DriverIOException
|
104 | 346 | fernando | * @throws CancelationException
|
105 | 353 | fernando | * @throws RuntimeException DOCUMENT ME!
|
106 | 242 | vcaballero | */
|
107 | 353 | fernando | public void moveTo(LayerPath from, LayerPath to) |
108 | throws DriverIOException, CancelationException {
|
||
109 | 242 | vcaballero | FLayer layer = getLayer(from); |
110 | 257 | vcaballero | LayerPositionEvent event = new LayerPositionEvent(layer, from, to);
|
111 | 353 | fernando | callLayerMoving(event); |
112 | removeLayer(from); |
||
113 | doAddLayer(to, layer); |
||
114 | callLayerMoved(event); |
||
115 | } |
||
116 | 270 | vcaballero | |
117 | 353 | fernando | private void doRemoveLayer(LayerPath path) { |
118 | int i = path.popIndex();
|
||
119 | FLayer lyr = (FLayer) layers.get(i); |
||
120 | 346 | fernando | |
121 | 353 | fernando | if (path.isEmpty()) {
|
122 | layers.remove(i); |
||
123 | } else if (layers.get(i) instanceof FLayers) { |
||
124 | ((FLayers) lyr).doRemoveLayer(path); |
||
125 | } else {
|
||
126 | throw new ChildrenNotAllowedException(); |
||
127 | } |
||
128 | 242 | vcaballero | } |
129 | 353 | fernando | |
130 | 242 | vcaballero | /**
|
131 | * Elimina una capa por su path relativo a ?ste nodo
|
||
132 | *
|
||
133 | * @param path DOCUMENT ME!
|
||
134 | *
|
||
135 | * @throws ChildrenNotAllowedException DOCUMENT ME!
|
||
136 | 346 | fernando | * @throws CancelationException
|
137 | 242 | vcaballero | */
|
138 | 346 | fernando | public void removeLayer(LayerPath path) |
139 | throws ChildrenNotAllowedException, CancelationException {
|
||
140 | 353 | fernando | |
141 | LayerCollectionEvent event = new LayerCollectionEvent(getLayer(path));
|
||
142 | callLayerRemoving(event); |
||
143 | doRemoveLayer(path); |
||
144 | callLayerRemoved(event); |
||
145 | 242 | vcaballero | } |
146 | 214 | fernando | |
147 | 242 | vcaballero | /**
|
148 | * Obtiene el array de capas visibles que penden del arbol cuya ra?z es
|
||
149 | * este nodo
|
||
150 | *
|
||
151 | * @return DOCUMENT ME!
|
||
152 | */
|
||
153 | public FLayer[] getVisibles() { |
||
154 | ArrayList array = new ArrayList(); |
||
155 | 257 | vcaballero | |
156 | 242 | vcaballero | for (Iterator iter = layers.iterator(); iter.hasNext();) { |
157 | if (((FLayer) iter.next()).isVisible()) {
|
||
158 | array.add((FLayer) iter.next()); |
||
159 | } |
||
160 | } |
||
161 | 214 | fernando | |
162 | 242 | vcaballero | return (FLayer[]) array.toArray(); |
163 | } |
||
164 | 214 | fernando | |
165 | 242 | vcaballero | /**
|
166 | * Obtiene el array de capas activas en el sub?rbol que pende de este nodo
|
||
167 | *
|
||
168 | * @return DOCUMENT ME!
|
||
169 | */
|
||
170 | public FLayer[] getActives() { |
||
171 | ArrayList array = new ArrayList(); |
||
172 | 257 | vcaballero | |
173 | 242 | vcaballero | for (Iterator iter = layers.iterator(); iter.hasNext();) { |
174 | if (((FLayer) iter.next()).isActive()) {
|
||
175 | array.add((FLayer) iter.next()); |
||
176 | } |
||
177 | } |
||
178 | 214 | fernando | |
179 | 279 | fernando | return (FLayer[]) array.toArray(new FLayer[0]); |
180 | 242 | vcaballero | } |
181 | 214 | fernando | |
182 | 242 | vcaballero | /**
|
183 | * Obtiene el descendiente de esta colecci?n que se encuentra en el camino
|
||
184 | * indicado en el par?metro. En caso de que el path no contenga ning?n
|
||
185 | * elemento se devuelve this
|
||
186 | *
|
||
187 | * @param path DOCUMENT ME!
|
||
188 | *
|
||
189 | * @return DOCUMENT ME!
|
||
190 | */
|
||
191 | public FLayer getLayer(LayerPath path) {
|
||
192 | 257 | vcaballero | int i = path.getFirstIndex();
|
193 | LayerPath lp = path.getChildPath(); |
||
194 | 242 | vcaballero | FLayer lyr = (FLayer) layers.get(i); |
195 | 214 | fernando | |
196 | 257 | vcaballero | if (lp.isEmpty()) {
|
197 | 242 | vcaballero | return (FLayer) layers.get(i);
|
198 | } else if (layers.get(i) instanceof FLayers) { |
||
199 | 257 | vcaballero | ((FLayers) lyr).getLayer(lp); |
200 | 242 | vcaballero | } |
201 | 214 | fernando | |
202 | 242 | vcaballero | return this; |
203 | } |
||
204 | 214 | fernando | |
205 | 242 | vcaballero | /**
|
206 | * Obtiene el hijo i-?simo directo de esta colecci?n
|
||
207 | *
|
||
208 | * @param index DOCUMENT ME!
|
||
209 | *
|
||
210 | * @return DOCUMENT ME!
|
||
211 | */
|
||
212 | public FLayer getChildLayer(int index) { |
||
213 | return (FLayer) layers.get(index);
|
||
214 | } |
||
215 | 214 | fernando | |
216 | 242 | vcaballero | /**
|
217 | * Obtiene el n?mero de capas que hay en el sub?rbol pendiente de ?ste nodo
|
||
218 | *
|
||
219 | * @return DOCUMENT ME!
|
||
220 | */
|
||
221 | public int getLayerCount() { |
||
222 | int all = 0; |
||
223 | 214 | fernando | |
224 | 242 | vcaballero | for (int i = 0; i < layers.size(); i++) { |
225 | all++; |
||
226 | 214 | fernando | |
227 | 242 | vcaballero | if (layers.get(i) instanceof FLayers) { |
228 | all += ((FLayers) layers.get(i)).getLayerCount(); |
||
229 | } |
||
230 | } |
||
231 | 214 | fernando | |
232 | 242 | vcaballero | return all;
|
233 | } |
||
234 | 214 | fernando | |
235 | 242 | vcaballero | /**
|
236 | * Obtiene el n?mero de hijos que penden de este nodo del ?rbol de capas
|
||
237 | *
|
||
238 | * @return DOCUMENT ME!
|
||
239 | */
|
||
240 | public int getChildLayerCount() { |
||
241 | return layers.size();
|
||
242 | } |
||
243 | 214 | fernando | |
244 | 242 | vcaballero | /**
|
245 | * DOCUMENT ME!
|
||
246 | *
|
||
247 | * @param xe DOCUMENT ME!
|
||
248 | *
|
||
249 | * @return DOCUMENT ME!
|
||
250 | */
|
||
251 | public static FLayers createFLayers(XMLEntity xe) { |
||
252 | //TODO implementar bien
|
||
253 | return null; |
||
254 | } |
||
255 | 214 | fernando | |
256 | 242 | vcaballero | /**
|
257 | * Crea una replica del objeto Layers
|
||
258 | *
|
||
259 | * @return DOCUMENT ME!
|
||
260 | */
|
||
261 | public FLayers cloneFLayers() {
|
||
262 | return createFLayers(getProperties());
|
||
263 | } |
||
264 | 217 | fernando | |
265 | 242 | vcaballero | /**
|
266 | * DOCUMENT ME!
|
||
267 | *
|
||
268 | * @param image DOCUMENT ME!
|
||
269 | * @param g DOCUMENT ME!
|
||
270 | * @param viewPort DOCUMENT ME!
|
||
271 | 244 | fernando | * @param cancel
|
272 | 242 | vcaballero | *
|
273 | * @throws DriverIOException
|
||
274 | *
|
||
275 | * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#draw(java.awt.image.BufferedImage,
|
||
276 | * java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
||
277 | */
|
||
278 | 257 | vcaballero | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
279 | Cancellable cancel) throws DriverIOException {
|
||
280 | 242 | vcaballero | for (Iterator iter = layers.iterator(); iter.hasNext();) { |
281 | LayerOperations capa = (LayerOperations) iter.next(); |
||
282 | 276 | fjp | FLayer lyr = (FLayer) capa; |
283 | System.out.println("Dibujando " + lyr.getName()); |
||
284 | 242 | vcaballero | |
285 | //TODO comprobar si la capa es visible
|
||
286 | // if (capa.isVisible()){
|
||
287 | 244 | fernando | capa.draw(image, g, viewPort, cancel); |
288 | 242 | vcaballero | |
289 | // }
|
||
290 | } |
||
291 | } |
||
292 | |||
293 | /**
|
||
294 | * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#getSelectionBounds()
|
||
295 | */
|
||
296 | public Rectangle2D getSelectionBounds() { |
||
297 | return null; |
||
298 | } |
||
299 | |||
300 | /**
|
||
301 | * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#createIndex()
|
||
302 | */
|
||
303 | public void createIndex() { |
||
304 | } |
||
305 | |||
306 | /**
|
||
307 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
||
308 | */
|
||
309 | 346 | fernando | public Rectangle2D getFullExtent() throws DriverIOException { |
310 | Rectangle2D rAux = null; |
||
311 | int i = 0; |
||
312 | |||
313 | for (Iterator iter = layers.iterator(); iter.hasNext();) { |
||
314 | 342 | fjp | LayerOperations capa = (LayerOperations) iter.next(); |
315 | 346 | fernando | |
316 | if (i == 0) { |
||
317 | rAux = capa.getFullExtent(); |
||
318 | } else {
|
||
319 | capa.getFullExtent().add(rAux); |
||
320 | } |
||
321 | |||
322 | 342 | fjp | i++; |
323 | } |
||
324 | 346 | fernando | |
325 | return rAux;
|
||
326 | 242 | vcaballero | } |
327 | |||
328 | /**
|
||
329 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#selectByPoint(java.awt.geom.Point2D,
|
||
330 | * double)
|
||
331 | */
|
||
332 | public void selectByPoint(QueriedPoint p, double tolerance) { |
||
333 | } |
||
334 | |||
335 | /**
|
||
336 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#selectByRect(java.awt.geom.Rectangle2D)
|
||
337 | */
|
||
338 | public void selectByRect(Rectangle2D rect) { |
||
339 | } |
||
340 | |||
341 | /**
|
||
342 | 305 | fjp | * @see com.iver.cit.gvsig.fmap.layers.FLayer#selectByShape(com.iver.cit.gvsig.fmap.core.IGeometry,
|
343 | 242 | vcaballero | * int)
|
344 | */
|
||
345 | 305 | fjp | public void selectByShape(IGeometry g, int relationship) { |
346 | 242 | vcaballero | } |
347 | 257 | vcaballero | |
348 | /**
|
||
349 | * DOCUMENT ME!
|
||
350 | *
|
||
351 | * @param event DOCUMENT ME!
|
||
352 | 346 | fernando | *
|
353 | * @throws CancelationException
|
||
354 | 257 | vcaballero | */
|
355 | 353 | fernando | private void callLayerAdding(LayerCollectionEvent event) |
356 | 346 | fernando | throws CancelationException {
|
357 | 257 | vcaballero | for (Iterator iter = layerListeners.iterator(); iter.hasNext();) { |
358 | 353 | fernando | ((LayerCollectionListener) iter.next()).layerAdding(event); |
359 | 257 | vcaballero | } |
360 | 247 | vcaballero | } |
361 | 257 | vcaballero | |
362 | /**
|
||
363 | * DOCUMENT ME!
|
||
364 | *
|
||
365 | * @param event DOCUMENT ME!
|
||
366 | 346 | fernando | *
|
367 | * @throws CancelationException
|
||
368 | 257 | vcaballero | */
|
369 | 353 | fernando | private void callLayerRemoving(LayerCollectionEvent event) |
370 | 346 | fernando | throws CancelationException {
|
371 | 257 | vcaballero | for (Iterator iter = layerListeners.iterator(); iter.hasNext();) { |
372 | 353 | fernando | ((LayerCollectionListener) iter.next()).layerRemoving(event); |
373 | 257 | vcaballero | } |
374 | } |
||
375 | |||
376 | /**
|
||
377 | * DOCUMENT ME!
|
||
378 | *
|
||
379 | * @param event DOCUMENT ME!
|
||
380 | 346 | fernando | *
|
381 | * @throws CancelationException
|
||
382 | 257 | vcaballero | */
|
383 | 353 | fernando | private void callLayerMoving(LayerPositionEvent event) |
384 | 346 | fernando | throws CancelationException {
|
385 | 257 | vcaballero | for (Iterator iter = layerListeners.iterator(); iter.hasNext();) { |
386 | 353 | fernando | ((LayerCollectionListener) iter.next()).layerMoving(event); |
387 | } |
||
388 | } |
||
389 | |||
390 | /**
|
||
391 | * DOCUMENT ME!
|
||
392 | *
|
||
393 | * @param event DOCUMENT ME!
|
||
394 | */
|
||
395 | private void callLayerAdded(LayerCollectionEvent event) { |
||
396 | for (Iterator iter = layerListeners.iterator(); iter.hasNext();) { |
||
397 | ((LayerCollectionListener) iter.next()).layerAdded(event); |
||
398 | } |
||
399 | } |
||
400 | |||
401 | /**
|
||
402 | * DOCUMENT ME!
|
||
403 | *
|
||
404 | * @param event DOCUMENT ME!
|
||
405 | */
|
||
406 | private void callLayerRemoved(LayerCollectionEvent event) { |
||
407 | for (Iterator iter = layerListeners.iterator(); iter.hasNext();) { |
||
408 | ((LayerCollectionListener) iter.next()).layerRemoved(event); |
||
409 | } |
||
410 | } |
||
411 | |||
412 | /**
|
||
413 | * DOCUMENT ME!
|
||
414 | *
|
||
415 | * @param event DOCUMENT ME!
|
||
416 | */
|
||
417 | private void callLayerMoved(LayerPositionEvent event) { |
||
418 | for (Iterator iter = layerListeners.iterator(); iter.hasNext();) { |
||
419 | 342 | fjp | ((LayerCollectionListener) iter.next()).layerMoved(event); |
420 | 257 | vcaballero | } |
421 | } |
||
422 | 341 | fernando | |
423 | 346 | fernando | /**
|
424 | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getLayerProperties()
|
||
425 | */
|
||
426 | public XMLEntity getLayerProperties() {
|
||
427 | return null; |
||
428 | } |
||
429 | 214 | fernando | } |