Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLayerStatus.java @ 24160

History | View | Annotate | Download (8.35 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 24160 2008-10-21 11:02:25Z 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 com.iver.cit.gvsig.fmap.layers;
57

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

    
61
import org.gvsig.exceptions.BaseException;
62

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

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

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

    
172
                writable = false;
173

    
174
        }
175

    
176
        /**
177
         * <p>Stores information of an exception produced working with a driver of the layer.</p>
178
         * 
179
         * @param error the driver exception
180
         */
181
        public void addLayerError(BaseException error){
182
                layerErrors.add(error);
183
        }
184
        
185
        public FLayerStatus cloneStatus(){
186
                FLayerStatus newStatus = new FLayerStatus();
187
                newStatus.layerErrors.addAll(this.layerErrors);
188
                newStatus.visible = this.visible;
189
                newStatus.active = this.active;
190
                newStatus.inTOC = this.inTOC;
191
                newStatus.editing = this.editing;
192
                newStatus.cacheDrawnLayers = this.cacheDrawnLayers;
193
                newStatus.dirty = this.dirty;
194
                newStatus.available = this.available;
195
                newStatus.driverLoaded = this.driverLoaded;        
196
                newStatus.writable = this.writable;
197
        
198
                return newStatus;
199
        }
200
        
201
        
202

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

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

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

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

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

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

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

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

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