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

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
package org.gvsig.fmap.mapcontext.layers;
25

    
26
import java.util.ArrayList;
27
import java.util.List;
28

    
29
import org.gvsig.tools.ToolsLocator;
30
import org.gvsig.tools.dynobject.DynStruct;
31
import org.gvsig.tools.exception.BaseException;
32
import org.gvsig.tools.persistence.PersistenceManager;
33
import org.gvsig.tools.persistence.PersistentState;
34
import org.gvsig.tools.persistence.exception.PersistenceException;
35
import org.gvsig.tools.util.Callable;
36

    
37

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

    
109
        private boolean temporal = false;
110
        /**
111
         * <p>List with the information of the driver errors produced working this layer.</p>
112
         */
113
        private List layerErrors;
114
                
115
        /**
116
         * <p>This state reports if the driver for managing the layer has been loaded successfully.</p>
117
         */
118
        private boolean driverLoaded=true;
119

    
120
        /**
121
         * <p>Creates an instance with the default status of a <code>FLyrDefault</code> layer:
122
         * <br>
123
         *  <ul>
124
         *  <li><b><i>Visible</i></b>: <code>true</code> .</li>
125
         *  <li><b><i>Active</i></b>: <code>false</code> .</li>
126
         *  <li><b><i>In TOC</i></b>: <code>true</code> .</li>
127
         *  <li><b><i>Editing</i></b>: <code>false</code> .</li>
128
         *  <li><b><i>Cache drawn layers</i></b>: <code>false</code> .</li>
129
         *  <li><b><i>Dirty</i></b>: <code>false</code> .</li>
130
         *  <li><b><i>Available</i></b>: <code>true</code> .</li>
131
         *  <li><b><i>Driver loaded</i></b>: <code>true</code> .</li>
132
         *  <li><b><i>Writable</i></b>: <code>false</code> .</li>
133
         *  <li>Without driver errors.</li>
134
         *  </ul>
135
         * </p>
136
         */
137
        public FLayerStatus(){
138
                this.layerErrors = new ArrayList();
139
                visible = true;
140
                active = false;
141
                inTOC = true;
142
                editing = false;
143
                cacheDrawnLayers = false;
144
                dirty = false;
145
                available = true;
146

    
147
                writable = false;
148

    
149
        }
150

    
151
        /**
152
         * <p>Stores information of an exception produced working with a driver of the layer.</p>
153
         * 
154
         * @param error the driver exception
155
         */
156
        public void addLayerError(BaseException error){
157
                layerErrors.add(error);
158
        }
159

    
160
        public FLayerStatus cloneStatus(){
161
                FLayerStatus newStatus = new FLayerStatus();
162
                newStatus.layerErrors.addAll(this.layerErrors);
163
                newStatus.visible = this.visible;
164
                newStatus.active = this.active;
165
                newStatus.inTOC = this.inTOC;
166
                newStatus.editing = this.editing;
167
                newStatus.cacheDrawnLayers = this.cacheDrawnLayers;
168
                newStatus.dirty = this.dirty;
169
                newStatus.available = this.available;
170
                newStatus.driverLoaded = this.driverLoaded;        
171
                newStatus.writable = this.writable;
172
        
173
                return newStatus;
174
        }
175
        
176
        
177

    
178
        public boolean equals(Object obj) {
179
                FLayerStatus other;
180
                if (obj instanceof FLayerStatus) {
181
                        other = (FLayerStatus) obj;
182
                } else{
183
                        return false;
184
                }
185

    
186
                if (other.visible != this.visible 
187
                                || other.active != this.active
188
                                || other.inTOC != this.inTOC || other.editing != this.editing
189
                                || other.cacheDrawnLayers != this.cacheDrawnLayers
190
                                || other.dirty != this.dirty
191
                                || other.available != this.available
192
                                || other.driverLoaded != this.driverLoaded
193
                                || other.writable != this.writable) {
194
                        return false;
195
                }
196
                
197

    
198
                
199
                if ((!other.layerErrors.containsAll(this.layerErrors)) || other.layerErrors.size() != this.layerErrors.size()){
200
                        return false;
201
                }
202
                return super.equals(obj);
203
        }
204

    
205
        /**
206
         * <p>Gets the number of driver exceptions produced working with the layer.</p>
207
         * 
208
         * @return number of driver exceptions produced
209
         */
210
        public int getNumErrors(){
211
                return layerErrors.size();
212
        }
213

    
214
        /**
215
         * <p>Gets the information of the <i>nth</i> layer driver exception registered in the status.</p>
216
         * 
217
         * @param i ith layer exception registered
218
         * 
219
         * @return the <i>nth</i> layer driver exception registered
220
         */
221
        public BaseException getError(int i){
222
                return (BaseException) layerErrors.get(i);
223
        }
224

    
225
        /**
226
         * <p>Returns if there have been driver errors working with the layer.</p>
227
         * 
228
         * @return <code>true</code> if there have driver errors working with the layer; otherwise <code>false</code>
229
         */
230
        public boolean isOk(){
231
                return layerErrors.size() == 0;
232
        }
233

    
234
        /**
235
         * <p>Returns a list of errors produced in a layer working with its driver.</p>
236
         * 
237
         * @return list errors produced in a layer working with its driver
238
         */
239
        public List getErrors() {
240
                return layerErrors;
241
        }
242

    
243
        /**
244
         * <p>Returns if has been loaded successfully the driver for managing the layer.</p>
245
         * 
246
         * @return <code>true</code> if has been loaded successfully the driver for managing the layer; otherwise <code>false</code>
247
         */
248
        public boolean isDriverLoaded() {
249
                return driverLoaded;
250
        }
251

    
252
        /**
253
         * <p>Sets if has been loaded successfully the driver for managing the layer.</p>
254
         * 
255
         * @param driverLoaded <code>true</code> if has been loaded successfully the driver for managing the layer; otherwise <code>false</code>
256
         */
257
        public void setDriverLoaded(boolean driverLoaded) {
258
                this.driverLoaded = driverLoaded;
259
        }
260

    
261
        public void loadFromState(PersistentState state)
262
                        throws PersistenceException {
263

    
264
                visible = state.getBoolean("visible");
265
                active = state.getBoolean("active");
266
                inTOC = state.getBoolean("inTOC");
267
                editing = state.getBoolean("editing");
268
                cacheDrawnLayers = state.getBoolean("cacheDrawnLayers");
269
                dirty = state.getBoolean("dirty");
270
                available = state.getBoolean("available");
271
                writable = state.getBoolean("writable");
272
                driverLoaded = state.getBoolean("driverLoaded");
273
        }
274

    
275
        public void saveToState(PersistentState state) throws PersistenceException {
276
                
277
                state.set("visible", visible);
278
                state.set("active", active);
279
                state.set("inTOC", inTOC);
280
                state.set("editing", editing);
281
                state.set("cacheDrawnLayers", cacheDrawnLayers);
282
                state.set("dirty", dirty);
283
                state.set("available", available);
284
                state.set("writable", writable);
285
                state.set("driverLoaded", driverLoaded);
286
        }
287
        
288
    public static class RegisterPersistence implements Callable {
289

    
290
        public Object call() {
291
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
292
                DynStruct definition = manager.addDefinition(
293
                                FLayerStatus.class,
294
                                "FLayerStatus",
295
                                "FLayerStatus Persistence definition",
296
                                null, 
297
                                null
298
                );
299
                definition.addDynFieldBoolean("visible").setMandatory(true);
300
                definition.addDynFieldBoolean("active").setMandatory(true);
301
                definition.addDynFieldBoolean("inTOC").setMandatory(true);
302
                definition.addDynFieldBoolean("editing").setMandatory(true);
303
                definition.addDynFieldBoolean("cacheDrawnLayers").setMandatory(true);
304
                definition.addDynFieldBoolean("dirty").setMandatory(true);
305
                definition.addDynFieldBoolean("available").setMandatory(true);
306
                definition.addDynFieldBoolean("writable").setMandatory(true);
307
                definition.addDynFieldBoolean("driverLoaded").setMandatory(true);
308
                //definition.addDynFieldBoolean("locked").setMandatory(true);
309
            
310
            return Boolean.TRUE;
311
        }
312
    }
313
}
314