Statistics
| Revision:

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

History | View | Annotate | Download (19.6 KB)

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

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

    
69
import com.iver.utiles.IPersistence;
70
import com.iver.utiles.XMLEntity;
71
import com.iver.utiles.XMLException;
72

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

    
90

    
91
        /**
92
         * <p>Returns an entity that represents this layer.</p>
93
         *
94
         * <p>This XML entity has elements that represent and store information about this layer.</p>
95
         *
96
         * @return an XML entity with information of this layer
97
         * @throws XMLException if there is an error obtaining the object.
98
         *
99
         * @see #setXMLEntity(XMLEntity)
100
         * @see #setXMLEntity03(XMLEntity)
101
         */
102
        XMLEntity getXMLEntity() throws XMLException;
103

    
104
        /**
105
         * <p>Inserts information to this layer from an XML entity.</p>
106
         *
107
         * <p>This XML entity has elements that represent and store information about this layer.</p>
108
         *
109
         * @param xml an <code>XMLEntity</code> with the information
110
         *
111
         * @throws XMLException if there is an error setting the object.
112
         *
113
         * @see #getXMLEntity()
114
         * @see #setXMLEntity03(XMLEntity)
115
         */
116
        void setXMLEntity(XMLEntity xml) throws XMLException;
117

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

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

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

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

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

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

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

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

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

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

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

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

    
269
        /**
270
         * Returns the transformation coordinates.
271
         *
272
         * @return transformation coordinates
273
         *
274
         * @see #setCoordTrans(ICoordTrans)
275
         */
276
        ICoordTrans getCoordTrans();
277

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

    
322

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

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

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

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

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

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

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

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

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

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

    
539

    
540

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

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

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

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

    
601
//        M?todos para la utilizaci?n de HyperLinks
602

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

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

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

    
629

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