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 / FLayerStatus.java @ 40559

History | View | Annotate | Download (10.4 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
/* CVS MESSAGES:
25
*
26
* $Id: FLayerStatus.java 20989 2008-05-28 11:05:57Z jmvivo $
27
* $Log$
28
* Revision 1.2  2007-03-06 17:08:55  caballero
29
* Exceptions
30
*
31
* Revision 1.1  2006/09/21 17:23:39  azabala
32
* First version in cvs
33
*
34
*
35
*/
36
package org.gvsig.fmap.mapcontext.layers;
37

    
38
import java.util.ArrayList;
39
import java.util.List;
40

    
41
import org.gvsig.tools.ToolsLocator;
42
import org.gvsig.tools.dynobject.DynStruct;
43
import org.gvsig.tools.exception.BaseException;
44
import org.gvsig.tools.persistence.PersistenceManager;
45
import org.gvsig.tools.persistence.PersistentState;
46
import org.gvsig.tools.persistence.exception.PersistenceException;
47

    
48

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

    
120
        
121
        /**
122
         * <p>List with the information of the driver errors produced working this layer.</p>
123
         */
124
        private ArrayList layerErrors;
125
                
126
        /**
127
         * <p>This state reports if the driver for managing the layer has been loaded successfully.</p>
128
         */
129
        private boolean driverLoaded=true;
130

    
131
        /**
132
         * <p>Creates an instance with the default status of a <code>FLyrDefault</code> layer:
133
         * <br>
134
         *  <ul>
135
         *  <li><b><i>Visible</i></b>: <code>true</code> .</li>
136
         *  <li><b><i>Active</i></b>: <code>false</code> .</li>
137
         *  <li><b><i>In TOC</i></b>: <code>true</code> .</li>
138
         *  <li><b><i>Editing</i></b>: <code>false</code> .</li>
139
         *  <li><b><i>Cache drawn layers</i></b>: <code>false</code> .</li>
140
         *  <li><b><i>Dirty</i></b>: <code>false</code> .</li>
141
         *  <li><b><i>Available</i></b>: <code>true</code> .</li>
142
         *  <li><b><i>Driver loaded</i></b>: <code>true</code> .</li>
143
         *  <li><b><i>Writable</i></b>: <code>false</code> .</li>
144
         *  <li>Without driver errors.</li>
145
         *  </ul>
146
         * </p>
147
         */
148
        public FLayerStatus(){
149
                this.layerErrors = new ArrayList();
150
                visible = true;
151
                active = false;
152
                inTOC = true;
153
                editing = false;
154
                cacheDrawnLayers = false;
155
                dirty = false;
156
                available = true;
157

    
158
                writable = false;
159

    
160
        }
161

    
162
        /**
163
         * <p>Stores information of an exception produced working with a driver of the layer.</p>
164
         * 
165
         * @param error the driver exception
166
         */
167
        public void addLayerError(BaseException error){
168
                layerErrors.add(error);
169
        }
170

    
171
        public FLayerStatus cloneStatus(){
172
                FLayerStatus newStatus = new FLayerStatus();
173
                newStatus.layerErrors.addAll(this.layerErrors);
174
                newStatus.visible = this.visible;
175
                newStatus.active = this.active;
176
                newStatus.inTOC = this.inTOC;
177
                newStatus.editing = this.editing;
178
                newStatus.cacheDrawnLayers = this.cacheDrawnLayers;
179
                newStatus.dirty = this.dirty;
180
                newStatus.available = this.available;
181
                newStatus.driverLoaded = this.driverLoaded;        
182
                newStatus.writable = this.writable;
183
        
184
                return newStatus;
185
        }
186
        
187
        
188

    
189
        public boolean equals(Object obj) {
190
                FLayerStatus other;
191
                if (obj instanceof FLayerStatus) {
192
                        other = (FLayerStatus) obj;
193
                } else{
194
                        return false;
195
                }
196

    
197
                if (other.visible != this.visible 
198
                                || other.active != this.active
199
                                || other.inTOC != this.inTOC || other.editing != this.editing
200
                                || other.cacheDrawnLayers != this.cacheDrawnLayers
201
                                || other.dirty != this.dirty
202
                                || other.available != this.available
203
                                || other.driverLoaded != this.driverLoaded
204
                                || other.writable != this.writable) {
205
                        return false;
206
                }
207
                
208

    
209
                
210
                if ((!other.layerErrors.containsAll(this.layerErrors)) || other.layerErrors.size() != this.layerErrors.size()){
211
                        return false;
212
                }
213
                return super.equals(obj);
214
        }
215

    
216
        /**
217
         * <p>Gets the number of driver exceptions produced working with the layer.</p>
218
         * 
219
         * @return number of driver exceptions produced
220
         */
221
        public int getNumErrors(){
222
                return layerErrors.size();
223
        }
224

    
225
        /**
226
         * <p>Gets the information of the <i>nth</i> layer driver exception registered in the status.</p>
227
         * 
228
         * @param i ith layer exception registered
229
         * 
230
         * @return the <i>nth</i> layer driver exception registered
231
         */
232
        public BaseException getError(int i){
233
                return (BaseException) layerErrors.get(i);
234
        }
235

    
236
        /**
237
         * <p>Returns if there have been driver errors working with the layer.</p>
238
         * 
239
         * @return <code>true</code> if there have driver errors working with the layer; otherwise <code>false</code>
240
         */
241
        public boolean isOk(){
242
                return layerErrors.size() == 0;
243
        }
244

    
245
        /**
246
         * <p>Returns a list of errors produced in a layer working with its driver.</p>
247
         * 
248
         * @return list errors produced in a layer working with its driver
249
         */
250
        public List getErrors() {
251
                return layerErrors;
252
        }
253

    
254
        /**
255
         * <p>Returns if has been loaded successfully the driver for managing the layer.</p>
256
         * 
257
         * @return <code>true</code> if has been loaded successfully the driver for managing the layer; otherwise <code>false</code>
258
         */
259
        public boolean isDriverLoaded() {
260
                return driverLoaded;
261
        }
262

    
263
        /**
264
         * <p>Sets if has been loaded successfully the driver for managing the layer.</p>
265
         * 
266
         * @param driverLoaded <code>true</code> if has been loaded successfully the driver for managing the layer; otherwise <code>false</code>
267
         */
268
        public void setDriverLoaded(boolean driverLoaded) {
269
                this.driverLoaded = driverLoaded;
270
        }
271

    
272
        public void loadFromState(PersistentState state)
273
                        throws PersistenceException {
274

    
275
                visible = state.getBoolean("visible");
276
                active = state.getBoolean("active");
277
                inTOC = state.getBoolean("inTOC");
278
                editing = state.getBoolean("editing");
279
                cacheDrawnLayers = state.getBoolean("cacheDrawnLayers");
280
                dirty = state.getBoolean("dirty");
281
                available = state.getBoolean("available");
282
                writable = state.getBoolean("writable");
283
                driverLoaded = state.getBoolean("driverLoaded");
284
        }
285

    
286
        public void saveToState(PersistentState state) throws PersistenceException {
287
                
288
                state.set("visible", visible);
289
                state.set("active", active);
290
                state.set("inTOC", inTOC);
291
                state.set("editing", editing);
292
                state.set("cacheDrawnLayers", cacheDrawnLayers);
293
                state.set("dirty", dirty);
294
                state.set("available", available);
295
                state.set("writable", writable);
296
                state.set("driverLoaded", driverLoaded);
297
        }
298
        
299
        public static void registerPersistent() {
300
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
301
                DynStruct definition = manager.addDefinition(
302
                                FLayerStatus.class,
303
                                "FLayerStatus",
304
                                "FLayerStatus Persistence definition",
305
                                null, 
306
                                null
307
                );
308
                definition.addDynFieldBoolean("visible").setMandatory(true);
309
                definition.addDynFieldBoolean("active").setMandatory(true);
310
                definition.addDynFieldBoolean("inTOC").setMandatory(true);
311
                definition.addDynFieldBoolean("editing").setMandatory(true);
312
                definition.addDynFieldBoolean("cacheDrawnLayers").setMandatory(true);
313
                definition.addDynFieldBoolean("dirty").setMandatory(true);
314
                definition.addDynFieldBoolean("available").setMandatory(true);
315
                definition.addDynFieldBoolean("writable").setMandatory(true);
316
                definition.addDynFieldBoolean("driverLoaded").setMandatory(true);
317
                //definition.addDynFieldBoolean("locked").setMandatory(true);
318
        }
319
}
320