root / trunk / extensions / extRasterTools-SE / src / org / gvsig / fmap / layers / StatusLayerRaster.java @ 12197
History | View | Annotate | Download (8.37 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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 |
package org.gvsig.fmap.layers; |
20 |
|
21 |
import java.util.ArrayList; |
22 |
|
23 |
import org.gvsig.raster.grid.GridTransparency; |
24 |
import org.gvsig.raster.grid.filter.RasterFilterListManager; |
25 |
import org.gvsig.raster.shared.IRasterProperties; |
26 |
import org.gvsig.raster.util.TransparencyRange; |
27 |
|
28 |
import com.iver.andami.PluginServices; |
29 |
import com.iver.andami.ui.mdiManager.IWindow; |
30 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
31 |
import com.iver.cit.gvsig.project.documents.view.gui.IView; |
32 |
import com.iver.utiles.XMLEntity; |
33 |
|
34 |
/**
|
35 |
* Esta clase almacena el estado de un raster en cuanto a las caracteristicas
|
36 |
* de opacidad, bandas y filtros. Estas caracter?sticas pueden ser salvadas a
|
37 |
* un xml y recuperadas por la capa a trav?s de las funciones setXMLEntity y
|
38 |
* getXMLEntity
|
39 |
*
|
40 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
41 |
*/
|
42 |
public class StatusLayerRaster implements StatusRasterInterface { |
43 |
|
44 |
public static String defaultClass = "org.gvsig.fmap.layers.StatusLayerRaster"; |
45 |
|
46 |
//Valor de opacidad global de la imagen
|
47 |
public int transparency = 255; |
48 |
|
49 |
//Rangos de transparencia
|
50 |
public ArrayList ranges = new ArrayList(); |
51 |
|
52 |
//(Selecci?n de bandas)N?mero de banda asignado al Rojo, verde y azul
|
53 |
public int bandR = 0; |
54 |
public int bandG = 1; |
55 |
public int bandB = 2; |
56 |
|
57 |
//Ficheros cargados en un PxRaster
|
58 |
public ArrayList files = new ArrayList(); |
59 |
|
60 |
//Filtros para poder montar una nueva pila
|
61 |
public ArrayList filters = new ArrayList(); |
62 |
|
63 |
/* (non-Javadoc)
|
64 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#setXMLEntity(com.iver.utiles.XMLEntity)
|
65 |
*/
|
66 |
public void setXMLEntity(XMLEntity xml, IRasterProperties layer)throws XMLException { |
67 |
//RECUPERAR PROPIEDADES
|
68 |
|
69 |
//Recuperamos las propiedades de los filtros
|
70 |
for(int i = 0; i < xml.getPropertyCount(); i++) { |
71 |
if(xml.getPropertyName(i).startsWith("filter.")) |
72 |
filters.add(xml.getPropertyName(i) + "=" + xml.getPropertyValue(i));
|
73 |
} |
74 |
|
75 |
//Rangos de transparencia
|
76 |
if (xml.contains("filter.transparency.active") && xml.getBooleanProperty("filter.transparency.active")) { |
77 |
int i = 0; |
78 |
String value = null; |
79 |
while(true) { |
80 |
if(xml.contains("filter.transparency.transparencyRange" + i)) { |
81 |
value = xml.getStringProperty("filter.transparency.transparencyRange" + i);
|
82 |
int alpha = 0; |
83 |
if(value.indexOf("@") != 0) { |
84 |
try {
|
85 |
alpha = Integer.parseInt(value.substring(value.indexOf("@") + 1, value.length())); |
86 |
} catch (NumberFormatException e) { |
87 |
alpha = 0;
|
88 |
} |
89 |
value = value.substring(0, value.indexOf("@")); |
90 |
} |
91 |
TransparencyRange range = new TransparencyRange(value);
|
92 |
if(alpha != 0) |
93 |
range.setAlpha(alpha); |
94 |
ranges.add(range); |
95 |
} else
|
96 |
break;
|
97 |
i ++; |
98 |
} |
99 |
} |
100 |
|
101 |
if (xml.contains("raster.opacityLevel")) |
102 |
transparency = xml.getIntProperty("raster.opacityLevel");
|
103 |
|
104 |
if (xml.contains("raster.bandR")) |
105 |
bandR = xml.getIntProperty("raster.bandR");
|
106 |
|
107 |
if (xml.contains("raster.bandG")) |
108 |
bandG = xml.getIntProperty("raster.bandG");
|
109 |
|
110 |
if (xml.contains("raster.bandB")) |
111 |
bandB = xml.getIntProperty("raster.bandB");
|
112 |
|
113 |
|
114 |
int cont = 0; |
115 |
while(true && cont < 50) { |
116 |
if (xml.contains("raster.file" + cont)) { |
117 |
files.add(xml.getStringProperty("raster.file" + cont));
|
118 |
cont++; |
119 |
}else
|
120 |
break;
|
121 |
} |
122 |
} |
123 |
|
124 |
|
125 |
/* (non-Javadoc)
|
126 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getXMLEntity(com.iver.utiles.XMLEntity)
|
127 |
*/
|
128 |
public void getXMLEntity(XMLEntity xml, boolean loadClass, IRasterProperties layer) throws XMLException { |
129 |
//SALVAR PROPIEDADES
|
130 |
|
131 |
if(loadClass)
|
132 |
xml.putProperty("raster.class", StatusLayerRaster.defaultClass);
|
133 |
|
134 |
//Opacidad
|
135 |
GridTransparency transp = layer.getRender().getLastTransparency(); |
136 |
if(transp.getOpacity() != 255) |
137 |
xml.putProperty("raster.opacityLevel", "" + transp.getOpacity()); |
138 |
|
139 |
//Rangos de transparencia
|
140 |
if(transp.getTransparencyRange().size() > 0) { |
141 |
xml.putProperty("filter.transparency.active", "true"); |
142 |
for (int i = 0; i < transp.getTransparencyRange().size(); i++) |
143 |
xml.putProperty("filter.transparency.transparencyRange" + i, "" + ((TransparencyRange)transp.getTransparencyRange().get(i)).getStrEntry() + "@" + ((TransparencyRange)transp.getTransparencyRange().get(i)).getAlpha()); |
144 |
} |
145 |
|
146 |
//Posici?n de visualizado de bandas
|
147 |
xml.putProperty("raster.bandR", "" + layer.getRender().getRenderBands()[0]); |
148 |
xml.putProperty("raster.bandG", "" + layer.getRender().getRenderBands()[1]); |
149 |
xml.putProperty("raster.bandB", "" + layer.getRender().getRenderBands()[2]); |
150 |
|
151 |
//Ficheros
|
152 |
if(files != null && layer.getFileCount() != 0){ |
153 |
for(int i = 0; i < layer.getFileCount(); i++) |
154 |
xml.putProperty("raster.file" + i, "" + layer.getFileName()[i]); |
155 |
} |
156 |
|
157 |
//Salvamos la lista de filtros aplicada en la renderizaci?n.
|
158 |
//Si la lista es null (esto puede ocurrir cuando se abre un
|
159 |
//proyecto que tiene WCS y no se abre la vista de este) entonces hay que leer los filtros
|
160 |
//que van a salvarse a disco directamente de la variable filters que es la que se ha cargado
|
161 |
//al hacer el setXMLEntity.
|
162 |
|
163 |
|
164 |
//Filtros
|
165 |
RasterFilterListManager filterListManager = null;
|
166 |
ArrayList l = null; |
167 |
if(layer.getRenderFilterList() != null) { |
168 |
filterListManager = new RasterFilterListManager(layer.getRenderFilterList());
|
169 |
l = filterListManager.getStringsFromFilterList(); |
170 |
if(l == null || l.size() == 0) |
171 |
l = filters; |
172 |
}else
|
173 |
l = filters; |
174 |
|
175 |
for(int i = 0; i < l.size(); i++) |
176 |
xml.putProperty(getElem((String)l.get(i)), getValue((String)l.get(i))); |
177 |
} |
178 |
|
179 |
/**
|
180 |
* Obtiene el valor de una cadena de la forma elemento=valor
|
181 |
* @param cadena
|
182 |
* @return
|
183 |
*/
|
184 |
private String getValue(String cadena) { |
185 |
if(cadena!=null) |
186 |
return cadena.substring(cadena.indexOf("=") + 1, cadena.length()); |
187 |
else
|
188 |
return null; |
189 |
} |
190 |
|
191 |
/**
|
192 |
* Obtiene el elemento de una cadena de la forma elemento=valor
|
193 |
* @param cadena
|
194 |
* @return
|
195 |
*/
|
196 |
private String getElem(String cadena) { |
197 |
if(cadena != null) |
198 |
return cadena.substring(0, cadena.indexOf("=")); |
199 |
else
|
200 |
return null; |
201 |
} |
202 |
|
203 |
/* (non-Javadoc)
|
204 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getFilters()
|
205 |
*/
|
206 |
public ArrayList getFilters() { |
207 |
return this.filters; |
208 |
} |
209 |
|
210 |
|
211 |
/* (non-Javadoc)
|
212 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#applyStatus(com.iver.cit.gvsig.fmap.layers.RasterFileAdapter)
|
213 |
*/
|
214 |
public void applyStatus(IRasterProperties layer) { |
215 |
|
216 |
//Eliminamos el fichero inicial y cargamos las bandas si hay para que se carguen
|
217 |
//en el orden correcto
|
218 |
if(layer instanceof FLyrRasterSE) { |
219 |
if(files.size() != 0){ |
220 |
//((FLyrRasterSE)layer).delFile((String)files.get(0));
|
221 |
for(int i = 1; i < files.size(); i++) |
222 |
((FLyrRasterSE)layer).addFile((String)files.get(i));
|
223 |
} |
224 |
} |
225 |
|
226 |
//Asigna las bandas
|
227 |
int[] renderBands = new int[]{bandR, bandG, bandB}; |
228 |
layer.getRender().setRenderBands(renderBands); |
229 |
|
230 |
//Asigna la transparencia
|
231 |
GridTransparency transp = layer.getRender().getLastTransparency(); |
232 |
if(transparency != 255) { |
233 |
transp.setOpacity(transparency); |
234 |
transp.activeTransparency(); |
235 |
} |
236 |
|
237 |
//Rangos de transparencia
|
238 |
if(ranges != null) { |
239 |
transp.setTransparencyRangeList(ranges); |
240 |
transp.activeTransparency(); |
241 |
} |
242 |
|
243 |
//Filtros
|
244 |
if(layer.getRenderFilterList() != null) { |
245 |
RasterFilterListManager filterListManager = new RasterFilterListManager(layer.getRenderFilterList());
|
246 |
filterListManager.createFilterListFromStrings(filters); |
247 |
} |
248 |
|
249 |
//Refrescamos todas las vistas
|
250 |
IWindow[] w = PluginServices.getMDIManager().getAllWindows();
|
251 |
for (int i = 0; i < w.length; i++) { |
252 |
if(w[i] != null && w[i] instanceof IView) |
253 |
((IView)w[i]).getMapControl().getMapContext().invalidate(); |
254 |
} |
255 |
} |
256 |
} |