svn-gvsig-desktop / tags / v1_0_2_Build_905 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / StatusLayerRaster.java @ 10767
History | View | Annotate | Download (6.52 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.layers; |
42 |
|
43 |
import java.util.ArrayList; |
44 |
|
45 |
import org.cresques.filter.RasterFilterStackManager; |
46 |
import org.cresques.io.GeoRasterFile; |
47 |
|
48 |
import com.iver.utiles.XMLEntity; |
49 |
|
50 |
/**
|
51 |
* Esta clase almacena el estado de un raster en cuanto a las caracteristicas
|
52 |
* de opacidad, bandas y filtros. Estas caracter?sticas pueden ser salvadas a
|
53 |
* un xml y recuperadas por la capa a trav?s de las funciones setXMLEntity y
|
54 |
* getXMLEntity
|
55 |
*
|
56 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
57 |
*/
|
58 |
public class StatusLayerRaster implements StatusRasterInterface{ |
59 |
|
60 |
public static String defaultClass = "com.iver.cit.gvsig.fmap.layers.StatusLayerRaster"; |
61 |
|
62 |
//Valor de opacidad global de la imagen
|
63 |
public int transparency = 0; |
64 |
|
65 |
//(Selecci?n de bandas)N?mero de banda asignado al Rojo, verde y azul
|
66 |
public int bandR = 0; |
67 |
public int bandG = 1; |
68 |
public int bandB = 2; |
69 |
|
70 |
//Ficheros cargados en un PxRaster
|
71 |
public ArrayList files = new ArrayList(); |
72 |
|
73 |
//Filtros para poder montar una nueva pila
|
74 |
public ArrayList filters = new ArrayList(); |
75 |
|
76 |
/* (non-Javadoc)
|
77 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#setXMLEntity(com.iver.utiles.XMLEntity)
|
78 |
*/
|
79 |
public void setXMLEntity(XMLEntity xml, RasterOperations layer)throws XMLException { |
80 |
|
81 |
//Recuperamos las propiedades de los filtros
|
82 |
for(int i=0;i<xml.getPropertyCount();i++){ |
83 |
if(xml.getPropertyName(i).startsWith("filter.")) |
84 |
filters.add(xml.getPropertyName(i)+"="+xml.getPropertyValue(i));
|
85 |
} |
86 |
|
87 |
if (xml.contains("raster.opacityLevel")) { |
88 |
transparency = xml.getIntProperty("raster.opacityLevel");
|
89 |
} |
90 |
if (xml.contains("raster.bandR")) { |
91 |
bandR = xml.getIntProperty("raster.bandR");
|
92 |
} |
93 |
if (xml.contains("raster.bandG")) { |
94 |
bandG = xml.getIntProperty("raster.bandG");
|
95 |
} |
96 |
if (xml.contains("raster.bandB")) { |
97 |
bandB = xml.getIntProperty("raster.bandB");
|
98 |
} |
99 |
|
100 |
int cont = 0; |
101 |
while(true && cont<50){ |
102 |
if (xml.contains("raster.file"+cont)) { |
103 |
files.add(xml.getStringProperty("raster.file"+cont));
|
104 |
cont++; |
105 |
}else
|
106 |
break;
|
107 |
} |
108 |
} |
109 |
|
110 |
|
111 |
/* (non-Javadoc)
|
112 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getXMLEntity(com.iver.utiles.XMLEntity)
|
113 |
*/
|
114 |
public void getXMLEntity(XMLEntity xml, boolean loadClass, RasterOperations layer) throws XMLException { |
115 |
|
116 |
if(loadClass)
|
117 |
xml.putProperty("raster.class", StatusLayerRaster.defaultClass);
|
118 |
|
119 |
if(transparency!=255) |
120 |
xml.putProperty("raster.opacityLevel", ""+transparency); |
121 |
|
122 |
xml.putProperty("raster.bandR", ""+bandR); |
123 |
xml.putProperty("raster.bandG", ""+bandG); |
124 |
xml.putProperty("raster.bandB", ""+bandB); |
125 |
|
126 |
|
127 |
if(files!=null && files.size()!=0){ |
128 |
for(int i=0;i<files.size();i++) |
129 |
xml.putProperty("raster.file"+i, ""+((String)files.get(i))); |
130 |
} |
131 |
|
132 |
//Salvamos la pila de filtros.
|
133 |
//Si la pila es null (esto puede ocurrir cuando se abre un
|
134 |
//proyecto que tiene WCS y no se abre la vista de este) entonces hay que leer los filtros
|
135 |
//que van a salvarse a disco directamente de la variable filters que es la que se ha cargado
|
136 |
//al hacer el setXMLEntity.
|
137 |
|
138 |
RasterFilterStackManager stackManager = null;
|
139 |
ArrayList l = null; |
140 |
if(layer.getFilterStack()!=null){ |
141 |
stackManager = new RasterFilterStackManager(layer.getFilterStack());
|
142 |
l = stackManager.getStringsFromStack(); |
143 |
if(l == null || l.size() == 0) |
144 |
l = filters; |
145 |
}else
|
146 |
l = filters; |
147 |
|
148 |
for(int i=0;i<l.size();i++) |
149 |
xml.putProperty(getElem((String)l.get(i)), getValue((String)l.get(i))); |
150 |
} |
151 |
|
152 |
/**
|
153 |
* Obtiene el valor de una cadena de la forma elemento=valor
|
154 |
* @param cadena
|
155 |
* @return
|
156 |
*/
|
157 |
private String getValue(String cadena){ |
158 |
if(cadena!=null) |
159 |
return cadena.substring(cadena.indexOf("=")+1, cadena.length()); |
160 |
else
|
161 |
return null; |
162 |
} |
163 |
|
164 |
/**
|
165 |
* Obtiene el elemento de una cadena de la forma elemento=valor
|
166 |
* @param cadena
|
167 |
* @return
|
168 |
*/
|
169 |
private String getElem(String cadena){ |
170 |
if(cadena!=null) |
171 |
return cadena.substring(0, cadena.indexOf("=")); |
172 |
else
|
173 |
return null; |
174 |
} |
175 |
|
176 |
/* (non-Javadoc)
|
177 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getFilters()
|
178 |
*/
|
179 |
public ArrayList getFilters(){ |
180 |
return this.filters; |
181 |
} |
182 |
|
183 |
|
184 |
/* (non-Javadoc)
|
185 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#applyStatus(com.iver.cit.gvsig.fmap.layers.RasterFileAdapter)
|
186 |
*/
|
187 |
public void applyStatus(RasterOperations layer){ |
188 |
|
189 |
//Eliminamos el fichero inicial y cargamos las bandas si hay para que se carguen
|
190 |
//en el orden correcto
|
191 |
if(layer instanceof FLyrRaster){ |
192 |
if(files.size()!=0){ |
193 |
((FLyrRaster)layer).delFile((String)files.get(0)); |
194 |
for(int i=0;i<files.size();i++) |
195 |
((FLyrRaster)layer).addFiles((String)files.get(i));
|
196 |
} |
197 |
} |
198 |
|
199 |
//Asigna las bandas
|
200 |
if(bandR==-1)bandR=0; |
201 |
if(bandG==-1)bandG=0; |
202 |
if(bandB==-1)bandB=0; |
203 |
layer.setBand(GeoRasterFile.RED_BAND, bandR); |
204 |
layer.setBand(GeoRasterFile.GREEN_BAND, bandG); |
205 |
layer.setBand(GeoRasterFile.BLUE_BAND, bandB); |
206 |
|
207 |
//Asigna la transparencia
|
208 |
if(transparency != 255) |
209 |
layer.setTransparency(transparency); |
210 |
|
211 |
//Crea la pila de filtros a partir de las propiedades recuperadas desde el XML
|
212 |
if(layer.getFilterStack() != null){ |
213 |
RasterFilterStackManager stackManager = new RasterFilterStackManager(layer.getFilterStack());
|
214 |
if(layer instanceof FLyrRaster) |
215 |
stackManager.createStackFromStrings(this.filters, ((FLyrRaster)layer).getSource().getFiles());
|
216 |
else
|
217 |
stackManager.createStackFromStrings(this.filters, new Integer(0)); |
218 |
} |
219 |
|
220 |
} |
221 |
} |