Statistics
| Revision:

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

History | View | Annotate | Download (7.68 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 org.cresques.cts.IProjection;
26
import org.gvsig.fmap.crs.CRSFactory;
27
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
28
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
29
import org.gvsig.tools.ToolsLocator;
30
import org.gvsig.tools.dynobject.DynClass;
31
import org.gvsig.tools.dynobject.DynField;
32
import org.gvsig.tools.dynobject.DynObjectManager;
33
import org.gvsig.tools.dynobject.DynStruct;
34
import org.gvsig.tools.persistence.PersistentState;
35
import org.gvsig.tools.persistence.exception.PersistenceException;
36

    
37
/**
38
 * Base class for all kind of parameters in raster
39
 * TODO: Now it only accepts files. Maybe in the future other kind of sources could be accepted like remote services (URL)
40
 * 
41
 * @author Nacho Brodin (nachobrodin@gmail.com)
42
 */
43
public abstract class AbstractRasterDataParameters extends AbstractDataParameters implements
44
                RasterDataParameters {
45
        public static final String     PERSISTENT_NAME        = "AbstractRasterDataParameters_Persistent";
46
    public static final String     PERSISTENT_DESCRIPTION = "AbstractRasterDataParameters Persistent";
47
    
48
        protected static final String  FIELD_URI              = "uri";
49
        private static final String    FIELD_SRS              = "srs";
50
        private static final String    FIELD_FRAME            = "frame";
51
        private static final String    FIELD_ALPHABAND        = "alphaband";
52
        private static final String    FIELD_VISIBLE          = "visible";
53
        private static final String    FIELD_REPROJ_OPTION    = "selected_option";
54
        
55

    
56
        public static DynClass registerDynClass(String dynClassName) {
57
                DynObjectManager dynman = ToolsLocator.getDynObjectManager();
58
                DynField field;
59

    
60
                if(dynman == null)
61
                        return null;
62

    
63
                DynClass dynClass = dynman.add(dynClassName);
64

    
65
                field = dynClass.addDynFieldString(FIELD_URI);
66
                field.setDescription("Uniform Resource Identifier (File name or URL)");
67
                field.setClassOfValue(String.class);
68
                field.setMandatory(false);
69

    
70
                field = dynClass.addDynField(FIELD_SRS);
71
                field.setDescription("SRS");
72
                field.setClassOfValue(Object.class);
73
                field.setMandatory(false);
74

    
75
                field = dynClass.addDynFieldInt(FIELD_FRAME);
76
                field.setDescription("frame");
77
                field.setClassOfValue(Integer.class);
78
                field.setMandatory(false);
79

    
80
                field = dynClass.addDynFieldInt(FIELD_ALPHABAND);
81
                field.setDescription("alphaband");
82
                field.setClassOfValue(Integer.class);
83
                field.setMandatory(false);
84
                
85
                field = dynClass.addDynFieldObject(FIELD_VISIBLE);
86
        field.setDescription("If the boolean in i position is true, that means that the i provider is visible");
87
        field.setMandatory(false);
88
        field.setClassOfValue(Object.class);
89
        
90
                field = dynClass.addDynFieldInt(FIELD_REPROJ_OPTION);
91
                field.setDescription("Reprojection option");
92
                field.setClassOfValue(Integer.class);
93
                field.setDefaultFieldValue(new Integer(0));
94
                field.setMandatory(false);
95
                
96
                return dynClass;
97
        }
98

    
99
        public AbstractRasterDataParameters() {
100
                super();
101
        }
102
        
103
        /*
104
         * (non-Javadoc)
105
         * @see org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters#setReprojectionOption(int)
106
         */
107
        public void setReprojectionOption(int option) {
108
                this.setDynValue(FIELD_REPROJ_OPTION, option);
109
        }
110
        
111
        /*
112
         * (non-Javadoc)
113
         * @see org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters#getReprojectionOption()
114
         */
115
        public int getReprojectionOption() {
116
                Integer b = (Integer)getDynValue(FIELD_REPROJ_OPTION);
117
                if(b != null)
118
                        return ((Integer)b).intValue();
119
                return 0;
120
        }
121
        
122
        public boolean isValid() {
123
                return (this.getURI() != null);
124
        }
125

    
126
        /*
127
         * (non-Javadoc)
128
         * @see org.gvsig.fmap.dal.coverage.store.RasterStoreParameters#getURI()
129
         */
130
        public String getURI() {
131
                return (String) this.getDynValue(FIELD_URI);
132
        }
133

    
134
        /*
135
         * (non-Javadoc)
136
         * @see org.gvsig.fmap.dal.coverage.store.RasterStoreParameters#setURI(java.lang.String)
137
         */
138
        public void setURI(String uri) {
139
                this.setDynValue(FIELD_URI, uri);
140
        }
141

    
142
        public String getSRSID() {
143
                IProjection srs = (IProjection) getDynValue(FIELD_SRS);
144
                if (srs == null) {
145
                        return null;
146
                }
147
                return srs.getAbrev();
148
        }
149

    
150
        public void setSRSID(String srsid) {
151
                if (srsid == null) {
152
                        setDynValue(FIELD_SRS, null);
153
                } else {
154
                        setDynValue(FIELD_SRS, CRSFactory.getCRS(srsid));
155
                }
156
        }
157

    
158
        public void setSRS(IProjection srs) {
159
                setDynValue(FIELD_SRS, srs);
160
        }
161

    
162
        public IProjection getSRS() {
163
                if (this.getSRSID() == null) {
164
                        return null;
165
                }
166
                return (IProjection) getDynValue(FIELD_SRS);
167
        }
168

    
169
        /**
170
         * Sets the number of alpha band
171
         * @param alphaBand
172
         */
173
        public void setAlphaBand(int alphaBand) {
174
                this.setDynValue(FIELD_ALPHABAND, new Integer(alphaBand));
175
        }
176
        
177
        /**
178
         * Sets the frame width
179
         * @param frame
180
         */
181
        public void setFrame(int frame) {
182
                this.setDynValue(FIELD_FRAME, new Integer(frame));
183
        }
184
        
185
        /**
186
         * Gets the number of alpha band
187
         * @param alphaBand
188
         */
189
        public int getAlphaBand() {
190
                Integer b = (Integer)getDynValue(FIELD_ALPHABAND);
191
                if(b != null)
192
                        return ((Integer)b).intValue();
193
                return 0;
194
        }
195
        
196
        /**
197
         * Gets the frame width
198
         * @param frame
199
         */
200
        public int getFrame() {
201
                Integer b = (Integer)getDynValue(FIELD_FRAME);
202
                if(b != null)
203
                        return ((Integer)b).intValue();
204
                return 0;
205
        }
206
        
207
        /*
208
         * (non-Javadoc)
209
         * @see org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters#isVisible()
210
         */
211
        public boolean isVisible() {
212
                Boolean b = (Boolean)getDynValue(FIELD_VISIBLE);
213
                if(b != null)
214
                        return ((Boolean)b).booleanValue();
215
                return true;
216
        }
217
        
218
        /*
219
         * (non-Javadoc)
220
         * @see org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters#setVisible(boolean)
221
         */
222
        public void setVisible(boolean visible) {
223
                this.setDynValue(FIELD_VISIBLE, new Boolean(visible));
224
        }
225

    
226
        /*
227
         * (non-Javadoc)
228
         * @see org.gvsig.fmap.dal.spi.AbstractDataParameters#loadFromState(org.gvsig.tools.persistence.PersistentState)
229
         */
230
        public void loadFromState(PersistentState state) throws PersistenceException {
231
                setURI(state.getString(FIELD_URI));
232
                setSRS((IProjection)state.get(FIELD_SRS));
233
                setAlphaBand(state.getInt(FIELD_ALPHABAND));
234
                setFrame(state.getInt(FIELD_FRAME));
235
                setVisible(state.getBoolean(FIELD_VISIBLE));
236
        }
237

    
238
        /*
239
         * (non-Javadoc)
240
         * @see org.gvsig.fmap.dal.spi.AbstractDataParameters#saveToState(org.gvsig.tools.persistence.PersistentState)
241
         */
242
        public void saveToState(PersistentState state) throws PersistenceException {
243
                state.set(FIELD_URI, getURI());
244
                state.set(FIELD_SRS, getSRS());
245
                state.set(FIELD_ALPHABAND, getAlphaBand());
246
                state.set(FIELD_FRAME, getFrame());
247
                state.set(FIELD_VISIBLE, isVisible());
248
        }        
249

    
250
        public static void registerPersistence(DynStruct definition) {
251
                definition.addDynFieldString(FIELD_URI).setMandatory(false);
252
                definition.addDynFieldObject(FIELD_SRS).setClassOfValue(IProjection.class).setMandatory(false);
253
                definition.addDynFieldInt(FIELD_ALPHABAND).setMandatory(false);
254
                definition.addDynFieldInt(FIELD_FRAME).setMandatory(false);
255
                definition.addDynFieldBoolean(FIELD_VISIBLE).setMandatory(false);
256
        }
257
}