Statistics
| Revision:

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

History | View | Annotate | Download (8.65 KB)

1
/*
2
 * Created on 01-sep-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: FLayerStatus.java 20989 2008-05-28 11:05:57Z jmvivo $
47
* $Log$
48
* Revision 1.2  2007-03-06 17:08:55  caballero
49
* Exceptions
50
*
51
* Revision 1.1  2006/09/21 17:23:39  azabala
52
* First version in cvs
53
*
54
*
55
*/
56
package org.gvsig.fmap.mapcontext.layers;
57

    
58
import java.util.ArrayList;
59
import java.util.List;
60

    
61
import org.gvsig.tools.exception.BaseException;
62

    
63

    
64
/**
65
 * <p>All layers in <i>libFMap</i> can be in a set of <i>states</i>, that their combination represent the <i>status</i> of a layer.</p>
66
 * 
67
 * <p><code>FLayerStatus</code> class supports the common status for all kind of {@link FLyrDefault FLyrDefault} layers.</p>
68
 * 
69
 * <p>This means that not necessarily all layers can stay in all possible status, it depends on its particular
70
 * nature.</p>
71
 * 
72
 * <p>Layer status states defined in <code>FLayerStatus</code> are:
73
 *  <ul>
74
 *  <li><i><b>Available</b></i>: the layer is available if the source of its data is on-line.</li>
75
 *  <li><i><b>Visible</b></i>: one layer is visible if it's selected its <i>check box</i> associated in TOC. This implies that 
76
 *  layer will be called to be painted unless the necessary data would be unavailable; this situation is more frequent with layers of
77
 *  remote services.</li>
78
 *  <li><i><b>Active</b></i>: is active if it's selected at the TOC.</li>
79
 *  <li><i><b>Dirty</b></i>: is dirty if needs to be refreshed.</li>
80
 *  <li><i><b>In TOC</b></i>: if it's being listed in a TOC GUI.</li>
81
 *  <li><i><b>Editing</b></i>: if the layer it's being edited now.</li>
82
 *  <li><i><b>Writable</b></i>: if can be modified and saved the changes.</li>
83
 *  <li><i><b>Cache drawn layers</b></i>: if stores previous draws. This is useful to accelerate the draw of the layer.</li>
84
 *  <li><i><b>Driver loaded</b></i>: if driver for managing the layer has been loaded successfully.</li>
85
 *  </ul>
86
 * </p>
87
 * 
88
 * @see IFLayerStatus
89
 * 
90
 * @author azabala
91
 */
92
public class FLayerStatus implements IFLayerStatus {
93
        /**
94
         * <p>Layer's availability: the layer is available if the source of its data is on-line.</p>
95
         */
96
        public boolean available;
97
        
98
        /**
99
         * <p>Layer's visibility: the layer is visible if it's selected its <i>check box</i> associated in TOC. This implies that 
100
         *  layer will tried to be painted unless the necessary data would be unavailable; this situation is more frequent with layers of
101
         *  remote services.</p>
102
         */
103
        public boolean visible;
104
        
105
        /**
106
         * <p>The layer is active if it's selected at the TOC.</p>
107
         */
108
        public boolean active;
109
        
110
        /**
111
         * <p>One layer is dirty if needs to be refreshed.</p>
112
         */
113
        public boolean dirty;
114
        
115
        /**
116
         * <p>The layer is in TOC if it's being listed in a TOC GUI.</p>
117
         */
118
        public boolean inTOC;
119
        
120
        /**
121
         * <p>This parameter reports if the layer it's being edited now.</p>
122
         */
123
        public boolean editing;
124
        
125
        /**
126
         * <p>This parameter reports if the layer can be modified and saved the changes.</p>
127
         */
128
        public boolean writable;
129
        
130
        /**
131
         * <p>This state reports if the layer stores previous draws. That's useful to accelerate the draw of the layer.</p>
132
         */
133
        public boolean cacheDrawnLayers;
134

    
135
        
136
        /**
137
         * <p>List with the information of the driver errors produced working this layer.</p>
138
         */
139
        private ArrayList layerErrors;
140
                
141
        /**
142
         * <p>This state reports if the driver for managing the layer has been loaded successfully.</p>
143
         */
144
        private boolean driverLoaded=true;
145

    
146
        /**
147
         * <p>Creates an instance with the default status of a <code>FLyrDefault</code> layer:
148
         * <br>
149
         *  <ul>
150
         *  <li><b><i>Visible</i></b>: <code>true</code> .</li>
151
         *  <li><b><i>Active</i></b>: <code>false</code> .</li>
152
         *  <li><b><i>In TOC</i></b>: <code>true</code> .</li>
153
         *  <li><b><i>Editing</i></b>: <code>false</code> .</li>
154
         *  <li><b><i>Cache drawn layers</i></b>: <code>false</code> .</li>
155
         *  <li><b><i>Dirty</i></b>: <code>false</code> .</li>
156
         *  <li><b><i>Available</i></b>: <code>true</code> .</li>
157
         *  <li><b><i>Driver loaded</i></b>: <code>true</code> .</li>
158
         *  <li><b><i>Writable</i></b>: <code>false</code> .</li>
159
         *  <li>Without driver errors.</li>
160
         *  </ul>
161
         * </p>
162
         */
163
        public FLayerStatus(){
164
                this.layerErrors = new ArrayList();
165
                visible = true;
166
                active = false;
167
                inTOC = true;
168
                editing = false;
169
                cacheDrawnLayers = false;
170
                dirty = false;
171
                available = true;
172

    
173
                writable = false;
174

    
175
        }
176

    
177
        /**
178
         * <p>Stores information of an exception produced working with a driver of the layer.</p>
179
         * 
180
         * @param error the driver exception
181
         */
182
        public void addLayerError(BaseException error){
183
                layerErrors.add(error);
184
        }
185

    
186
        public FLayerStatus cloneStatus(){
187
                FLayerStatus newStatus = new FLayerStatus();
188
                newStatus.layerErrors.addAll(this.layerErrors);
189
                newStatus.visible = this.visible;
190
                newStatus.active = this.active;
191
                newStatus.inTOC = this.inTOC;
192
                newStatus.editing = this.editing;
193
                newStatus.cacheDrawnLayers = this.cacheDrawnLayers;
194
                newStatus.dirty = this.dirty;
195
                newStatus.available = this.available;
196
                newStatus.driverLoaded = this.driverLoaded;        
197
                newStatus.writable = this.writable;
198
        
199
                return newStatus;
200
        }
201
        
202
        
203

    
204
        public boolean equals(Object obj) {
205
                FLayerStatus other;
206
                if (obj instanceof FLayerStatus) {
207
                        other = (FLayerStatus) obj;
208
                } else{
209
                        return false;
210
                }
211

    
212
                if (other.visible != this.visible 
213
                                || other.active != this.active
214
                                || other.inTOC != this.inTOC || other.editing != this.editing
215
                                || other.cacheDrawnLayers != this.cacheDrawnLayers
216
                                || other.dirty != this.dirty
217
                                || other.available != this.available
218
                                || other.driverLoaded != this.driverLoaded
219
                                || other.writable != this.writable) {
220
                        return false;
221
                }
222
                
223

    
224
                
225
                if ((!other.layerErrors.containsAll(this.layerErrors)) || other.layerErrors.size() != this.layerErrors.size()){
226
                        return false;
227
                }
228
                return super.equals(obj);
229
        }
230

    
231
        /**
232
         * <p>Gets the number of driver exceptions produced working with the layer.</p>
233
         * 
234
         * @return number of driver exceptions produced
235
         */
236
        public int getNumErrors(){
237
                return layerErrors.size();
238
        }
239

    
240
        /**
241
         * <p>Gets the information of the <i>nth</i> layer driver exception registered in the status.</p>
242
         * 
243
         * @param i ith layer exception registered
244
         * 
245
         * @return the <i>nth</i> layer driver exception registered
246
         */
247
        public BaseException getError(int i){
248
                return (BaseException) layerErrors.get(i);
249
        }
250

    
251
        /**
252
         * <p>Returns if there have been driver errors working with the layer.</p>
253
         * 
254
         * @return <code>true</code> if there have driver errors working with the layer; otherwise <code>false</code>
255
         */
256
        public boolean isOk(){
257
                return layerErrors.size() == 0;
258
        }
259

    
260
        /**
261
         * <p>Returns a list of errors produced in a layer working with its driver.</p>
262
         * 
263
         * @return list errors produced in a layer working with its driver
264
         */
265
        public List getErrors() {
266
                return layerErrors;
267
        }
268

    
269
        /**
270
         * <p>Returns if has been loaded successfully the driver for managing the layer.</p>
271
         * 
272
         * @return <code>true</code> if has been loaded successfully the driver for managing the layer; otherwise <code>false</code>
273
         */
274
        public boolean isDriverLoaded() {
275
                return driverLoaded;
276
        }
277

    
278
        /**
279
         * <p>Sets if has been loaded successfully the driver for managing the layer.</p>
280
         * 
281
         * @param driverLoaded <code>true</code> if has been loaded successfully the driver for managing the layer; otherwise <code>false</code>
282
         */
283
        public void setDriverLoaded(boolean driverLoaded) {
284
                this.driverLoaded = driverLoaded;
285
        }
286
}
287