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 @ 44050

History | View | Annotate | Download (17.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
 * Definition of the basic functionality that all kind of layers should implement.
57
 * <br>
58
 * 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.
60
 * <br>
61
 * 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.
63
 * <br>
64
 * Each particular implementation can add new properties, and limit or expand the functionality.</p
65
 * <br>
66
 * @see Projected
67
 */
68
public interface FLayer extends Projected, Persistent, Metadata, Disposable, ExtendedPropertiesSupport
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
         * <p>Changes the status of this layer to active or inactive.</p>
78
         * <p>One layer is active if is selected in TOC.</p>
79
         *
80
         * @param selected the boolean to be set
81
         *
82
         * @see #isActive()
83
         */
84
        void setActive(boolean selected);
85

    
86
        /**
87
         * <p>Returns if this layer is active or not in TOC.</p>
88
         * <p>One layer is active if is selected in TOC.</p>
89
         *
90
         * @return <code>true</code> if this layer is active; <code>false</code> otherwise
91
         *
92
         * @see #setActive(boolean)
93
         */
94
        boolean isActive();
95

    
96
        /**
97
         * Sets a name to this layer.
98
         *
99
         * @param name the string that is to be this layer's name
100
         *
101
         * @see #getName()
102
         */
103
        void setName(String name);
104

    
105
        /**
106
         * Returns the name of this layer.
107
         *
108
         * @return an string with this layer's name
109
         *
110
         * @see #setName(String)
111
         */
112
        String getName();
113

    
114
        /**
115
         * <p>Executes the initialization operations of this layer. This method is invoked
116
         * only one time during the life of this layer and just before visualize it.</p>
117
         *
118
         * @throws LoadLayerException if fails loading the layer.
119
         *
120
         * @see #reload()
121
         */
122
        void load() throws LoadLayerException;
123
        /**
124
         * <p>Changes the status of this layer to visible or not.</p>
125
         * <p>One layer is visible if it's check box associated is selected. This means
126
         *  that layer will tried to be painted. If the data associated isn't available,
127
         *  then this property will change to <code>false</code>.</p>
128
         *
129
         * @param visibility the boolean to be set
130
         *
131
         * @see #isVisible()
132
         * @see #visibleRequired()
133
         * @see #isAvailable()
134
         */
135
        void setVisible(boolean visibility);
136

    
137
        /**
138
         * <p>Returns if this layer is visible and available.</p>
139
         * <p>One layer is visible if it's check box associated is selected. This means
140
         *  that layer will tried to be painted.</p>
141
         * <p>One layer is available if the source of data is on-line.</p>
142
         * <p>It's probably that one layer selected hadn't available it's data, for example
143
         *  in a remote service.</p>
144
         *
145
         * @return <code>true</code> if this layer is visible and available; <code>false</code> otherwise
146
         *
147
         * @see #isAvailable()
148
         * @see #setAvailable(boolean)
149
         * @see #visibleRequired()
150
         */
151
        boolean isVisible();
152

    
153
        /**
154
         * Returns the parent {@link FLayers FLayers} node of this layer.
155
         *
156
         * @return the parent of this layer, or <code>null</code> if hasn't parent
157
         *
158
         * @see #setParentLayer(FLayers)
159
         */
160
        public FLayers getParentLayer();
161

    
162
        /**
163
         * <p>Returns a reference to the model of this layer, or null if this layer has no model.</p>
164
         *
165
         * @return the model of this layer
166
         */
167
        public MapContext getMapContext();
168

    
169
        /**
170
         * Inserts the parent {@link FLayers FLayers} node of the layer.
171
         *
172
         * @param root a <code>FLayers</code> object
173
         *
174
         * @see #getParentLayer()
175
         */
176
        public void setParentLayer(FLayers root);
177
        /**
178
         * Returns the full extension of the layer node.
179
         *
180
         * @return location and dimension of this layer node
181
         *
182
         * @throws ReadException if fails the driver used in this method.
183
         */
184
        Envelope getFullEnvelope() throws ReadException;
185

    
186
        /**
187
         * Draws the layer using a buffer.
188
         *
189
         * @param image an image used to accelerate the screen draw
190
         * @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
191
         * @param viewPort information for drawing this layer
192
         * @param cancel an object thread that implements the <code>Cancellable</code> interface, and will allow to cancel the draw
193
         * @param scale value that represents the scale
194
         *
195
         * @throws ReadException if fails the driver used in this method.
196
         *
197
         * @see #print(Graphics2D, ViewPort, Cancellable, double, PrintAttributes)
198
         */
199
        void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
200
                        Cancellable cancel,double scale) throws ReadException;
201

    
202
        /**
203
         * Prints this layer according to some properties requested.
204
         *
205
         * @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
206
         * @param viewPort the information for drawing the layers
207
         * @param cancel an object thread that implements the {@link Cancellable Cancellable} interface, and will allow to cancel the draw
208
         * @param scale the scale of the view. Must be between {@linkplain FLayer#getMinScale()} and {@linkplain FLayer#getMaxScale()}.
209
         * @param properties a set with the settings to be applied to a whole print job and to all the docs in the print job
210
         *
211
         * @throws ReadException if fails the driver used in this method.
212
         *
213
         * @see #draw(BufferedImage, Graphics2D, ViewPort, Cancellable, double)
214
         */
215
        void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintAttributes properties)
216
        throws ReadException;
217

    
218
        /**
219
         * Inserts the transformation coordinates.
220
         *
221
         * @param ct transformation coordinates
222
         *
223
         * @see #getCoordTrans()
224
         */
225
        void setCoordTrans(ICoordTrans ct);
226

    
227
        /**
228
         * Returns the transformation coordinates.
229
         *
230
         * @return transformation coordinates
231
         *
232
         * @see #setCoordTrans(ICoordTrans)
233
         */
234
        ICoordTrans getCoordTrans();
235

    
236
        /**
237
         * Returns layer tolerance in pixels
238
         *
239
         * @return layer tolerance
240
         *
241
         */
242
        public int getDefaultTolerance();
243
        
244
        /**
245
         * Adds a <code>LayerListener</code> to the listener list.
246
         *
247
         * @param o a layer listener
248
         *
249
         * @return <code>true</code> if hasn't been any problem during the insertion of the listener
250
         *
251
         * @see #getLayerListeners()
252
         * @see #removeLayerListener(LayerListener)
253
         */
254
        public boolean addLayerListener(LayerListener o);
255
        /**
256
         * Returns all <code>LayerListener</code>s of this layer as an array.
257
         *
258
         * @return an array with all layer listeners associated to this layer
259
         *
260
         * @see #addLayerListener(LayerListener)
261
         * @see #removeLayerListener(LayerListener)
262
         */
263
        public LayerListener[] getLayerListeners();
264
        /**
265
         * Removes the <code>LayerListener</code> argument from this layer.
266
         *
267
         * @param o a layer listener
268
         *
269
         * @return <code>true</code> if hasn't been any problem doing this process
270
         *
271
         * @see #addLayerListener(LayerListener)
272
         * @see #getLayerListeners()
273
         */
274
        public boolean removeLayerListener(LayerListener o);
275
        /**
276
         * <p>Returns if the value of <code>scale</code> argument
277
         *  is within the maximum and minimum scale of this layer.</p>
278
         *
279
         * @param scale the scale > 0
280
         *
281
         * @return <code>true</code> if the <code>scale</code> argument is within the range of scales of this layer; <code>false</code> otherwise
282
         *
283
         * @see #setMinScale(double)
284
         * @see #setMaxScale(double)
285
         */
286
        public boolean isWithinScale(double scale);
287

    
288

    
289
        /**
290
         * Returns the minimum scale visible. Lower scales won't be drawn.
291
         *
292
         * @return the minimum scale > 0, -1 if not defined
293
         *
294
         * @see #setMinScale(double)
295
         */
296
        public double getMinScale();
297

    
298
        /**
299
         * Returns the maximum scale visible. Higher scales won't be drawn.
300
         *
301
         * @return the maximum scale > 0, -1 if not defined
302
         *
303
         * @see #setMaxScale(double)
304
         */
305
        public double getMaxScale();
306
        /**
307
         * Sets the minimum scale visible. Lower scales won't be drawn.
308
         *
309
         * @param minScale the scale > 0, -1 if not defined
310
         *
311
         * @see #getMinScale()
312
         */
313
        public void setMinScale(double minScale);
314
        /**
315
         * Sets the maximum scale visible. Higher scales won't be drawn.
316
         *
317
         * @param maxScale the scale > 0, -1 if not defined
318
         *
319
         * @see #getMaxScale()
320
         */
321
        public void setMaxScale(double maxScale);
322

    
323
        /**
324
         * <p>Returns if this layer is editable.</p>
325
         * <p>One layer is editable if user can modify its information with graphical tools.</p>
326
         *
327
         * @return <code>true</code> if this layer is editable; <code>false</code> otherwise
328
         *
329
         * @see #setEditing(boolean)
330
         */
331
        public boolean isEditing();
332

    
333
        /**
334
         * Returns the image icon that will be shown in the TOC next to this layer.
335
         *
336
         * @return a String reference to the image icon, or <code>null</code> if there isn't any
337
         */
338
        public String getTocImageIcon();
339

    
340
        /**
341
         * <p>Returns if this layer appears in the TOC.</p>
342
         * <p>If doesn't appears, remains in the view and in the project.</p>
343
         *
344
         * @return <code>true</code> if this layer appears in the TOC; <code>false</code> otherwise
345
         */
346
        boolean isInTOC();
347
        /**
348
         * <p>Sets that this layer appears or not in the TOC.</p>
349
         *
350
         * @param b <code>true</code> if appears in the TOC; <code>false</code> otherwise
351
         */
352
        void setInTOC(boolean b);
353
        /**
354
         * Returns the status of this layer.
355
         *
356
         * @return the status stored in a <code>FLayerStatus</code> object
357
         *
358
         * @see #setFLayerStatus(FLayerStatus)
359
         */
360
        public FLayerStatus getFLayerStatus();
361
        /**
362
         * Sets the status of this layer.
363
         *
364
         * @param status information of the status for this layer
365
         *
366
         * @see #getFLayerStatus()
367
         */
368
        public void setFLayerStatus(FLayerStatus status);
369
        /*
370
         * This stuff is to save error's info that causes
371
         * unavailable status.
372
         * */
373
        /**
374
         * <p>Returns if this layer hasn't got errors.</p>
375
         *
376
         * @return <code>true</code> if this layer hasn't got errors; <code>false</code> otherwise
377
         */
378
        public boolean isOk();
379
        /**
380
         * Returns the number of errors which causes this layer to be in unavailable status.
381
         *
382
         * @return number of errors >= 0
383
         *
384
         * @see #getError(int)
385
         * @see #getErrors()
386
         */
387
        public int getNumErrors();
388

    
389
        /**
390
         * Returns the specified error.
391
         *
392
         * @param i index of the error >= 0 && < <code>getNumErrors</code>
393
         *
394
         * @return a singular error
395
         *
396
         * @see #getNumErrors()
397
         * @see #getErrors()
398
         */
399
        public Throwable getError(int i);
400

    
401
    /**
402
     * Adds an error reason that describes this layer's wrong status.
403
     * 
404
     * @param exception
405
     *            a <code>BaseException</code> with the information of the error
406
     * 
407
     * @see #getNumErrors()
408
     * @see #getError(int)
409
     * @see #getErrors()
410
     */
411
        public void addError(Throwable exception);
412

    
413
    public void setError(Throwable ex);
414
        
415
        /**
416
         * Returns a list with all layer errors.
417
         *
418
         * @return an <code>ArrayList</code> with the errors
419
         *
420
         * @see #getError(int)
421
         * @see #getNumErrors()
422
         */
423
        public List<Throwable> getErrors();
424
        /**
425
         * <p>Changes the status of availability of this layer.</p>
426
         * <p>One layer is available if the source of data is on-line.</p>
427
         *
428
         * @param available the boolean to be set
429
         *
430
         * @see #isAvailable()
431
         */
432
        public void setAvailable(boolean available);
433
        /**
434
         * <p>Returns the status of availability of this layer.</p>
435
         * <p>One layer is available if the source of data is on-line.</p>
436
         *
437
         * @return <code>true</code> if the source of data is on-line; <code>false</code> otherwise
438
         *
439
         * @see #setAvailable(boolean)
440
         * @see #isVisible()
441
         */
442
        public boolean isAvailable();
443

    
444
    /**
445
     * <p>
446
     * Tries recover a layer of a possible error.
447
     * </p>
448
     * <p>
449
     * If it has any problem during the load, marks the availability to false
450
     * and throws an exception.
451
     * </p>
452
     * 
453
     * @throws ReloadLayerException
454
     *             if it's thrown a <code>ReadException</code> or an
455
     *             <code>IOException</code> during the load of this layer.
456
     * 
457
     * @see #load()
458
     */
459
        public void reload() throws ReloadLayerException;
460

    
461
        /**
462
         * Returns <code>true</code> if this layer has the visible status enabled.
463
         *
464
         * @return <code>true</code> if visible this layer has the visible status enabled, otherwise <code>false</code>
465
         *
466
         * @see #isVisible()
467
         * @see #setVisible(boolean)
468
         */
469
        boolean visibleRequired();
470
        /**
471
         * Returns an string with the information of this layer.
472
         *
473
         * @return the string that is to be this component's information
474
         */
475
        public String getInfoString();
476
        /**
477
         * <p>Returns the writing status of this layer.</p>
478
         * <p>One layer is writable if there is a writing driver for this layer.</p>
479
         *
480
         * @return <code>true</code> if there is a writing driver for this layer; <code>false</code> otherwise
481
         */
482
        public boolean isWritable();
483

    
484
        /**
485
         * <p>This method can be used to have a fast cloned layer.</p>
486
         * <p>The implementations should take care of not recreate this layer. Instead of this,
487
         *  is better to use the same source (driver) and <i>deepclone</i> the legend. Exception:
488
         *   the labels aren't <i>deepcloned</i> to avoid memory consumption.</p>
489
         * <p><i>Note</i>: Labels are memory consuming to speed up layers like PostGIS and so on.</p>
490
         *
491
         * @return a layer that is a clonation of this layer
492
         *
493
         * @throws java.lang.Exception any exception produced during the cloning of this layer.
494
         */
495
        public FLayer cloneLayer() throws Exception;
496

    
497
        /**
498
         * <p>Returns a new instance of {@link ComposedLayer ComposedLayer}.</p>
499
         *
500
         * <p>This allows make a single draw for a group
501
         * of layers with the same source.</p>
502
         *
503
         * <p>If this operation isn't applicable for this
504
         * kind of layer, this method returns null.</p>
505
         *
506
         * <p>By default this operation is not supported.</p>
507
         *
508
         * @see org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer
509
         *
510
         * @return a new composed layer or <code>null</code> if not supported
511
         */
512
        public ComposedLayer  newComposedLayer();
513

    
514
        /**
515
         * Returns the image icon that will be shown in the TOC next to this layer, according its status.
516
         *
517
         * @return the image
518
         */
519
        Image getTocStatusImage();
520

    
521
        /**
522
         * <p>Sets the projection to this layer.</p>
523
         *
524
         * @param proj information about the new projection
525
         *
526
         */
527
        public void setProjection(IProjection proj);
528
        
529
        public long getDrawVersion();
530

    
531
        public boolean isTemporary();
532
        
533
        public void setTemporary(boolean temporary);
534
        
535
        /**
536
         * Do nothing.
537
         * 
538
         * @param b
539
         * @throws org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException
540
         * @deprecated Editing status is managed internally by layer, cannot be assigned here.
541
         */
542
        public void setEditing(boolean b) throws StartEditionLayerException;
543
        
544
        /**
545
         * Alwais return false
546
         * @return false
547
         * @deprecated see https://redmine.gvsig.net/redmine/projects/gvsig-hyperlink
548
         */
549
        public boolean allowLinks();
550

    
551
        /**
552
         * Alwais return null.
553
         * @return null
554
         * @deprecated see https://redmine.gvsig.net/redmine/projects/gvsig-hyperlink
555
         */
556
        public AbstractLinkProperties getLinkProperties();
557

    
558
        /**
559
         * alwais return null
560
         * 
561
         * @param point
562
         * @param tolerance
563
         * @return null
564
         * @throws org.gvsig.fmap.dal.exception.ReadException
565
         * @deprecated see https://redmine.gvsig.net/redmine/projects/gvsig-hyperlink
566
         */
567
        public URI[] getLink(Point2D point, double tolerance) throws ReadException;
568

    
569

    
570

    
571
}