Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / FLayer.java @ 38605

History | View | Annotate | Download (19.8 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
         */
369
        public void setEditing(boolean b) throws StartEditionLayerException;
370
        /**
371
         * <p>Returns if this layer is editable.</p>
372
         * <p>One layer is editable if user can modify its information with graphical tools.</p>
373
         *
374
         * @return <code>true</code> if this layer is editable; <code>false</code> otherwise
375
         *
376
         * @see #setEditing(boolean)
377
         */
378
        public boolean isEditing();
379

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

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

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

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

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

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

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

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

    
542

    
543

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

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

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

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

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

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

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

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

    
632

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