Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / store / AbstractRasterDataParameters.java @ 2377

History | View | Annotate | Download (5.9 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.io.File;
26

    
27
import org.cresques.DataTypes;
28
import org.cresques.cts.IProjection;
29
import org.gvsig.fmap.crs.CRSFactory;
30
import org.gvsig.fmap.dal.coverage.store.RasterDataServerExplorer;
31
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
32
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
33
import org.gvsig.tools.dynobject.DynStruct;
34

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

    
55
        public static void registerDynClass(DynStruct definition) {
56
                definition.addDynFieldString(FIELD_URI)
57
                .setDescription("Uniform Resource Identifier (File name or URL)")
58
                .setType(DataTypes.STRING)
59
                .setMandatory(false);
60

    
61
                definition.addDynFieldInt(FIELD_FRAME)
62
                .setDescription("frame")
63
                .setType(DataTypes.INT)
64
                .setMandatory(false)
65
                .setHidden(true);
66

    
67
                definition.addDynFieldInt(FIELD_ALPHABAND)
68
                .setDescription("alphaband")
69
                .setType(DataTypes.INT)
70
                .setMandatory(false)
71
                .setHidden(true);
72
                
73
                definition.addDynFieldBoolean(FIELD_VISIBLE)
74
        .setDescription("If the boolean in i position is true, that means that the i provider is visible")
75
        .setMandatory(false)
76
        .setHidden(true);
77
        
78
        definition.addDynFieldInt(FIELD_REPROJ_OPTION)
79
                .setDescription("Reprojection option")
80
                .setType(DataTypes.INT)
81
                .setDefaultFieldValue(new Integer(0))
82
                .setMandatory(false)
83
                .setHidden(true);
84
                
85
                definition.addDynFieldString(FIELD_RMF_FOLDER)
86
                .setDescription("Folder to store the RMF file")
87
                .setMandatory(false)
88
                .setHidden(true);
89
                
90
                /*definition.addDynFieldObject(FIELD_CRS)
91
                .setDescription("CRS")
92
                .setMandatory(false)
93
                .setHidden(true);*/
94
        }
95
        
96
        public void assignFields(RasterDataParameters par, RasterDataServerExplorer explorer) {
97
                setRMFFolder(par.getRMFFolder());
98
                setReprojectionOption(par.getReprojectionOption());
99
                setVisible(par.isVisible());
100
                setAlphaBand(par.getAlphaBand());
101
                setFrame(par.getFrame());
102
                setURI(par.getURI());
103
        }
104

    
105
        public AbstractRasterDataParameters() {
106
                super();
107
        }
108
        
109
        public void setReprojectionOption(int option) {
110
                this.setDynValue(FIELD_REPROJ_OPTION, option);
111
        }
112
        
113
        public int getReprojectionOption() {
114
                Integer b = (Integer)getDynValue(FIELD_REPROJ_OPTION);
115
                if(b != null)
116
                        return ((Integer)b).intValue();
117
                return 0;
118
        }
119
        
120
        public boolean isValid() {
121
                return (this.getURI() != null);
122
        }
123

    
124
        public String getURI() {
125
                return (String) this.getDynValue(FIELD_URI);
126
        }
127

    
128
        public void setURI(String uri) {
129
                this.setDynValue(FIELD_URI, uri);
130
        }
131
        
132
        public void setRMFFolder(File rmfFolder) {
133
                if(rmfFolder != null)
134
                        this.setDynValue(FIELD_RMF_FOLDER, rmfFolder.getAbsolutePath());
135
        }
136
        
137
        public File getRMFFolder() {
138
                String s = (String)this.getDynValue(FIELD_RMF_FOLDER);
139
                if(s != null)
140
                        return new File(s);
141
                else
142
                        return null;
143
        }
144

    
145
        public String getSRSID() {
146
                if (crs == null) {
147
                        return null;
148
                }
149
                return crs.getAbrev();
150
        }
151

    
152
        public void setSRSID(String srsid) {
153
                if (srsid == null) {
154
                        crs = null;
155
                } else {
156
                        crs = CRSFactory.getCRS(srsid);
157
                }
158
        }
159

    
160
        public void setSRS(IProjection srs) {
161
                this.crs = srs;
162
        }
163

    
164
        public IProjection getSRS() {
165
                if (this.getSRSID() == null) {
166
                        return null;
167
                }
168
                return crs;
169
        }
170

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