Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / main / java / org / gvsig / fmap / mapcontext / layers / FLayer.java @ 40559

History | View | Annotate | Download (19.6 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.mapcontext.layers;
25

    
26
import java.awt.Graphics2D;
27
import java.awt.Image;
28
import java.awt.geom.Point2D;
29
import java.awt.image.BufferedImage;
30
import java.net.URI;
31
import java.util.List;
32
import java.util.Map;
33

    
34
import org.cresques.cts.ICoordTrans;
35
import org.cresques.cts.IProjection;
36
import org.cresques.geo.Projected;
37
import org.gvsig.compat.print.PrintAttributes;
38
import org.gvsig.fmap.dal.DataStore;
39
import org.gvsig.fmap.dal.exception.ReadException;
40
import org.gvsig.fmap.geom.primitive.Envelope;
41
import org.gvsig.fmap.mapcontext.MapContext;
42
import org.gvsig.fmap.mapcontext.ViewPort;
43
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
44
import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException;
45
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException;
46
import org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer;
47
import org.gvsig.metadata.Metadata;
48
import org.gvsig.tools.dispose.Disposable;
49
import org.gvsig.tools.exception.BaseException;
50
import org.gvsig.tools.persistence.Persistent;
51
import org.gvsig.tools.task.Cancellable;
52

    
53

    
54

    
55
/**
56
 * <p>Definition of the basic functionality that all kind of <i>FMap</i> layers should implement.</p>
57
 *
58
 * <p>This kind of layers store their data, are drawable, projectable (with a projection), can be a node of a tree of layers, and
59
 *  could be editable and have a cache with previous draws. They also can be visible or not, and active or not.</p>
60
 *
61
 * <p>A layer can also store information about errors produced working with it, and have a name (kind of layer) and
62
 *  a brief summary explaining what's for.</p>
63
 *
64
 * <p>Each particular implementation can add new properties, and limit or expand the functionality.</p>
65
 *
66
 * @see Projected
67
 */
68
public interface FLayer extends Projected, Persistent, Metadata, Disposable
69
{
70
        public final String METADATA_DEFINITION_NAME = "Layer";
71
        public final String METADATA_DEFINITION_DESCRIPTION = "Basic layer metadata definition";
72

    
73
        public static final String METADATA_CRS = DataStore.METADATA_CRS;
74
        public static final String METADATA_NAME = "name";
75

    
76

    
77
//        /**
78
//         * <p>Returns an entity that represents this layer.</p>
79
//         *
80
//         * <p>This XML entity has elements that represent and store information about this layer.</p>
81
//         *
82
//         * @return an XML entity with information of this layer
83
//         * @throws XMLException if there is an error obtaining the object.
84
//         *
85
//         * @see #setXMLEntity(XMLEntity)
86
//         * @see #setXMLEntity03(XMLEntity)
87
//         */
88
//        XMLEntity getXMLEntity() throws XMLException;
89
//
90
//        /**
91
//         * <p>Inserts information to this layer from an XML entity.</p>
92
//         *
93
//         * <p>This XML entity has elements that represent and store information about this layer.</p>
94
//         *
95
//         * @param xml an <code>XMLEntity</code> with the information
96
//         *
97
//         * @throws XMLException if there is an error setting the object.
98
//         *
99
//         * @see #getXMLEntity()
100
//         * @see #setXMLEntity03(XMLEntity)
101
//         */
102
//        void setXMLEntity(XMLEntity xml) throws XMLException;
103

    
104
        /**
105
         * <p>Changes the status of this layer to active or inactive.</p>
106
         * <p>One layer is active if is selected in TOC.</p>
107
         *
108
         * @param selected the boolean to be set
109
         *
110
         * @see #isActive()
111
         */
112
        void setActive(boolean selected);
113

    
114
        /**
115
         * <p>Returns if this layer is active or not in TOC.</p>
116
         * <p>One layer is active if is selected in TOC.</p>
117
         *
118
         * @return <code>true</code> if this layer is active; <code>false</code> otherwise
119
         *
120
         * @see #setActive(boolean)
121
         */
122
        boolean isActive();
123

    
124
        /**
125
         * Sets a name to this layer.
126
         *
127
         * @param name the string that is to be this layer's name
128
         *
129
         * @see #getName()
130
         */
131
        void setName(String name);
132

    
133
        /**
134
         * Returns the name of this layer.
135
         *
136
         * @return an string with this layer's name
137
         *
138
         * @see #setName(String)
139
         */
140
        String getName();
141

    
142
        /**
143
         * <p>Executes the initialization operations of this layer. This method is invoked
144
         * only one time during the life of this layer and just before visualize it.</p>
145
         *
146
         * @throws org.gvsig.fmap.drivers.reading.DriverIOException if fails loading the layer.
147
         *
148
         * @see #reload()
149
         */
150
        void load() throws LoadLayerException;
151
        /**
152
         * <p>Changes the status of this layer to visible or not.</p>
153
         * <p>One layer is visible if it's check box associated is selected. This means
154
         *  that layer will tried to be painted. If the data associated isn't available,
155
         *  then this property will change to <code>false</code>.</p>
156
         *
157
         * @param visibility the boolean to be set
158
         *
159
         * @see #isVisible()
160
         * @see #visibleRequired()
161
         * @see #isAvailable()
162
         */
163
        void setVisible(boolean visibility);
164

    
165
        /**
166
         * <p>Returns if this layer is visible and available.</p>
167
         * <p>One layer is visible if it's check box associated is selected. This means
168
         *  that layer will tried to be painted.</p>
169
         * <p>One layer is available if the source of data is on-line.</p>
170
         * <p>It's probably that one layer selected hadn't available it's data, for example
171
         *  in a remote service.</p>
172
         *
173
         * @return <code>true</code> if this layer is visible and available; <code>false</code> otherwise
174
         *
175
         * @see #isAvailable()
176
         * @see #setAvailable(boolean)
177
         * @see #visibleRequired()
178
         */
179
        boolean isVisible();
180

    
181
        /**
182
         * Returns the parent {@link FLayers FLayers} node of this layer.
183
         *
184
         * @return the parent of this layer, or <code>null</code> if hasn't parent
185
         *
186
         * @see #setParentLayer(FLayers)
187
         */
188
        public FLayers getParentLayer();
189

    
190
        /**
191
         * <p>Returns a reference to the model of this layer, or null if this layer has no model.</p>
192
         *
193
         * @return the model of this layer
194
         */
195
        public MapContext getMapContext();
196

    
197
        /**
198
         * Inserts the parent {@link FLayers FLayers} node of the layer.
199
         *
200
         * @param root a <code>FLayers</code> object
201
         *
202
         * @see #getParentLayer()
203
         */
204
        public void setParentLayer(FLayers root);
205
        /**
206
         * Returns the full extension of the layer node.
207
         *
208
         * @return location and dimension of this layer node
209
         *
210
         * @throws ReadException if fails the driver used in this method.
211
         */
212
        Envelope getFullEnvelope() throws ReadException;
213

    
214
        /**
215
         * Draws the layer using a buffer.
216
         *
217
         * @param image an image used to accelerate the screen draw
218
         * @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
219
         * @param viewPort information for drawing this layer
220
         * @param cancel an object thread that implements the <code>Cancellable</code> interface, and will allow to cancel the draw
221
         * @param scale value that represents the scale
222
         *
223
         * @throws ReadException if fails the driver used in this method.
224
         *
225
         * @see #print(Graphics2D, ViewPort, Cancellable, double, PrintAttributes)
226
         */
227
        void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
228
                        Cancellable cancel,double scale) throws ReadException;
229

    
230
        /**
231
         * Prints this layer according to some properties requested.
232
         *
233
         * @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
234
         * @param viewPort the information for drawing the layers
235
         * @param cancel an object thread that implements the {@link Cancellable Cancellable} interface, and will allow to cancel the draw
236
         * @param scale the scale of the view. Must be between {@linkplain FLayer#getMinScale()} and {@linkplain FLayer#getMaxScale()}.
237
         * @param properties a set with the settings to be applied to a whole print job and to all the docs in the print job
238
         *
239
         * @throws ReadException if fails the driver used in this method.
240
         *
241
         * @see #draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
242
         */
243
        void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintAttributes properties)
244
        throws ReadException;
245

    
246
        /**
247
         * Inserts the transformation coordinates.
248
         *
249
         * @param ct transformation coordinates
250
         *
251
         * @see #getCoordTrans()
252
         */
253
        void setCoordTrans(ICoordTrans ct);
254

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

    
264
        /**
265
         * Adds a <code>LayerListener</code> to the listener list.
266
         *
267
         * @param o a layer listener
268
         *
269
         * @return <code>true</code> if hasn't been any problem during the insertion of the listener
270
         *
271
         * @see #getLayerListeners()
272
         * @see #removeLayerListener(LayerListener)
273
         */
274
        public boolean addLayerListener(LayerListener o);
275
        /**
276
         * Returns all <code>LayerListener</code>s of this layer as an array.
277
         *
278
         * @return an array with all layer listeners associated to this layer
279
         *
280
         * @see #addLayerListener(LayerListener)
281
         * @see #removeLayerListener(LayerListener)
282
         */
283
        public LayerListener[] getLayerListeners();
284
        /**
285
         * Removes the <code>LayerListener</code> argument from this layer.
286
         *
287
         * @param o a layer listener
288
         *
289
         * @return <code>true</code> if hasn't been any problem doing this process
290
         *
291
         * @see #addLayerListener(LayerListener)
292
         * @see #getLayerListeners()
293
         */
294
        public boolean removeLayerListener(LayerListener o);
295
        /**
296
         * <p>Returns if the value of <code>scale</code> argument
297
         *  is within the maximum and minimum scale of this layer.</p>
298
         *
299
         * @param scale the scale > 0
300
         *
301
         * @return <code>true</code> if the <code>scale</code> argument is within the range of scales of this layer; <code>false</code> otherwise
302
         *
303
         * @see #setMinScale(double)
304
         * @see #setMaxScale(double)
305
         */
306
        public boolean isWithinScale(double scale);
307

    
308

    
309
        /**
310
         * Returns the minimum scale visible. Lower scales won't be drawn.
311
         *
312
         * @return the minimum scale > 0, -1 if not defined
313
         *
314
         * @see #setMinScale(double)
315
         */
316
        public double getMinScale();
317

    
318
        /**
319
         * Returns the maximum scale visible. Higher scales won't be drawn.
320
         *
321
         * @return the maximum scale > 0, -1 if not defined
322
         *
323
         * @see #setMaxScale(double)
324
         */
325
        public double getMaxScale();
326
        /**
327
         * Sets the minimum scale visible. Lower scales won't be drawn.
328
         *
329
         * @param minScale the scale > 0, -1 if not defined
330
         *
331
         * @see #getMinScale()
332
         */
333
        public void setMinScale(double minScale);
334
        /**
335
         * Sets the maximum scale visible. Higher scales won't be drawn.
336
         *
337
         * @param maxScale the scale > 0, -1 if not defined
338
         *
339
         * @see #getMaxScale()
340
         */
341
        public void setMaxScale(double maxScale);
342
        /**
343
         * <p>Changes the status of this layer to editable or not.</p>
344
         * <p>One layer is editable if user can modify its information with graphical tools.</p>
345
         *
346
         * @param b the boolean to be set
347
         *
348
         * @throws com.iver.cit.gvsig.fmap.edition.EditionException if fails enabling for edition this kind of layer.
349
         *
350
         * @see #isEditing()
351
         * @deprecated Editing status is managed internally by layer, cannot be assigned here.
352
         */
353
        public void setEditing(boolean b) throws StartEditionLayerException;
354
        /**
355
         * <p>Returns if this layer is editable.</p>
356
         * <p>One layer is editable if user can modify its information with graphical tools.</p>
357
         *
358
         * @return <code>true</code> if this layer is editable; <code>false</code> otherwise
359
         *
360
         * @see #setEditing(boolean)
361
         */
362
        public boolean isEditing();
363

    
364
        /**
365
         * Returns the image icon that will be shown in the TOC next to this layer.
366
         *
367
         * @return a String reference to the image icon, or <code>null</code> if there isn't any
368
         */
369
        public String getTocImageIcon();
370

    
371
        /**
372
         * <p>Returns if this layer appears in the TOC.</p>
373
         * <p>If doesn't appears, remains in the view and in the project.</p>
374
         *
375
         * @return <code>true</code> if this layer appears in the TOC; <code>false</code> otherwise
376
         */
377
        boolean isInTOC();
378
        /**
379
         * <p>Sets that this layer appears or not in the TOC.</p>
380
         *
381
         * @param b <code>true</code> if appears in the TOC; <code>false</code> otherwise
382
         */
383
        void setInTOC(boolean b);
384
        /**
385
         * Returns the status of this layer.
386
         *
387
         * @return the status stored in a <code>FLayerStatus</code> object
388
         *
389
         * @see #setFLayerStatus(FLayerStatus)
390
         */
391
        public FLayerStatus getFLayerStatus();
392
        /**
393
         * Sets the status of this layer.
394
         *
395
         * @param status information of the status for this layer
396
         *
397
         * @see #getFLayerStatus()
398
         */
399
        public void setFLayerStatus(FLayerStatus status);
400
        /*
401
         * This stuff is to save error's info that causes
402
         * unavailable status.
403
         * */
404
        /**
405
         * <p>Returns if this layer hasn't got errors.</p>
406
         *
407
         * @return <code>true</code> if this layer hasn't got errors; <code>false</code> otherwise
408
         */
409
        public boolean isOk();
410
        /**
411
         * Returns the number of errors which causes this layer to be in unavailable status.
412
         *
413
         * @return number of errors >= 0
414
         *
415
         * @see #getError(int)
416
         * @see #getErrors()
417
         */
418
        public int getNumErrors();
419

    
420
        /**
421
         * Returns the specified error.
422
         *
423
         * @param i index of the error >= 0 && < <code>getNumErrors</code>
424
         *
425
         * @return a singular error
426
         *
427
         * @see #getNumErrors()
428
         * @see #getErrors()
429
         */
430
        public BaseException getError(int i);
431

    
432
    /**
433
     * Adds an error reason that describes this layer's wrong status.
434
     * 
435
     * @param error
436
     *            a <code>BaseException</code> with the information of the error
437
     * 
438
     * @see #getNumErrors()
439
     * @see #getError(int)
440
     * @see #getErrors()
441
     */
442
        public void addError(BaseException exception);
443

    
444
        /**
445
         * Returns a list with all layer errors.
446
         *
447
         * @return an <code>ArrayList</code> with the errors
448
         *
449
         * @see #getError(int)
450
         * @see #getNumErrors()
451
         */
452
        public List getErrors();
453
        /**
454
         * <p>Changes the status of availability of this layer.</p>
455
         * <p>One layer is available if the source of data is on-line.</p>
456
         *
457
         * @param the boolean to be set
458
         *
459
         * @see #isAvailable()
460
         */
461
        public void setAvailable(boolean available);
462
        /**
463
         * <p>Returns the status of availability of this layer.</p>
464
         * <p>One layer is available if the source of data is on-line.</p>
465
         *
466
         * @return <code>true</code> if the source of data is on-line; <code>false</code> otherwise
467
         *
468
         * @see #setAvailable(boolean)
469
         * @see #isVisible()
470
         */
471
        public boolean isAvailable();
472

    
473
    /**
474
     * <p>
475
     * Tries recover a layer of a possible error.
476
     * </p>
477
     * <p>
478
     * If it has any problem during the load, marks the availability to false
479
     * and throws an exception.
480
     * </p>
481
     * 
482
     * @throws ReloadLayerException
483
     *             if it's thrown a <code>ReadException</code> or an
484
     *             <code>IOException</code> during the load of this layer.
485
     * 
486
     * @see #load()
487
     */
488
        public void reload() throws ReloadLayerException;
489

    
490
        /**
491
         * Returns <code>true</code> if this layer has the visible status enabled.
492
         *
493
         * @return <code>true</code> if visible this layer has the visible status enabled, otherwise <code>false</code>
494
         *
495
         * @see #isVisible()
496
         * @see #setVisible(boolean)
497
         */
498
        boolean visibleRequired();
499
        /**
500
         * Returns an string with the information of this layer.
501
         *
502
         * @return the string that is to be this component's information
503
         */
504
        public String getInfoString();
505
        /**
506
         * <p>Returns the writing status of this layer.</p>
507
         * <p>One layer is writable if there is a writing driver for this layer.</p>
508
         *
509
         * @return <code>true</code> if there is a writing driver for this layer; <code>false</code> otherwise
510
         */
511
        public boolean isWritable();
512

    
513
        /**
514
         * <p>This method can be used to have a fast cloned layer.</p>
515
         * <p>The implementations should take care of not recreate this layer. Instead of this,
516
         *  is better to use the same source (driver) and <i>deepclone</i> the legend. Exception:
517
         *   the labels aren't <i>deepcloned</i> to avoid memory consumption.</p>
518
         * <p><i>Note</i>: Labels are memory consuming to speed up layers like PostGIS and so on.</p>
519
         *
520
         * @return a layer that is a clonation of this layer
521
         *
522
         * @throws java.lang.Exception any exception produced during the cloning of this layer.
523
         */
524
        public FLayer cloneLayer() throws Exception;
525

    
526

    
527

    
528
        /**
529
         * <p>Returns a reference to an object (property) associated to this layer.</p>
530
         *
531
         * <p>For example, you can attach a network definition to key "network" and check
532
         *  if a layer has a network loaded using <i>getAssociatedObject("network")</i> and
533
         *  that it's not null.</p>
534
         *
535
         * @param key the key associated to the property
536
         *
537
         * @return <code>null</code> if key is not found
538
         *
539
         * @see #getExtendedProperties()
540
         * @see #setProperty(Object, Object)
541
         */
542
        public Object getProperty(Object key);
543

    
544
        /**
545
         * Insets an object as a property to this layer.
546
         *
547
         * @param key the key associated to the property
548
         * @param obj the property
549
         *
550
         * @see #getProperty(Object)
551
         * @see #getExtendedProperties()
552
         */
553
        public void setProperty(Object key, Object obj);
554
        /**
555
         * Returns a hash map with all new properties associated to this layer.
556
         *
557
         * @return hash table with the added properties
558
         *
559
         * @see #getProperty(Object)
560
         * @see #setProperty(Object, Object)
561
         */
562
        public Map getExtendedProperties();
563

    
564
        /**
565
         * <p>Returns a new instance of {@link ComposedLayer ComposedLayer}.</p>
566
         *
567
         * <p>This allows make a single draw for a group
568
         * of layers with the same source.</p>
569
         *
570
         * <p>If this operation isn't applicable for this
571
         * kind of layer, this method returns null.</p>
572
         *
573
         * <p>By default this operation is not supported.</p>
574
         *
575
         * @see org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer
576
         *
577
         * @return a new composed layer or <code>null</code> if not supported
578
         */
579
        public ComposedLayer  newComposedLayer();
580

    
581
        /**
582
         * Returns the image icon that will be shown in the TOC next to this layer, according its status.
583
         *
584
         * @return the image
585
         */
586
        Image getTocStatusImage();
587

    
588
//        M?todos para la utilizaci?n de HyperLinks
589

    
590
        /**
591
         * Returns information about if the layer allows HyperLink or not
592
         * @return boolean true if allows Link, false if not
593
         */
594
        public boolean allowLinks();
595

    
596
        /**
597
         * Returns an instance of AbstractLinkProperties that contains the information
598
         * of the HyperLink
599
         * @return Abstra
600
         */
601
        public AbstractLinkProperties getLinkProperties();
602

    
603
        /**
604
         * Provides an array with URIs. Returns one URI by geometry that includes the point
605
         * in its own geometry limits with a allowed tolerance.
606
         * @param layer, the layer
607
         * @param point, the point to check that is contained or not in the geometries in the layer
608
         * @param tolerance, the tolerance allowed. Allowed margin of error to detect if the  point
609
         *                 is contained in some geometries of the layer
610
         * @return
611
         * @throws ReadException
612
         * @throws BehaviorException
613
         */
614
        public URI[] getLink(Point2D point, double tolerance) throws ReadException;
615

    
616

    
617
        /**
618
         * <p>Inserts the projection to this layer.</p>
619
         *
620
         * @param proj information about the new projection
621
         *
622
         */
623
        public void setProjection(IProjection proj);
624
        
625
        public long getDrawVersion();
626
        
627
}