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 / datastruct / DatasetBandImpl.java @ 1328
History | View | Annotate | Download (8.6 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 |
package org.gvsig.raster.impl.datastruct; |
23 |
|
24 |
import java.net.URI; |
25 |
import java.net.URISyntaxException; |
26 |
import java.util.ArrayList; |
27 |
import java.util.List; |
28 |
|
29 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
30 |
import org.gvsig.fmap.dal.coverage.datastruct.DatasetBand; |
31 |
import org.gvsig.tools.ToolsLocator; |
32 |
import org.gvsig.tools.dynobject.DynStruct; |
33 |
import org.gvsig.tools.persistence.PersistenceManager; |
34 |
import org.gvsig.tools.persistence.PersistentState; |
35 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
36 |
|
37 |
|
38 |
/**
|
39 |
* Clase que representa a una banda de un fichero.
|
40 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
41 |
*/
|
42 |
public class DatasetBandImpl implements DatasetBand { |
43 |
public static final String PERSISTENT_NAME = "DatasetBand_Persistent"; |
44 |
public static final String PERSISTENT_DESCRIPTION = "DatasetBand Persistent"; |
45 |
|
46 |
//Nombre del fichero al que pertenece la banda
|
47 |
private String fileName = ""; |
48 |
//Lista de nombre de otros ficheros que forman la banda. Esto es util para CompositeDataset que est? compuesto por un mosaico de ficheros.
|
49 |
@SuppressWarnings("unchecked") |
50 |
private ArrayList additionalName = new ArrayList(); |
51 |
//Posici?n en el fichero de la banda
|
52 |
private int position = -1; |
53 |
//Tipo de dato de la banda
|
54 |
private int dataType = Buffer.TYPE_BYTE; |
55 |
//lista de bandas del buffer donde se dibuja esta banda de imagen. Cada elemento
|
56 |
//del vector es un n?mero que corresponde con el n?mero de banda del buffer donde se escribe esta
|
57 |
private int[] rasterBufBandToDrawList = null; |
58 |
//
|
59 |
private int nBandsInThisProvider = 0; |
60 |
|
61 |
public DatasetBandImpl() {
|
62 |
|
63 |
} |
64 |
|
65 |
public DatasetBandImpl(String f, int p, int dt, int nBands){ |
66 |
setFileName(f); |
67 |
setPosition(p); |
68 |
setDataType(dt); |
69 |
nBandsInThisProvider = nBands; |
70 |
} |
71 |
|
72 |
/*
|
73 |
* (non-Javadoc)
|
74 |
* @see java.lang.Object#clone()
|
75 |
*/
|
76 |
public Object clone() { |
77 |
DatasetBandImpl result = new DatasetBandImpl(fileName, position, dataType, nBandsInThisProvider);
|
78 |
if(rasterBufBandToDrawList != null) { |
79 |
int[] drawBands = new int[rasterBufBandToDrawList.length]; |
80 |
for (int i = 0; i < rasterBufBandToDrawList.length; i++) |
81 |
drawBands[i] = rasterBufBandToDrawList[i]; |
82 |
result.rasterBufBandToDrawList = drawBands; |
83 |
} |
84 |
return result;
|
85 |
} |
86 |
|
87 |
/**
|
88 |
* Resetea la asignaci?n de dibujado de las bandas de la imagen
|
89 |
* sobre el DataImage cuando se hace un update para esta banda.
|
90 |
*/
|
91 |
public void clearDrawableBands(){ |
92 |
rasterBufBandToDrawList = null;
|
93 |
} |
94 |
|
95 |
//******************************
|
96 |
//Setters and Getters
|
97 |
//******************************
|
98 |
|
99 |
/**
|
100 |
* Obtiene las banda del RasterBuf sobre la que se pinta
|
101 |
* este objeto banda
|
102 |
* @return bandas del RasterBuf
|
103 |
*/
|
104 |
public int[] getBufferBandListToDraw() { |
105 |
return rasterBufBandToDrawList;
|
106 |
} |
107 |
|
108 |
/**
|
109 |
* Obtiene las banda del RasterBuf sobre la que se pinta
|
110 |
* este objeto banda
|
111 |
* @return bandas del RasterBuf
|
112 |
*/
|
113 |
public int[] getLocalBufferBandListToDraw() { |
114 |
return rasterBufBandToDrawList;
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* Dice si la banda se est? dibujando en el buffers de salida.
|
119 |
* @return true si la banda se est? dibujando y false si no se est? haciendo
|
120 |
*/
|
121 |
public boolean isDrawing(){ |
122 |
if(this.rasterBufBandToDrawList == null) |
123 |
return false; |
124 |
return true; |
125 |
} |
126 |
|
127 |
/**
|
128 |
* Asigna una banda del RasterBuf sobre la que se pinta
|
129 |
* este objeto banda
|
130 |
* @param rasterBufBandToDraw banda del RasterBuf
|
131 |
*/
|
132 |
public void setPositionToDrawInBuffer(int rasterBufBandToDraw) { |
133 |
if (rasterBufBandToDrawList == null) { |
134 |
rasterBufBandToDrawList = new int[1]; |
135 |
rasterBufBandToDrawList[0] = rasterBufBandToDraw;
|
136 |
} else {
|
137 |
int[] auxList = new int[rasterBufBandToDrawList.length + 1]; |
138 |
for (int i = 0; i < rasterBufBandToDrawList.length; i++) |
139 |
auxList[i] = rasterBufBandToDrawList[i]; |
140 |
auxList[rasterBufBandToDrawList.length] = rasterBufBandToDraw; |
141 |
rasterBufBandToDrawList = auxList; |
142 |
} |
143 |
} |
144 |
|
145 |
/**
|
146 |
* Obtiene el nombre del fichero al que pertenece la banda
|
147 |
* @return String con el nombre del fichero al
|
148 |
* que pertenece la banda
|
149 |
*/
|
150 |
public String getFileName() { |
151 |
return fileName;
|
152 |
} |
153 |
|
154 |
/**
|
155 |
* Asigna el nombre del fichero al que pertenece la banda
|
156 |
* @param fileName String con el nombre del fichero al
|
157 |
* que pertenece la banda
|
158 |
*/
|
159 |
public void setFileName(String fileName) { |
160 |
this.fileName = fileName;
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* Obtiene la posici?n de la banda en el fichero
|
165 |
* @return entero con la posici?n de la banda en el fichero
|
166 |
*/
|
167 |
public int getPosition() { |
168 |
return position;
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* Asigna la posici?n de la banda en el fichero
|
173 |
* @param position Posici?n de la banda en el fichero
|
174 |
*/
|
175 |
public void setPosition(int position) { |
176 |
this.position = position;
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* Obtiene el tipo de dato de la banda
|
181 |
* @return entero con el tipo de dato
|
182 |
*/
|
183 |
public int getDataType() { |
184 |
return dataType;
|
185 |
} |
186 |
|
187 |
/**
|
188 |
* Asigna el tipo de dato de la banda
|
189 |
* @param datatype entero con el tipo de dato de la banda
|
190 |
*/
|
191 |
public void setDataType(int dataType) { |
192 |
this.dataType = dataType;
|
193 |
} |
194 |
|
195 |
/**
|
196 |
* Asigna un nombre de fichero adicional al principal. Esto es util para
|
197 |
* mosaicos de raster donde una banda est? compuesta por multiples ficheros.
|
198 |
*/
|
199 |
@SuppressWarnings("unchecked") |
200 |
public void setAdditionalName(String fileName) { |
201 |
additionalName.add(fileName); |
202 |
} |
203 |
|
204 |
/**
|
205 |
* Obtiene la lista de nombres de fichero adicionales.
|
206 |
* @return String[]
|
207 |
*/
|
208 |
public String[] getAdditionalName() { |
209 |
return (String[]) additionalName.toArray(); |
210 |
} |
211 |
|
212 |
/*
|
213 |
* (non-Javadoc)
|
214 |
* @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState)
|
215 |
*/
|
216 |
@SuppressWarnings("unchecked") |
217 |
public void loadFromState(PersistentState state) |
218 |
throws PersistenceException {
|
219 |
List<String> aux = state.getList("additionalName"); |
220 |
this.additionalName = new ArrayList<String>(); |
221 |
this.additionalName.addAll(aux);
|
222 |
|
223 |
try {
|
224 |
URI uri = state.getURI("fileName"); |
225 |
if(uri != null) { |
226 |
fileName = uri.toString(); |
227 |
if(uri.getScheme() == null || "file".equalsIgnoreCase(uri.getScheme())) |
228 |
fileName = uri.getPath(); |
229 |
} |
230 |
} catch(ClassCastException e) { |
231 |
fileName = state.getString("fileName");
|
232 |
} |
233 |
|
234 |
this.position = state.getInt("position"); |
235 |
this.dataType = state.getInt("dataType"); |
236 |
this.nBandsInThisProvider = state.getInt("nBandsInThisProvider"); |
237 |
this.rasterBufBandToDrawList = (int[])state.getIntArray("rasterBufBandToDrawList"); |
238 |
} |
239 |
|
240 |
/*
|
241 |
* (non-Javadoc)
|
242 |
* @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState)
|
243 |
*/
|
244 |
public void saveToState(PersistentState state) throws PersistenceException { |
245 |
try {
|
246 |
state.set("fileName", new URI(fileName)); |
247 |
} catch (URISyntaxException e) { |
248 |
throw new PersistenceException(e); |
249 |
} |
250 |
state.set("position", position);
|
251 |
state.set("dataType", dataType);
|
252 |
state.set("nBandsInThisProvider", nBandsInThisProvider);
|
253 |
state.set("additionalName", additionalName);
|
254 |
state.set("rasterBufBandToDrawList", rasterBufBandToDrawList);
|
255 |
} |
256 |
|
257 |
public static void registerPersistence() { |
258 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
259 |
DynStruct definition = manager.getDefinition(PERSISTENT_NAME); |
260 |
if( definition == null ) { |
261 |
definition = manager.addDefinition( |
262 |
DatasetBandImpl.class, |
263 |
PERSISTENT_NAME, |
264 |
PERSISTENT_DESCRIPTION, |
265 |
null,
|
266 |
null
|
267 |
); |
268 |
|
269 |
definition.addDynFieldURI("fileName").setMandatory(false); |
270 |
definition.addDynFieldInt("position").setMandatory(false); |
271 |
definition.addDynFieldList("additionalName").setClassOfItems(String.class).setMandatory(false); |
272 |
definition.addDynFieldList("rasterBufBandToDrawList").setClassOfItems(int.class).setMandatory(false); |
273 |
definition.addDynFieldInt("dataType").setMandatory(false); |
274 |
definition.addDynFieldInt("nBandsInThisProvider").setMandatory(false); |
275 |
} |
276 |
} |
277 |
} |