Statistics
| Revision:

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

History | View | Annotate | Download (10.7 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.ToolsLocator;
62
import org.gvsig.tools.dynobject.DynStruct;
63
import org.gvsig.tools.exception.BaseException;
64
import org.gvsig.tools.persistence.PersistenceManager;
65
import org.gvsig.tools.persistence.PersistentState;
66
import org.gvsig.tools.persistence.exception.PersistenceException;
67

    
68

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

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

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

    
178
                writable = false;
179

    
180
        }
181

    
182
        /**
183
         * <p>Stores information of an exception produced working with a driver of the layer.</p>
184
         * 
185
         * @param error the driver exception
186
         */
187
        public void addLayerError(BaseException error){
188
                layerErrors.add(error);
189
        }
190

    
191
        public FLayerStatus cloneStatus(){
192
                FLayerStatus newStatus = new FLayerStatus();
193
                newStatus.layerErrors.addAll(this.layerErrors);
194
                newStatus.visible = this.visible;
195
                newStatus.active = this.active;
196
                newStatus.inTOC = this.inTOC;
197
                newStatus.editing = this.editing;
198
                newStatus.cacheDrawnLayers = this.cacheDrawnLayers;
199
                newStatus.dirty = this.dirty;
200
                newStatus.available = this.available;
201
                newStatus.driverLoaded = this.driverLoaded;        
202
                newStatus.writable = this.writable;
203
        
204
                return newStatus;
205
        }
206
        
207
        
208

    
209
        public boolean equals(Object obj) {
210
                FLayerStatus other;
211
                if (obj instanceof FLayerStatus) {
212
                        other = (FLayerStatus) obj;
213
                } else{
214
                        return false;
215
                }
216

    
217
                if (other.visible != this.visible 
218
                                || other.active != this.active
219
                                || other.inTOC != this.inTOC || other.editing != this.editing
220
                                || other.cacheDrawnLayers != this.cacheDrawnLayers
221
                                || other.dirty != this.dirty
222
                                || other.available != this.available
223
                                || other.driverLoaded != this.driverLoaded
224
                                || other.writable != this.writable) {
225
                        return false;
226
                }
227
                
228

    
229
                
230
                if ((!other.layerErrors.containsAll(this.layerErrors)) || other.layerErrors.size() != this.layerErrors.size()){
231
                        return false;
232
                }
233
                return super.equals(obj);
234
        }
235

    
236
        /**
237
         * <p>Gets the number of driver exceptions produced working with the layer.</p>
238
         * 
239
         * @return number of driver exceptions produced
240
         */
241
        public int getNumErrors(){
242
                return layerErrors.size();
243
        }
244

    
245
        /**
246
         * <p>Gets the information of the <i>nth</i> layer driver exception registered in the status.</p>
247
         * 
248
         * @param i ith layer exception registered
249
         * 
250
         * @return the <i>nth</i> layer driver exception registered
251
         */
252
        public BaseException getError(int i){
253
                return (BaseException) layerErrors.get(i);
254
        }
255

    
256
        /**
257
         * <p>Returns if there have been driver errors working with the layer.</p>
258
         * 
259
         * @return <code>true</code> if there have driver errors working with the layer; otherwise <code>false</code>
260
         */
261
        public boolean isOk(){
262
                return layerErrors.size() == 0;
263
        }
264

    
265
        /**
266
         * <p>Returns a list of errors produced in a layer working with its driver.</p>
267
         * 
268
         * @return list errors produced in a layer working with its driver
269
         */
270
        public List getErrors() {
271
                return layerErrors;
272
        }
273

    
274
        /**
275
         * <p>Returns if has been loaded successfully the driver for managing the layer.</p>
276
         * 
277
         * @return <code>true</code> if has been loaded successfully the driver for managing the layer; otherwise <code>false</code>
278
         */
279
        public boolean isDriverLoaded() {
280
                return driverLoaded;
281
        }
282

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

    
292
        public void loadFromState(PersistentState state)
293
                        throws PersistenceException {
294

    
295
                visible = state.getBoolean("visible");
296
                active = state.getBoolean("active");
297
                inTOC = state.getBoolean("inTOC");
298
                editing = state.getBoolean("editing");
299
                cacheDrawnLayers = state.getBoolean("cacheDrawnLayers");
300
                dirty = state.getBoolean("dirty");
301
                available = state.getBoolean("available");
302
                writable = state.getBoolean("writable");
303
                driverLoaded = state.getBoolean("driverLoaded");
304
        }
305

    
306
        public void saveToState(PersistentState state) throws PersistenceException {
307
                
308
                state.set("visible", visible);
309
                state.set("active", active);
310
                state.set("inTOC", inTOC);
311
                state.set("editing", editing);
312
                state.set("cacheDrawnLayers", cacheDrawnLayers);
313
                state.set("dirty", dirty);
314
                state.set("available", available);
315
                state.set("writable", writable);
316
                state.set("driverLoaded", driverLoaded);
317
        }
318
        
319
        public static void registerPersistent() {
320
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
321
                DynStruct definition = manager.addDefinition(
322
                                FLayerStatus.class,
323
                                "FLayerStatus",
324
                                "FLayerStatus Persistence definition",
325
                                null, 
326
                                null
327
                );
328
                definition.addDynFieldBoolean("visible").setMandatory(true);
329
                definition.addDynFieldBoolean("active").setMandatory(true);
330
                definition.addDynFieldBoolean("inTOC").setMandatory(true);
331
                definition.addDynFieldBoolean("editing").setMandatory(true);
332
                definition.addDynFieldBoolean("cacheDrawnLayers").setMandatory(true);
333
                definition.addDynFieldBoolean("dirty").setMandatory(true);
334
                definition.addDynFieldBoolean("available").setMandatory(true);
335
                definition.addDynFieldBoolean("writable").setMandatory(true);
336
                definition.addDynFieldBoolean("driverLoaded").setMandatory(true);
337
                definition.addDynFieldBoolean("locked").setMandatory(true);
338
        }
339
}
340