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