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 @ 42811
History | View | Annotate | Download (10.5 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
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 | 41840 | jjdelcerro | import org.gvsig.tools.util.Callable; |
36 | 40435 | jjdelcerro | |
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 | 41853 | jjdelcerro | private boolean temporal = false; |
110 | 40435 | jjdelcerro | /**
|
111 | * <p>List with the information of the driver errors produced working this layer.</p>
|
||
112 | */
|
||
113 | 41853 | jjdelcerro | private List layerErrors; |
114 | 40435 | jjdelcerro | |
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 | 42811 | jjdelcerro | public void setLayerError(Exception ex) { |
161 | layerErrors.clear(); |
||
162 | layerErrors.add(ex); |
||
163 | } |
||
164 | |||
165 | 41840 | jjdelcerro | public FLayerStatus cloneStatus(){
|
166 | FLayerStatus newStatus = new FLayerStatus();
|
||
167 | newStatus.layerErrors.addAll(this.layerErrors);
|
||
168 | newStatus.visible = this.visible;
|
||
169 | newStatus.active = this.active;
|
||
170 | newStatus.inTOC = this.inTOC;
|
||
171 | newStatus.editing = this.editing;
|
||
172 | newStatus.cacheDrawnLayers = this.cacheDrawnLayers;
|
||
173 | newStatus.dirty = this.dirty;
|
||
174 | newStatus.available = this.available;
|
||
175 | newStatus.driverLoaded = this.driverLoaded;
|
||
176 | newStatus.writable = this.writable;
|
||
177 | |||
178 | return newStatus;
|
||
179 | } |
||
180 | |||
181 | |||
182 | |||
183 | public boolean equals(Object obj) { |
||
184 | FLayerStatus other; |
||
185 | if (obj instanceof FLayerStatus) { |
||
186 | other = (FLayerStatus) obj; |
||
187 | } else{
|
||
188 | return false; |
||
189 | } |
||
190 | |||
191 | if (other.visible != this.visible |
||
192 | || other.active != this.active
|
||
193 | || other.inTOC != this.inTOC || other.editing != this.editing |
||
194 | || other.cacheDrawnLayers != this.cacheDrawnLayers
|
||
195 | || other.dirty != this.dirty
|
||
196 | || other.available != this.available
|
||
197 | || other.driverLoaded != this.driverLoaded
|
||
198 | || other.writable != this.writable) {
|
||
199 | return false; |
||
200 | } |
||
201 | |||
202 | |||
203 | |||
204 | if ((!other.layerErrors.containsAll(this.layerErrors)) || other.layerErrors.size() != this.layerErrors.size()){ |
||
205 | return false; |
||
206 | } |
||
207 | return super.equals(obj); |
||
208 | } |
||
209 | |||
210 | 40435 | jjdelcerro | /**
|
211 | * <p>Gets the number of driver exceptions produced working with the layer.</p>
|
||
212 | *
|
||
213 | * @return number of driver exceptions produced
|
||
214 | */
|
||
215 | public int getNumErrors(){ |
||
216 | return layerErrors.size();
|
||
217 | } |
||
218 | |||
219 | /**
|
||
220 | * <p>Gets the information of the <i>nth</i> layer driver exception registered in the status.</p>
|
||
221 | *
|
||
222 | * @param i ith layer exception registered
|
||
223 | *
|
||
224 | * @return the <i>nth</i> layer driver exception registered
|
||
225 | */
|
||
226 | public BaseException getError(int i){ |
||
227 | return (BaseException) layerErrors.get(i);
|
||
228 | } |
||
229 | |||
230 | /**
|
||
231 | * <p>Returns if there have been driver errors working with the layer.</p>
|
||
232 | *
|
||
233 | * @return <code>true</code> if there have driver errors working with the layer; otherwise <code>false</code>
|
||
234 | */
|
||
235 | public boolean isOk(){ |
||
236 | return layerErrors.size() == 0; |
||
237 | } |
||
238 | |||
239 | /**
|
||
240 | * <p>Returns a list of errors produced in a layer working with its driver.</p>
|
||
241 | *
|
||
242 | * @return list errors produced in a layer working with its driver
|
||
243 | */
|
||
244 | public List getErrors() { |
||
245 | return layerErrors;
|
||
246 | } |
||
247 | 42811 | jjdelcerro | |
248 | 40435 | jjdelcerro | /**
|
249 | * <p>Returns if has been loaded successfully the driver for managing the layer.</p>
|
||
250 | *
|
||
251 | * @return <code>true</code> if has been loaded successfully the driver for managing the layer; otherwise <code>false</code>
|
||
252 | */
|
||
253 | public boolean isDriverLoaded() { |
||
254 | return driverLoaded;
|
||
255 | } |
||
256 | |||
257 | /**
|
||
258 | * <p>Sets if has been loaded successfully the driver for managing the layer.</p>
|
||
259 | *
|
||
260 | * @param driverLoaded <code>true</code> if has been loaded successfully the driver for managing the layer; otherwise <code>false</code>
|
||
261 | */
|
||
262 | public void setDriverLoaded(boolean driverLoaded) { |
||
263 | this.driverLoaded = driverLoaded;
|
||
264 | } |
||
265 | |||
266 | public void loadFromState(PersistentState state) |
||
267 | throws PersistenceException {
|
||
268 | |||
269 | visible = state.getBoolean("visible");
|
||
270 | active = state.getBoolean("active");
|
||
271 | inTOC = state.getBoolean("inTOC");
|
||
272 | editing = state.getBoolean("editing");
|
||
273 | cacheDrawnLayers = state.getBoolean("cacheDrawnLayers");
|
||
274 | dirty = state.getBoolean("dirty");
|
||
275 | available = state.getBoolean("available");
|
||
276 | writable = state.getBoolean("writable");
|
||
277 | driverLoaded = state.getBoolean("driverLoaded");
|
||
278 | } |
||
279 | |||
280 | public void saveToState(PersistentState state) throws PersistenceException { |
||
281 | |||
282 | state.set("visible", visible);
|
||
283 | state.set("active", active);
|
||
284 | state.set("inTOC", inTOC);
|
||
285 | state.set("editing", editing);
|
||
286 | state.set("cacheDrawnLayers", cacheDrawnLayers);
|
||
287 | state.set("dirty", dirty);
|
||
288 | state.set("available", available);
|
||
289 | state.set("writable", writable);
|
||
290 | state.set("driverLoaded", driverLoaded);
|
||
291 | } |
||
292 | |||
293 | 41840 | jjdelcerro | public static class RegisterPersistence implements Callable { |
294 | |||
295 | public Object call() { |
||
296 | 40435 | jjdelcerro | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
297 | DynStruct definition = manager.addDefinition( |
||
298 | FLayerStatus.class, |
||
299 | "FLayerStatus",
|
||
300 | "FLayerStatus Persistence definition",
|
||
301 | null,
|
||
302 | null
|
||
303 | ); |
||
304 | definition.addDynFieldBoolean("visible").setMandatory(true); |
||
305 | definition.addDynFieldBoolean("active").setMandatory(true); |
||
306 | definition.addDynFieldBoolean("inTOC").setMandatory(true); |
||
307 | definition.addDynFieldBoolean("editing").setMandatory(true); |
||
308 | definition.addDynFieldBoolean("cacheDrawnLayers").setMandatory(true); |
||
309 | definition.addDynFieldBoolean("dirty").setMandatory(true); |
||
310 | definition.addDynFieldBoolean("available").setMandatory(true); |
||
311 | definition.addDynFieldBoolean("writable").setMandatory(true); |
||
312 | definition.addDynFieldBoolean("driverLoaded").setMandatory(true); |
||
313 | //definition.addDynFieldBoolean("locked").setMandatory(true);
|
||
314 | 41840 | jjdelcerro | |
315 | return Boolean.TRUE; |
||
316 | } |
||
317 | } |
||
318 | 40435 | jjdelcerro | } |