Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2056 / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / FLayer.java @ 39022

History | View | Annotate | Download (19.9 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 org.gvsig.fmap.mapcontext.layers;
42

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

    
51
import org.cresques.cts.ICoordTrans;
52
import org.cresques.cts.IProjection;
53
import org.cresques.geo.Projected;
54
import org.gvsig.compat.print.PrintAttributes;
55
import org.gvsig.fmap.dal.DataStore;
56
import org.gvsig.fmap.dal.exception.ReadException;
57
import org.gvsig.fmap.geom.primitive.Envelope;
58
import org.gvsig.fmap.mapcontext.MapContext;
59
import org.gvsig.fmap.mapcontext.ViewPort;
60
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
61
import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException;
62
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException;
63
import org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer;
64
import org.gvsig.metadata.Metadata;
65
import org.gvsig.tools.dispose.Disposable;
66
import org.gvsig.tools.exception.BaseException;
67
import org.gvsig.tools.persistence.Persistent;
68
import org.gvsig.tools.task.Cancellable;
69

    
70

    
71

    
72
/**
73
 * <p>Definition of the basic functionality that all kind of <i>FMap</i> layers should implement.</p>
74
 *
75
 * <p>This kind of layers store their data, are drawable, projectable (with a projection), can be a node of a tree of layers, and
76
 *  could be editable and have a cache with previous draws. They also can be visible or not, and active or not.</p>
77
 *
78
 * <p>A layer can also store information about errors produced working with it, and have a name (kind of layer) and
79
 *  a brief summary explaining what's for.</p>
80
 *
81
 * <p>Each particular implementation can add new properties, and limit or expand the functionality.</p>
82
 *
83
 * @see Projected
84
 */
85
public interface FLayer extends Projected, Persistent, Metadata, Disposable
86
{
87
        public final String METADATA_DEFINITION_NAME = "Layer";
88
        public final String METADATA_DEFINITION_DESCRIPTION = "Basic layer metadata definition";
89

    
90
        public static final String METADATA_CRS = DataStore.METADATA_CRS;
91
        public static final String METADATA_NAME = "name";
92

    
93

    
94
//        /**
95
//         * <p>Returns an entity that represents this layer.</p>
96
//         *
97
//         * <p>This XML entity has elements that represent and store information about this layer.</p>
98
//         *
99
//         * @return an XML entity with information of this layer
100
//         * @throws XMLException if there is an error obtaining the object.
101
//         *
102
//         * @see #setXMLEntity(XMLEntity)
103
//         * @see #setXMLEntity03(XMLEntity)
104
//         */
105
//        XMLEntity getXMLEntity() throws XMLException;
106
//
107
//        /**
108
//         * <p>Inserts information to this layer from an XML entity.</p>
109
//         *
110
//         * <p>This XML entity has elements that represent and store information about this layer.</p>
111
//         *
112
//         * @param xml an <code>XMLEntity</code> with the information
113
//         *
114
//         * @throws XMLException if there is an error setting the object.
115
//         *
116
//         * @see #getXMLEntity()
117
//         * @see #setXMLEntity03(XMLEntity)
118
//         */
119
//        void setXMLEntity(XMLEntity xml) throws XMLException;
120

    
121
        /**
122
         * <p>Changes the status of this layer to active or inactive.</p>
123
         * <p>One layer is active if is selected in TOC.</p>
124
         *
125
         * @param selected the boolean to be set
126
         *
127
         * @see #isActive()
128
         */
129
        void setActive(boolean selected);
130

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

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

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

    
159
        /**
160
         * <p>Executes the initialization operations of this layer. This method is invoked
161
         * only one time during the life of this layer and just before visualize it.</p>
162
         *
163
         * @throws org.gvsig.fmap.drivers.reading.DriverIOException if fails loading the layer.
164
         *
165
         * @see #reload()
166
         */
167
        void load() throws LoadLayerException;
168
        /**
169
         * <p>Changes the status of this layer to visible or not.</p>
170
         * <p>One layer is visible if it's check box associated is selected. This means
171
         *  that layer will tried to be painted. If the data associated isn't available,
172
         *  then this property will change to <code>false</code>.</p>
173
         *
174
         * @param visibility the boolean to be set
175
         *
176
         * @see #isVisible()
177
         * @see #visibleRequired()
178
         * @see #isAvailable()
179
         */
180
        void setVisible(boolean visibility);
181

    
182
        /**
183
         * <p>Returns if this layer is visible and available.</p>
184
         * <p>One layer is visible if it's check box associated is selected. This means
185
         *  that layer will tried to be painted.</p>
186
         * <p>One layer is available if the source of data is on-line.</p>
187
         * <p>It's probably that one layer selected hadn't available it's data, for example
188
         *  in a remote service.</p>
189
         *
190
         * @return <code>true</code> if this layer is visible and available; <code>false</code> otherwise
191
         *
192
         * @see #isAvailable()
193
         * @see #setAvailable(boolean)
194
         * @see #visibleRequired()
195
         */
196
        boolean isVisible();
197

    
198
        /**
199
         * Returns the parent {@link FLayers FLayers} node of this layer.
200
         *
201
         * @return the parent of this layer, or <code>null</code> if hasn't parent
202
         *
203
         * @see #setParentLayer(FLayers)
204
         */
205
        public FLayers getParentLayer();
206

    
207
        /**
208
         * <p>Returns a reference to the model of this layer, or null if this layer has no model.</p>
209
         *
210
         * @return the model of this layer
211
         */
212
        public MapContext getMapContext();
213

    
214
        /**
215
         * Inserts the parent {@link FLayers FLayers} node of the layer.
216
         *
217
         * @param root a <code>FLayers</code> object
218
         *
219
         * @see #getParentLayer()
220
         */
221
        public void setParentLayer(FLayers root);
222
        /**
223
         * Returns the full extension of the layer node.
224
         *
225
         * @return location and dimension of this layer node
226
         *
227
         * @throws ReadException if fails the driver used in this method.
228
         */
229
        Envelope getFullEnvelope() throws ReadException;
230

    
231
        /**
232
         * Draws the layer using a buffer.
233
         *
234
         * @param image an image used to accelerate the screen draw
235
         * @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
236
         * @param viewPort information for drawing this layer
237
         * @param cancel an object thread that implements the <code>Cancellable</code> interface, and will allow to cancel the draw
238
         * @param scale value that represents the scale
239
         *
240
         * @throws ReadException if fails the driver used in this method.
241
         *
242
         * @see #print(Graphics2D, ViewPort, Cancellable, double, PrintAttributes)
243
         */
244
        void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
245
                        Cancellable cancel,double scale) throws ReadException;
246

    
247
        /**
248
         * Prints this layer according to some properties requested.
249
         *
250
         * @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
251
         * @param viewPort the information for drawing the layers
252
         * @param cancel an object thread that implements the {@link Cancellable Cancellable} interface, and will allow to cancel the draw
253
         * @param scale the scale of the view. Must be between {@linkplain FLayer#getMinScale()} and {@linkplain FLayer#getMaxScale()}.
254
         * @param properties a set with the settings to be applied to a whole print job and to all the docs in the print job
255
         *
256
         * @throws ReadException if fails the driver used in this method.
257
         *
258
         * @see #draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
259
         */
260
        void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintAttributes properties)
261
        throws ReadException;
262

    
263
        /**
264
         * Inserts the transformation coordinates.
265
         *
266
         * @param ct transformation coordinates
267
         *
268
         * @see #getCoordTrans()
269
         */
270
        void setCoordTrans(ICoordTrans ct);
271

    
272
        /**
273
         * Returns the transformation coordinates.
274
         *
275
         * @return transformation coordinates
276
         *
277
         * @see #setCoordTrans(ICoordTrans)
278
         */
279
        ICoordTrans getCoordTrans();
280

    
281
        /**
282
         * Adds a <code>LayerListener</code> to the listener list.
283
         *
284
         * @param o a layer listener
285
         *
286
         * @return <code>true</code> if hasn't been any problem during the insertion of the listener
287
         *
288
         * @see #getLayerListeners()
289
         * @see #removeLayerListener(LayerListener)
290
         */
291
        public boolean addLayerListener(LayerListener o);
292
        /**
293
         * Returns all <code>LayerListener</code>s of this layer as an array.
294
         *
295
         * @return an array with all layer listeners associated to this layer
296
         *
297
         * @see #addLayerListener(LayerListener)
298
         * @see #removeLayerListener(LayerListener)
299
         */
300
        public LayerListener[] getLayerListeners();
301
        /**
302
         * Removes the <code>LayerListener</code> argument from this layer.
303
         *
304
         * @param o a layer listener
305
         *
306
         * @return <code>true</code> if hasn't been any problem doing this process
307
         *
308
         * @see #addLayerListener(LayerListener)
309
         * @see #getLayerListeners()
310
         */
311
        public boolean removeLayerListener(LayerListener o);
312
        /**
313
         * <p>Returns if the value of <code>scale</code> argument
314
         *  is within the maximum and minimum scale of this layer.</p>
315
         *
316
         * @param scale the scale > 0
317
         *
318
         * @return <code>true</code> if the <code>scale</code> argument is within the range of scales of this layer; <code>false</code> otherwise
319
         *
320
         * @see #setMinScale(double)
321
         * @see #setMaxScale(double)
322
         */
323
        public boolean isWithinScale(double scale);
324

    
325

    
326
        /**
327
         * Returns the minimum scale visible. Lower scales won't be drawn.
328
         *
329
         * @return the minimum scale > 0, -1 if not defined
330
         *
331
         * @see #setMinScale(double)
332
         */
333
        public double getMinScale();
334

    
335
        /**
336
         * Returns the maximum scale visible. Higher scales won't be drawn.
337
         *
338
         * @return the maximum scale > 0, -1 if not defined
339
         *
340
         * @see #setMaxScale(double)
341
         */
342
        public double getMaxScale();
343
        /**
344
         * Sets the minimum scale visible. Lower scales won't be drawn.
345
         *
346
         * @param minScale the scale > 0, -1 if not defined
347
         *
348
         * @see #getMinScale()
349
         */
350
        public void setMinScale(double minScale);
351
        /**
352
         * Sets the maximum scale visible. Higher scales won't be drawn.
353
         *
354
         * @param maxScale the scale > 0, -1 if not defined
355
         *
356
         * @see #getMaxScale()
357
         */
358
        public void setMaxScale(double maxScale);
359
        /**
360
         * <p>Changes the status of this layer to editable or not.</p>
361
         * <p>One layer is editable if user can modify its information with graphical tools.</p>
362
         *
363
         * @param b the boolean to be set
364
         *
365
         * @throws com.iver.cit.gvsig.fmap.edition.EditionException if fails enabling for edition this kind of layer.
366
         *
367
         * @see #isEditing()
368
         * @deprecated Editing status is managed internally by layer, cannot be assigned here.
369
         */
370
        public void setEditing(boolean b) throws StartEditionLayerException;
371
        /**
372
         * <p>Returns if this layer is editable.</p>
373
         * <p>One layer is editable if user can modify its information with graphical tools.</p>
374
         *
375
         * @return <code>true</code> if this layer is editable; <code>false</code> otherwise
376
         *
377
         * @see #setEditing(boolean)
378
         */
379
        public boolean isEditing();
380

    
381
        /**
382
         * Returns the image icon that will be shown in the TOC next to this layer.
383
         *
384
         * @return a String reference to the image icon, or <code>null</code> if there isn't any
385
         */
386
        public String getTocImageIcon();
387

    
388
        /**
389
         * <p>Returns if this layer appears in the TOC.</p>
390
         * <p>If doesn't appears, remains in the view and in the project.</p>
391
         *
392
         * @return <code>true</code> if this layer appears in the TOC; <code>false</code> otherwise
393
         */
394
        boolean isInTOC();
395
        /**
396
         * <p>Sets that this layer appears or not in the TOC.</p>
397
         *
398
         * @param b <code>true</code> if appears in the TOC; <code>false</code> otherwise
399
         */
400
        void setInTOC(boolean b);
401
        /**
402
         * Returns the status of this layer.
403
         *
404
         * @return the status stored in a <code>FLayerStatus</code> object
405
         *
406
         * @see #setFLayerStatus(FLayerStatus)
407
         */
408
        public FLayerStatus getFLayerStatus();
409
        /**
410
         * Sets the status of this layer.
411
         *
412
         * @param status information of the status for this layer
413
         *
414
         * @see #getFLayerStatus()
415
         */
416
        public void setFLayerStatus(FLayerStatus status);
417
        /*
418
         * This stuff is to save error's info that causes
419
         * unavailable status.
420
         * */
421
        /**
422
         * <p>Returns if this layer hasn't got errors.</p>
423
         *
424
         * @return <code>true</code> if this layer hasn't got errors; <code>false</code> otherwise
425
         */
426
        public boolean isOk();
427
        /**
428
         * Returns the number of errors which causes this layer to be in unavailable status.
429
         *
430
         * @return number of errors >= 0
431
         *
432
         * @see #getError(int)
433
         * @see #getErrors()
434
         */
435
        public int getNumErrors();
436

    
437
        /**
438
         * Returns the specified error.
439
         *
440
         * @param i index of the error >= 0 && < <code>getNumErrors</code>
441
         *
442
         * @return a singular error
443
         *
444
         * @see #getNumErrors()
445
         * @see #getErrors()
446
         */
447
        public BaseException getError(int i);
448

    
449
    /**
450
     * Adds an error reason that describes this layer's wrong status.
451
     * 
452
     * @param error
453
     *            a <code>BaseException</code> with the information of the error
454
     * 
455
     * @see #getNumErrors()
456
     * @see #getError(int)
457
     * @see #getErrors()
458
     */
459
        public void addError(BaseException exception);
460

    
461
        /**
462
         * Returns a list with all layer errors.
463
         *
464
         * @return an <code>ArrayList</code> with the errors
465
         *
466
         * @see #getError(int)
467
         * @see #getNumErrors()
468
         */
469
        public List getErrors();
470
        /**
471
         * <p>Changes the status of availability of this layer.</p>
472
         * <p>One layer is available if the source of data is on-line.</p>
473
         *
474
         * @param the boolean to be set
475
         *
476
         * @see #isAvailable()
477
         */
478
        public void setAvailable(boolean available);
479
        /**
480
         * <p>Returns the status of availability of this layer.</p>
481
         * <p>One layer is available if the source of data is on-line.</p>
482
         *
483
         * @return <code>true</code> if the source of data is on-line; <code>false</code> otherwise
484
         *
485
         * @see #setAvailable(boolean)
486
         * @see #isVisible()
487
         */
488
        public boolean isAvailable();
489

    
490
    /**
491
     * <p>
492
     * Tries recover a layer of a possible error.
493
     * </p>
494
     * <p>
495
     * If it has any problem during the load, marks the availability to false
496
     * and throws an exception.
497
     * </p>
498
     * 
499
     * @throws ReloadLayerException
500
     *             if it's thrown a <code>ReadException</code> or an
501
     *             <code>IOException</code> during the load of this layer.
502
     * 
503
     * @see #load()
504
     */
505
        public void reload() throws ReloadLayerException;
506

    
507
        /**
508
         * Returns <code>true</code> if this layer has the visible status enabled.
509
         *
510
         * @return <code>true</code> if visible this layer has the visible status enabled, otherwise <code>false</code>
511
         *
512
         * @see #isVisible()
513
         * @see #setVisible(boolean)
514
         */
515
        boolean visibleRequired();
516
        /**
517
         * Returns an string with the information of this layer.
518
         *
519
         * @return the string that is to be this component's information
520
         */
521
        public String getInfoString();
522
        /**
523
         * <p>Returns the writing status of this layer.</p>
524
         * <p>One layer is writable if there is a writing driver for this layer.</p>
525
         *
526
         * @return <code>true</code> if there is a writing driver for this layer; <code>false</code> otherwise
527
         */
528
        public boolean isWritable();
529

    
530
        /**
531
         * <p>This method can be used to have a fast cloned layer.</p>
532
         * <p>The implementations should take care of not recreate this layer. Instead of this,
533
         *  is better to use the same source (driver) and <i>deepclone</i> the legend. Exception:
534
         *   the labels aren't <i>deepcloned</i> to avoid memory consumption.</p>
535
         * <p><i>Note</i>: Labels are memory consuming to speed up layers like PostGIS and so on.</p>
536
         *
537
         * @return a layer that is a clonation of this layer
538
         *
539
         * @throws java.lang.Exception any exception produced during the cloning of this layer.
540
         */
541
        public FLayer cloneLayer() throws Exception;
542

    
543

    
544

    
545
        /**
546
         * <p>Returns a reference to an object (property) associated to this layer.</p>
547
         *
548
         * <p>For example, you can attach a network definition to key "network" and check
549
         *  if a layer has a network loaded using <i>getAssociatedObject("network")</i> and
550
         *  that it's not null.</p>
551
         *
552
         * @param key the key associated to the property
553
         *
554
         * @return <code>null</code> if key is not found
555
         *
556
         * @see #getExtendedProperties()
557
         * @see #setProperty(Object, Object)
558
         */
559
        public Object getProperty(Object key);
560

    
561
        /**
562
         * Insets an object as a property to this layer.
563
         *
564
         * @param key the key associated to the property
565
         * @param obj the property
566
         *
567
         * @see #getProperty(Object)
568
         * @see #getExtendedProperties()
569
         */
570
        public void setProperty(Object key, Object obj);
571
        /**
572
         * Returns a hash map with all new properties associated to this layer.
573
         *
574
         * @return hash table with the added properties
575
         *
576
         * @see #getProperty(Object)
577
         * @see #setProperty(Object, Object)
578
         */
579
        public Map getExtendedProperties();
580

    
581
        /**
582
         * <p>Returns a new instance of {@link ComposedLayer ComposedLayer}.</p>
583
         *
584
         * <p>This allows make a single draw for a group
585
         * of layers with the same source.</p>
586
         *
587
         * <p>If this operation isn't applicable for this
588
         * kind of layer, this method returns null.</p>
589
         *
590
         * <p>By default this operation is not supported.</p>
591
         *
592
         * @see org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer
593
         *
594
         * @return a new composed layer or <code>null</code> if not supported
595
         */
596
        public ComposedLayer  newComposedLayer();
597

    
598
        /**
599
         * Returns the image icon that will be shown in the TOC next to this layer, according its status.
600
         *
601
         * @return the image
602
         */
603
        Image getTocStatusImage();
604

    
605
//        M?todos para la utilizaci?n de HyperLinks
606

    
607
        /**
608
         * Returns information about if the layer allows HyperLink or not
609
         * @return boolean true if allows Link, false if not
610
         */
611
        public boolean allowLinks();
612

    
613
        /**
614
         * Returns an instance of AbstractLinkProperties that contains the information
615
         * of the HyperLink
616
         * @return Abstra
617
         */
618
        public AbstractLinkProperties getLinkProperties();
619

    
620
        /**
621
         * Provides an array with URIs. Returns one URI by geometry that includes the point
622
         * in its own geometry limits with a allowed tolerance.
623
         * @param layer, the layer
624
         * @param point, the point to check that is contained or not in the geometries in the layer
625
         * @param tolerance, the tolerance allowed. Allowed margin of error to detect if the  point
626
         *                 is contained in some geometries of the layer
627
         * @return
628
         * @throws ReadException
629
         * @throws BehaviorException
630
         */
631
        public URI[] getLink(Point2D point, double tolerance) throws ReadException;
632

    
633

    
634
        /**
635
         * <p>Inserts the projection to this layer.</p>
636
         *
637
         * @param proj information about the new projection
638
         *
639
         */
640
        public void setProjection(IProjection proj);
641
        
642
        public long getDrawVersion();
643
        
644
}