Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLayer.java @ 13588

History | View | Annotate | Download (20.6 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.layers;
42

    
43
import java.awt.Graphics2D;
44
import java.awt.Image;
45
import java.awt.geom.Rectangle2D;
46
import java.awt.image.BufferedImage;
47
import java.util.List;
48
import java.util.Map;
49

    
50
import javax.print.attribute.PrintRequestAttributeSet;
51
import javax.swing.ImageIcon;
52

    
53
import org.cresques.cts.ICoordTrans;
54
import org.cresques.cts.IProjection;
55
import org.cresques.geo.Projected;
56

    
57
import com.iver.cit.gvsig.fmap.DriverException;
58
import com.iver.cit.gvsig.fmap.MapContext;
59
import com.iver.cit.gvsig.fmap.MapControl;
60
import com.iver.cit.gvsig.fmap.ViewPort;
61
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
62
import com.iver.cit.gvsig.fmap.edition.EditionException;
63
import com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer;
64
import com.iver.utiles.XMLEntity;
65
import com.iver.utiles.swing.threads.Cancellable;
66

    
67

    
68
/**
69
 * <p>Definition of the basic functionality that all kind of <i>FMap</i> layers should implement.</p>
70
 *
71
 * <p>This kind of layers store their data, are drawable, projectable (with a projection), can be a node of a tree of layers, and
72
 *  could be editable and have a cache with previous draws. They also can be visible or not, and active or not.</p>
73
 *
74
 * <p>A layer can also store information about errors produced working with it, and have a name (kind of layer) and
75
 *  a brief summary explaining what's for.</p>
76
 *
77
 * <p>Each particular implementation can add new properties, and limit or expand the functionality.</p>
78
 *
79
 * @see Projected
80
 */
81
public interface FLayer extends Projected {
82
        /**
83
         * <p>Returns an entity that represents this layer.</p>
84
         *
85
         * <p>This XML entity has elements that represent and store information about this layer.</p>
86
         *
87
         * @return an XML entity with information to the current layer
88
         * @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error obtaining the object.
89
         *
90
         * @see #setXMLEntity(XMLEntity)
91
         * @see #setXMLEntity03(XMLEntity)
92
         */
93
        XMLEntity getXMLEntity() throws XMLException;
94

    
95
        /**
96
         * <p>Inserts information to this layer from an XML entity.</p>
97
         *
98
         * <p>This XML entity has elements that represent and store information about this layer.</p>
99
         *
100
         * @param xml an <code>XMLEntity</code> with the information
101
         *
102
         * @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error setting the object.
103
         *
104
         * @see #getXMLEntity()
105
         * @see #setXMLEntity03(XMLEntity)
106
         */
107
        void setXMLEntity(XMLEntity xml) throws XMLException;
108

    
109
        /**
110
         * Inserts some properties to this layer.
111
         *
112
         * @param xml an <code>XMLEntity</code> with the information
113
         *
114
         * @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error obtaining the object.
115
         *
116
         * @see #getXMLEntity()
117
         * @see #setXMLEntity(XMLEntity)
118
         */
119
        void setXMLEntity03(XMLEntity xml) throws XMLException;
120

    
121
        /**
122
         * Changes the status of the current layer to active or inactive.
123
         *
124
         * @param selected the boolean to be set
125
         *
126
         * @see #isActive()
127
         */
128
        void setActive(boolean selected);
129

    
130
        /**
131
         * Returns <code>true</code> or <code>false</code> if this layer is in black or not in the TOC.
132
         *
133
         * @return <code>true</code> if this layer is active; <code>false</code> otherwise
134
         *
135
         * @see #setActive(boolean)
136
         */
137
        boolean isActive();
138

    
139
        /**
140
         * Sets a name to this layer.
141
         *
142
         * @param name the string that is to be this layer's name
143
         *
144
         * @see #getName()
145
         */
146
        void setName(String name);
147

    
148
        /**
149
         * Returns the name of this layer.
150
         *
151
         * @return an string with this layer's name
152
         *
153
         * @see #setName(String)
154
         */
155
        String getName();
156

    
157
        /**
158
         * <p>Executes the initialization operations of this layer. This method is invoked
159
         * only one time during the life of this layer and just before visualize it.</p>
160
         *
161
         * @throws com.iver.cit.gvsig.fmap.drivers.DriverIOException if fails loading the layer.
162
         *
163
         * @see #reload()
164
         */
165
        void load() throws DriverIOException;
166

    
167
        /**
168
         * Changes the status of the current layer to visible or invisible.
169
         *
170
         * @param visibility the boolean to be set
171
         *
172
         * @see #isVisible()
173
         * @see #visibleRequired()
174
         * @see #isAvailable()
175
         */
176
        void setVisible(boolean visibility);
177

    
178
        /**
179
         * <p>Returns <code>true</code> if this layer is visible and available.</p>
180
         *
181
         * @return <code>true</code> if this layer is visible and available; <code>false</code> otherwise
182
         *
183
         * @see #isAvailable()
184
         * @see #setAvailable(boolean)
185
         * @see #visibleRequired()
186
         */
187
        boolean isVisible();
188

    
189
        /**
190
         * Returns the parent {@link FLayers FLayers} node of this layer.
191
         *
192
         * @return the parent of this layer, or <code>null</code> if hasn't parent
193
         *
194
         * @see #setParentLayer(FLayers)
195
         */
196
        public FLayers getParentLayer();
197

    
198
        /**
199
         * <p>Returns a reference to the model of this layer, or null if this layer has no model.</p>
200
         *
201
         * @return the model of this layer
202
         */
203
        public MapContext getMapContext();
204

    
205
        /**
206
         * Inserts the parent {@link FLayers FLayers} node of the layer.
207
         *
208
         * @param root a <code>FLayers</code> object
209
         *
210
         * @see #getParentLayer()
211
         */
212
        public void setParentLayer(FLayers root);
213

    
214
        /**
215
         * Returns the full extension of the layer node.
216
         *
217
         * @return location and dimension of this layer node
218
         *
219
         * @throws com.iver.cit.gvsig.fmap.DriverException if fails the driver used in this method.
220
         */
221
        Rectangle2D getFullExtent() throws DriverException;
222

    
223
        /**
224
         * Draws the layer using a buffer.
225
         *
226
         * @param image an image used to accelerate the screen draw
227
         * @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
228
         * @param viewPort information for drawing this layer
229
         * @param cancel an object thread that implements the <code>Cancellable</code> interface, and will allow to cancel the draw
230
         * @param scale value that represents the scale
231
         *
232
         * @throws com.iver.cit.gvsig.fmap.DriverException if fails the driver used in this method.
233
         *
234
         * @see #print(Graphics2D, ViewPort, Cancellable, double, PrintRequestAttributeSet)
235
         */
236
        void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
237
                Cancellable cancel, double scale) throws DriverException;
238

    
239
        /**
240
         * Prints this layer according to some properties requested.
241
         *
242
         * @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
243
         * @param viewPort the information for drawing the layers
244
         * @param cancel an object thread that implements the {@link Cancellable Cancellable} interface, and will allow to cancel the draw
245
         * @param scale the scale of the view. Must be between {@linkplain FLayer#getMinScale()} and {@linkplain FLayer#getMaxScale()}.
246
         * @param properties a set with the settings to be applied to a whole print job and to all the docs in the print job
247
         *
248
         * @throws com.iver.cit.gvsig.fmap.DriverException if fails the driver used in this method.
249
         *
250
         * @see #draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
251
         */
252
        void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties)
253
                throws DriverException;
254

    
255
        /**
256
         * Inserts the transformation coordinates.
257
         *
258
         * @param ct transformation coordinates
259
         *
260
         * @see #getCoordTrans()
261
         */
262
        void setCoordTrans(ICoordTrans ct);
263

    
264
        /**
265
         * Returns the transformation coordinates.
266
         *
267
         * @return transformation coordinates
268
         *
269
         * @see #setCoordTrans(ICoordTrans)
270
         */
271
        ICoordTrans getCoordTrans();
272

    
273
        /**
274
         * Adds a <code>LayerListener</code> to the listener list.
275
         *
276
         * @param o a layer listener
277
         *
278
         * @return <code>true</code> if hasn't been any problem during the insertion of the listener
279
         *
280
         * @see #getLayerListeners()
281
         * @see #removeLayerListener(LayerListener)
282
         */
283
        public boolean addLayerListener(LayerListener o);
284

    
285
        /**
286
         * Returns all <code>LayerListener</code>s of this layer as an array.
287
         *
288
         * @return an array with all layer listeners associated to this layer
289
         *
290
         * @see #addLayerListener(LayerListener)
291
         * @see #removeLayerListener(LayerListener)
292
         */
293
        public LayerListener[] getLayerListeners();
294

    
295
        /**
296
         * Removes the <code>LayerListener</code> argument from this layer.
297
         *
298
         * @param o a layer listener
299
         *
300
         * @return <code>true</code> if hasn't been any problem doing this process
301
         *
302
         * @see #addLayerListener(LayerListener)
303
         * @see #getLayerListeners()
304
         */
305
        public boolean removeLayerListener(LayerListener o);
306

    
307
        /**
308
         * <p>Returns <code>true</code> if the value of <code>scale</code> argument
309
         *  is within the maximum and minimum scale of this layer.</p>
310
         *
311
         * @param scale the scale > 0
312
         *
313
         * @return <code>true</code> if the <code>scale</code> argument is within the range of scales of this layer; <code>false</code> otherwise
314
         *
315
         * @see #setMinScale(double)
316
         * @see #setMaxScale(double)
317
         */
318
        public boolean isWithinScale(double scale);
319

    
320
        /**
321
         * Returns the minimum scale visible. Lower scales won't be drawn.
322
         *
323
         * @return the minimum scale > 0, -1 if not defined
324
         *
325
         * @see #setMinScale(double)
326
         */
327
        public double getMinScale();
328

    
329
        /**
330
         * Returns the maximum scale visible. Higher scales won't be drawn.
331
         *
332
         * @return the maximum scale > 0, -1 if not defined
333
         *
334
         * @see #setMaxScale(double)
335
         */
336
        public double getMaxScale();
337

    
338
        /**
339
         * Sets the minimum scale visible. Lower scales won't be drawn.
340
         *
341
         * @param minScale the scale > 0, -1 if not defined
342
         *
343
         * @see #getMinScale()
344
         */
345
        public void setMinScale(double minScale);
346

    
347
        /**
348
         * Sets the maximum scale visible. Higher scales won't be drawn.
349
         *
350
         * @param maxScale the scale > 0, -1 if not defined
351
         *
352
         * @see #getMaxScale()
353
         */
354
        public void setMaxScale(double maxScale);
355

    
356
        /**
357
         * Changes the status of the current layer to editable or not.
358
         *
359
         * @param b the boolean to be set
360
         *
361
         * @throws com.iver.cit.gvsig.fmap.edition.EditionException if fails enabling for edition this kind of layer.
362
         *
363
         * @see #isEditing()
364
         */
365
        public void setEditing(boolean b) throws EditionException;
366

    
367
        /**
368
         * <p>Returns <code>true</code> if this layer is editable.</p>
369
         *
370
         * @return <code>true</code> if this layer is editable; <code>false</code> otherwise
371
         *
372
         * @see #setEditing(boolean)
373
         */
374
        public boolean isEditing();
375

    
376
        /**
377
         * <p>Uses or not a <code>BufferedImage</code> image that represents the drawn layers.</p>
378
         *
379
         * @return <code>true</code> if uses that kind of image; <code>false</code> otherwise
380
         *
381
         * @see #setCachingDrawnLayers(boolean)
382
         */
383
        public boolean isCachingDrawnLayers();
384

    
385
        /**
386
         * <p>Set <code>true</code> if you want this layer to store an image of previous layers.
387
         *  Then, if you perform a <code>FLayers#invalidateLayer()</code>, the system will
388
         *  redraw only this layers you are requesting.</p>
389
         *
390
         *  @param bCacheDrawnLayers the boolean to be set
391
         *
392
         *  @see #isCachingDrawnLayers()
393
         */
394
//         * <p>Another option could be store an image of each layer drawn, and call each one using something
395
//         *  like "invalidate()". On having rendered, it's possible to see if it's invalidated, and if itsn't,
396
//         *  paste the cached image.</p>
397
//         *
398
//         * <p> ERROR!: You can't cache that image, because if the background has changed, the antialiasing
399
//         *  will affect the draw of that layer. However, it would be useful draw the cached image of each layer
400
//         *  that aren't invalidated, and from that appears one of them invalidated, the rest already have to draw.
401
//         *  The problem is that continues spending more memory</p>
402
//         *
403
//         * @param bCacheDrawnLayers
404
//         */
405
        public void setCachingDrawnLayers(boolean bCacheDrawnLayers);
406

    
407
        /**
408
         * Returns the image icon that will be shown in the TOC next to this layer.
409
         *
410
         * @return a reference to the image icon, or <code>null</code> if there isn't any
411
         */
412
        public ImageIcon getTocImageIcon();
413

    
414
        /**
415
         * <p>Returns <code>true</code> if this layer appears in the TOC.</p>
416
         * <p>If doesn't appears, remains in the view and in the project.</p>
417
         *
418
         * @return <code>true</code> if this layer appears in the TOC; <code>false</code> otherwise
419
         */
420
        boolean isInTOC();
421

    
422
        /**
423
     * <p>Sets if this layer appears or not in the TOC.</p>
424
     * 
425
     * @param b <code>true</code> if appears in the TOC; <code>false</code> otherwise
426
     */
427
        void setInTOC(boolean b);
428

    
429
        /**
430
         * <p>Returns <code>true</code> if this layer needs or doesn't need a repaint.
431
         *
432
         * @return <code>true</code> if this layer need a repaint; <code>false</code> otherwise
433
         *
434
         * @see #setDirty(boolean)
435
         */
436
        public boolean isDirty();
437

    
438
        /**
439
         * <p>Changes the status of this layer to dirty if needs a repaint.</p>
440
         *
441
         * <p>By default, all layers will be set to dirty when the extent changes. But for events like changing
442
         * its legend, or editing a layer, we could perform some optimization using the private method <code>MapContext#prepareDrawing</code> from <code>MapContext</code>.</p>
443
         *
444
         * @param dirty <code>true</code> if this layer needs a repaint
445
         *
446
         * @see #isDirty()
447
         */
448
        public void setDirty(boolean dirty);
449

    
450
        /**
451
         * Returns the image with bands, of the drawn layers.
452
         *
453
         * @return an image with bands
454
         *
455
         * @see #setCacheImageDrawnLayers(BufferedImage)
456
         */
457
        public BufferedImage getCacheImageDrawnLayers();
458

    
459
        /**
460
         * Sets the image with bands, for the drawn layers.
461
         *
462
         * @param cacheImageDrawnLayers an image with bands
463
         *
464
         * @see #getCacheImageDrawnLayers()
465
         */
466
        public void setCacheImageDrawnLayers(BufferedImage cacheImageDrawnLayers);
467

    
468
        /**
469
         * Returns the status of this layer.
470
         *
471
         * @return the status stored in a <code>FLayerStatus</code> object
472
         *
473
         * @see #setFLayerStatus(FLayerStatus)
474
         */
475
        public FLayerStatus getFLayerStatus();
476

    
477
        /**
478
         * Sets the status of this layer.
479
         *
480
         * @param status information of the status for this layer
481
         *
482
         * @see #getFLayerStatus()
483
         */
484
        public void setFLayerStatus(FLayerStatus status);
485

    
486
        /*
487
         * This stuff is to save error's info that causes
488
         * unavailable status.
489
         * */
490
        /**
491
         * Returns <code>true</code> if this layer is in OK status (it hasn't got errors).
492
         *
493
         * @return <code>true</code> if is in OK status; <code>false</code> otherwise
494
         */
495
        public boolean isOk();
496

    
497
        /**
498
         * Returns the number of errors which causes this layer to be in unavailable status.
499
         *
500
         * @return number of errors >= 0
501
         *
502
         * @see #getError(int)
503
         * @see #getErrors()
504
         * @see #addError(DriverException)
505
         */
506
        public int getNumErrors();
507

    
508
        /**
509
         * Returns the specified error.
510
         *
511
         * @param i index of the error >= 0 && < <code>getNumErrors</code>
512
         *
513
         * @return a singular error
514
         *
515
         * @see #getNumErrors()
516
         * @see #getErrors()
517
         */
518
        public DriverException getError(int i);
519

    
520
        /**
521
         * Adds an error reason that describes this layer's wrong status.
522
         *
523
         * @param error a <code>DriverException</code> with the information of the error
524
         *
525
         * @see #getNumErrors()
526
         * @see #getError(int)
527
         * @see #getErrors()
528
         */
529
        public void addError(DriverException error);
530

    
531
        /**
532
         * Returns a list with all layer errors.
533
         *
534
         * @return an <code>ArrayList</code> with the errors
535
         *
536
         * @see #getError(int)
537
         * @see #getNumErrors()
538
         */
539
        public List getErrors();
540

    
541
        /**
542
         * Changes the status of the current layer to available or not. By default it's <code>true</code>.
543
         *
544
         * @param the boolean to be set
545
         *
546
         * @see #isAvailable()
547
         */
548
        public void setAvailable(boolean available);
549

    
550
        /**
551
         * Returns the status of availability of the current layer.
552
         *
553
         * @return <code>true</code> if the source of data is on-line; <code>false</code> otherwise
554
         *
555
         * @see #setAvailable(boolean)
556
         * @see #isVisible()
557
         */
558
        public boolean isAvailable();
559

    
560
        /**
561
         * <p>Tries recover a layer of a possible error.</p>
562
         * <p>If it has any problem during the load, marks the availability
563
         *  to false and throws an exception.</p>
564
         *
565
         * @throws DriverIOException if it's thrown a <code>DriverException</code> or an <code>IOException</code> during the load of this layer.
566
         *
567
         * @see #load()
568
         */
569
        public void reload() throws DriverIOException;
570

    
571
        /**
572
         * Returns <code>true</code> if this layer has the visible status enabled.
573
         *
574
         * @return <code>true</code> if visible this layer has the visible status enabled, otherwise <code>false</code>
575
         *
576
         * @see #isVisible()
577
         * @see #setVisible(boolean)
578
         */
579
        boolean visibleRequired();
580

    
581
        /**
582
         * Returns an string with the information of this layer.
583
         *
584
         * @return the string that is to be this component's information
585
         */
586
        public String getInfoString();
587

    
588
        /**
589
         * Returns the writing status of this layer.
590
         *
591
         * @return <code>true</code> if there is a writing driver for this layer; <code>false</code> otherwise
592
         */
593
        public boolean isWritable();
594

    
595
        /**
596
         * <p>Returns a reference to an object (property) associated to this layer.</p>
597
         *
598
         * <p>For example, you can attach a network definition to key "network" and check
599
         *  if a layer has a network loaded using <i>getAssociatedObject("network")</i> and
600
         *  that it's not null.</p>
601
         *
602
         * @param key the key associated to the property
603
         *
604
         * @return <code>null</code> if key is not found
605
         *
606
         * @see #getExtendedProperties()
607
         * @see #setProperty(Object, Object)
608
         */
609
        public Object getProperty(Object key);
610

    
611
        /**
612
         * Insets an object as a property to this layer.
613
         *
614
         * @param key the key associated to the property
615
         * @param obj the property
616
         *
617
         * @see #getProperty(Object)
618
         * @see #getExtendedProperties()
619
         */
620
        public void setProperty(Object key, Object obj);
621

    
622
        /**
623
         * <p>This method can be used to have a fast cloned layer.</p>
624
         * <p>The implementations should take care of not recreate this layer. Instead of this,
625
         *  is better to use the same source (driver) and <i>deepclone</i> the legend. Exception:
626
         *   the labels aren't <i>deepcloned</i> to avoid memory consumption.</p>
627
         * <p><i>Note</i>: Labels are memory consuming to speed up layers like PostGIS and so on.</p>
628
         *
629
         * @return a layer that is a clonation of this layer
630
         *
631
         * @throws java.lang.Exception any exception produced during the cloning of this layer.
632
         */
633
        public FLayer cloneLayer() throws Exception;
634

    
635
        /**
636
         * Returns a hash map with all new properties associated to this layer.
637
         *
638
         * @return hash table with the added properties
639
         *
640
         * @see #getProperty(Object)
641
         * @see #setProperty(Object, Object)
642
         */
643
        public Map getExtendedProperties();
644

    
645
        /**
646
         * <p>Returns a new instance of {@link ComposedLayer ComposedLayer}.</p>
647
         *
648
         * <p>This allows make a single draw for a group
649
         * of layers with the same source.</p>
650
         *
651
         * <p>If this operation isn't applicable for this
652
         * kind of layer, this method returns null.</p>
653
         *
654
         * <p>By default this operation is not supported.</p>
655
         *
656
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer
657
         *
658
         * @return a new composed layer or <code>null</code> if not supported
659
         */
660
        public ComposedLayer newComposedLayer();
661

    
662
        /**
663
         * Returns the image icon that will be shown in the TOC next to this layer, according its status.
664
         *
665
         * @return the image
666
         */
667
        Image getTocStatusImage();
668

    
669
        /**
670
         * Returns <code>true</code> if the projection of the layer can be changed.
671
         *
672
         * @return <code>true</code> if can be changed its projection; <code>false</code> otherwise
673
         *
674
         * @see #reProject(MapControl)
675
         * @see #setProjection(IProjection)
676
         */
677
        public boolean isReprojectable();
678

    
679
        /**
680
         * <p>Changes the projection of this layer.</p>
681
         * <p>This method will be overload in each kind of layer, according its specific operations</p>
682
         *
683
         * @param mapC object that will allow work with the image (draw, reproject, transform, store information, ...)
684
         *
685
         * @return <true> if the layer is created with the method {@link FLayers#addLayer(FLayer) FLayers#addLayer}, but returns <code>false</code>
686
         *  if the layer load control is passed to the reprojection method
687
         *
688
         * @see #isReprojectable()
689
         * @see #setProjection(IProjection)
690
         */
691
        public boolean reProject(MapControl mapC);
692

    
693
        /**
694
         * Inserts the projection to this layer.
695
         *
696
         * @param proj information about the new projection
697
         *
698
         * @see #isReprojectable()
699
         * @see #reProject(MapControl)
700
         */
701
        public void setProjection(IProjection proj);
702
}