gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / store / AbstractRasterDataParameters.java @ 1358
History | View | Annotate | Download (8.17 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
|
23 |
package org.gvsig.raster.impl.store; |
24 |
|
25 |
import java.net.URI; |
26 |
import java.net.URISyntaxException; |
27 |
|
28 |
import org.cresques.cts.IProjection; |
29 |
import org.gvsig.fmap.crs.CRSFactory; |
30 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
31 |
import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
32 |
import org.gvsig.tools.ToolsLocator; |
33 |
import org.gvsig.tools.dynobject.DynClass; |
34 |
import org.gvsig.tools.dynobject.DynField; |
35 |
import org.gvsig.tools.dynobject.DynObjectManager; |
36 |
import org.gvsig.tools.dynobject.DynStruct; |
37 |
import org.gvsig.tools.persistence.PersistentState; |
38 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
39 |
|
40 |
/**
|
41 |
* Base class for all kind of parameters in raster
|
42 |
* TODO: Now it only accepts files. Maybe in the future other kind of sources could be accepted like remote services (URL)
|
43 |
*
|
44 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
45 |
*/
|
46 |
public abstract class AbstractRasterDataParameters extends AbstractDataParameters implements |
47 |
RasterDataParameters { |
48 |
public static final String PERSISTENT_NAME = "AbstractRasterDataParameters_Persistent"; |
49 |
public static final String PERSISTENT_DESCRIPTION = "AbstractRasterDataParameters Persistent"; |
50 |
|
51 |
protected static final String FIELD_URI = "uri"; |
52 |
private static final String FIELD_CRS = "CRS"; |
53 |
private static final String FIELD_FRAME = "frame"; |
54 |
private static final String FIELD_ALPHABAND = "alphaband"; |
55 |
private static final String FIELD_VISIBLE = "visible"; |
56 |
private static final String FIELD_REPROJ_OPTION = "selected_option"; |
57 |
|
58 |
|
59 |
public static DynClass registerDynClass(String dynClassName) { |
60 |
DynObjectManager dynman = ToolsLocator.getDynObjectManager(); |
61 |
DynField field; |
62 |
|
63 |
if(dynman == null) |
64 |
return null; |
65 |
|
66 |
DynClass dynClass = dynman.add(dynClassName); |
67 |
|
68 |
field = dynClass.addDynFieldString(FIELD_URI); |
69 |
field.setDescription("Uniform Resource Identifier (File name or URL)");
|
70 |
field.setClassOfValue(String.class);
|
71 |
field.setMandatory(false);
|
72 |
|
73 |
field = dynClass.addDynFieldObject(FIELD_CRS); |
74 |
field.setDescription("CRS");
|
75 |
field.setClassOfValue(Object.class);
|
76 |
field.setMandatory(false);
|
77 |
|
78 |
field = dynClass.addDynFieldInt(FIELD_FRAME); |
79 |
field.setDescription("frame");
|
80 |
field.setClassOfValue(Integer.class);
|
81 |
field.setMandatory(false);
|
82 |
|
83 |
field = dynClass.addDynFieldInt(FIELD_ALPHABAND); |
84 |
field.setDescription("alphaband");
|
85 |
field.setClassOfValue(Integer.class);
|
86 |
field.setMandatory(false);
|
87 |
|
88 |
field = dynClass.addDynFieldObject(FIELD_VISIBLE); |
89 |
field.setDescription("If the boolean in i position is true, that means that the i provider is visible");
|
90 |
field.setMandatory(false);
|
91 |
field.setClassOfValue(Object.class);
|
92 |
|
93 |
field = dynClass.addDynFieldInt(FIELD_REPROJ_OPTION); |
94 |
field.setDescription("Reprojection option");
|
95 |
field.setClassOfValue(Integer.class);
|
96 |
field.setDefaultFieldValue(new Integer(0)); |
97 |
field.setMandatory(false);
|
98 |
|
99 |
return dynClass;
|
100 |
} |
101 |
|
102 |
public AbstractRasterDataParameters() {
|
103 |
super();
|
104 |
} |
105 |
|
106 |
/*
|
107 |
* (non-Javadoc)
|
108 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters#setReprojectionOption(int)
|
109 |
*/
|
110 |
public void setReprojectionOption(int option) { |
111 |
this.setDynValue(FIELD_REPROJ_OPTION, option);
|
112 |
} |
113 |
|
114 |
/*
|
115 |
* (non-Javadoc)
|
116 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters#getReprojectionOption()
|
117 |
*/
|
118 |
public int getReprojectionOption() { |
119 |
Integer b = (Integer)getDynValue(FIELD_REPROJ_OPTION); |
120 |
if(b != null) |
121 |
return ((Integer)b).intValue(); |
122 |
return 0; |
123 |
} |
124 |
|
125 |
public boolean isValid() { |
126 |
return (this.getURI() != null); |
127 |
} |
128 |
|
129 |
/*
|
130 |
* (non-Javadoc)
|
131 |
* @see org.gvsig.fmap.dal.coverage.store.RasterStoreParameters#getURI()
|
132 |
*/
|
133 |
public String getURI() { |
134 |
return (String) this.getDynValue(FIELD_URI); |
135 |
} |
136 |
|
137 |
/*
|
138 |
* (non-Javadoc)
|
139 |
* @see org.gvsig.fmap.dal.coverage.store.RasterStoreParameters#setURI(java.lang.String)
|
140 |
*/
|
141 |
public void setURI(String uri) { |
142 |
this.setDynValue(FIELD_URI, uri);
|
143 |
} |
144 |
|
145 |
public String getSRSID() { |
146 |
IProjection srs = (IProjection) getDynValue(FIELD_CRS); |
147 |
if (srs == null) { |
148 |
return null; |
149 |
} |
150 |
return srs.getAbrev();
|
151 |
} |
152 |
|
153 |
public void setSRSID(String srsid) { |
154 |
if (srsid == null) { |
155 |
setDynValue(FIELD_CRS, null);
|
156 |
} else {
|
157 |
setDynValue(FIELD_CRS, CRSFactory.getCRS(srsid)); |
158 |
} |
159 |
} |
160 |
|
161 |
public void setSRS(IProjection srs) { |
162 |
setDynValue(FIELD_CRS, srs); |
163 |
} |
164 |
|
165 |
public IProjection getSRS() {
|
166 |
if (this.getSRSID() == null) { |
167 |
return null; |
168 |
} |
169 |
return (IProjection) getDynValue(FIELD_CRS);
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* Sets the number of alpha band
|
174 |
* @param alphaBand
|
175 |
*/
|
176 |
public void setAlphaBand(int alphaBand) { |
177 |
this.setDynValue(FIELD_ALPHABAND, new Integer(alphaBand)); |
178 |
} |
179 |
|
180 |
/**
|
181 |
* Sets the frame width
|
182 |
* @param frame
|
183 |
*/
|
184 |
public void setFrame(int frame) { |
185 |
this.setDynValue(FIELD_FRAME, new Integer(frame)); |
186 |
} |
187 |
|
188 |
/**
|
189 |
* Gets the number of alpha band
|
190 |
* @param alphaBand
|
191 |
*/
|
192 |
public int getAlphaBand() { |
193 |
Integer b = (Integer)getDynValue(FIELD_ALPHABAND); |
194 |
if(b != null) |
195 |
return ((Integer)b).intValue(); |
196 |
return 0; |
197 |
} |
198 |
|
199 |
/**
|
200 |
* Gets the frame width
|
201 |
* @param frame
|
202 |
*/
|
203 |
public int getFrame() { |
204 |
Integer b = (Integer)getDynValue(FIELD_FRAME); |
205 |
if(b != null) |
206 |
return ((Integer)b).intValue(); |
207 |
return 0; |
208 |
} |
209 |
|
210 |
/*
|
211 |
* (non-Javadoc)
|
212 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters#isVisible()
|
213 |
*/
|
214 |
public boolean isVisible() { |
215 |
Boolean b = (Boolean)getDynValue(FIELD_VISIBLE); |
216 |
if(b != null) |
217 |
return ((Boolean)b).booleanValue(); |
218 |
return true; |
219 |
} |
220 |
|
221 |
/*
|
222 |
* (non-Javadoc)
|
223 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters#setVisible(boolean)
|
224 |
*/
|
225 |
public void setVisible(boolean visible) { |
226 |
this.setDynValue(FIELD_VISIBLE, new Boolean(visible)); |
227 |
} |
228 |
|
229 |
/*
|
230 |
* (non-Javadoc)
|
231 |
* @see org.gvsig.fmap.dal.spi.AbstractDataParameters#loadFromState(org.gvsig.tools.persistence.PersistentState)
|
232 |
*/
|
233 |
public void loadFromState(PersistentState state) throws PersistenceException { |
234 |
String uriString = null; |
235 |
try {
|
236 |
URI uri = state.getURI(FIELD_URI);
|
237 |
if(uri != null) { |
238 |
uriString = uri.toString(); |
239 |
if(uri.getScheme() == null || "file".equalsIgnoreCase(uri.getScheme())) |
240 |
uriString = uri.getPath(); |
241 |
} |
242 |
} catch(ClassCastException e) { |
243 |
uriString = state.getString(FIELD_URI); |
244 |
} |
245 |
|
246 |
setURI(uriString); |
247 |
setSRS((IProjection)state.get(FIELD_CRS)); |
248 |
setAlphaBand(state.getInt(FIELD_ALPHABAND)); |
249 |
setFrame(state.getInt(FIELD_FRAME)); |
250 |
setVisible(state.getBoolean(FIELD_VISIBLE)); |
251 |
} |
252 |
|
253 |
/*
|
254 |
* (non-Javadoc)
|
255 |
* @see org.gvsig.fmap.dal.spi.AbstractDataParameters#saveToState(org.gvsig.tools.persistence.PersistentState)
|
256 |
*/
|
257 |
public void saveToState(PersistentState state) throws PersistenceException { |
258 |
try {
|
259 |
String uri = getURI();
|
260 |
if(uri != null) |
261 |
state.set(FIELD_URI, new URI(uri)); |
262 |
} catch (URISyntaxException e) { |
263 |
throw new PersistenceException(e); |
264 |
} |
265 |
state.set(FIELD_CRS, getSRS()); |
266 |
state.set(FIELD_ALPHABAND, getAlphaBand()); |
267 |
state.set(FIELD_FRAME, getFrame()); |
268 |
state.set(FIELD_VISIBLE, isVisible()); |
269 |
} |
270 |
|
271 |
public static void registerPersistence(DynStruct definition) { |
272 |
definition.addDynFieldURI(FIELD_URI).setMandatory(false);
|
273 |
definition.addDynFieldObject(FIELD_CRS).setClassOfValue(IProjection.class).setMandatory(false);
|
274 |
definition.addDynFieldInt(FIELD_ALPHABAND).setMandatory(false);
|
275 |
definition.addDynFieldInt(FIELD_FRAME).setMandatory(false);
|
276 |
definition.addDynFieldBoolean(FIELD_VISIBLE).setMandatory(false);
|
277 |
} |
278 |
} |