root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / StatusLayerRaster.java @ 2183
History | View | Annotate | Download (6.01 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 |
import java.util.StringTokenizer; |
45 |
|
46 |
import org.cresques.io.GeoRasterFile; |
47 |
import org.cresques.io.raster.RasterFilterStackManager; |
48 |
|
49 |
import com.iver.utiles.XMLEntity; |
50 |
|
51 |
/**
|
52 |
*
|
53 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
54 |
*
|
55 |
* Esta clase almacena el estado de un raster en cuanto a las caracteristicas
|
56 |
* de opacidad, bandas y filtros. Estas caracter?sticas pueden ser salvadas a
|
57 |
* un xml y recuperadas por la capa a trav?s de las funciones setXMLEntity y
|
58 |
* getXMLEntity
|
59 |
*/
|
60 |
public class StatusLayerRaster implements StatusRasterInterface{ |
61 |
|
62 |
public String clase = "com.iver.cit.gvsig.fmap.layers.StatusLayerRaster"; |
63 |
|
64 |
//Valor de opacidad global de la imagen
|
65 |
public int transparency = 100; |
66 |
|
67 |
//(Selecci?n de bandas)N?mero de banda asignado al Rojo, verde y azul
|
68 |
public int bandR = 0; |
69 |
public int bandG = 1; |
70 |
public int bandB = 2; |
71 |
|
72 |
//Ficheros cargados en un PxRaster
|
73 |
public ArrayList files = new ArrayList(); |
74 |
|
75 |
//Filtros para poder montar una nueva pila
|
76 |
public ArrayList filters = new ArrayList(); |
77 |
|
78 |
/* (non-Javadoc)
|
79 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#setXMLEntity(com.iver.utiles.XMLEntity)
|
80 |
*/
|
81 |
public void setXMLEntity(XMLEntity xml, FLyrRaster layer)throws XMLException { |
82 |
|
83 |
if (xml.contains("raster.opacityLevel")) { |
84 |
transparency = xml.getIntProperty("raster.opacityLevel");
|
85 |
} |
86 |
if (xml.contains("raster.bandR")) { |
87 |
bandR = xml.getIntProperty("raster.bandR");
|
88 |
} |
89 |
if (xml.contains("raster.bandG")) { |
90 |
bandG = xml.getIntProperty("raster.bandG");
|
91 |
} |
92 |
if (xml.contains("raster.bandB")) { |
93 |
bandB = xml.getIntProperty("raster.bandB");
|
94 |
} |
95 |
|
96 |
int cont = 0; |
97 |
while(true && cont<50){ |
98 |
if (xml.contains("raster.file"+cont)) { |
99 |
files.add(xml.getStringProperty("raster.file"+cont));
|
100 |
cont++; |
101 |
}else
|
102 |
break;
|
103 |
} |
104 |
|
105 |
//Recuperamos las propiedades de los filtros
|
106 |
for(int i=0;i<xml.getPropertyCount();i++){ |
107 |
if(xml.getPropertyName(i).startsWith("filter.")){ |
108 |
filters.add(xml.getPropertyName(i)+"="+xml.getPropertyValue(i));
|
109 |
//System.out.println("==>Recuperando "+xml.getPropertyName(i)+"="+xml.getPropertyValue(i));
|
110 |
} |
111 |
} |
112 |
|
113 |
} |
114 |
|
115 |
|
116 |
/* (non-Javadoc)
|
117 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getXMLEntity(com.iver.utiles.XMLEntity)
|
118 |
*/
|
119 |
public void getXMLEntity(XMLEntity xml, boolean loadClass, FLyrRaster layer) throws XMLException { |
120 |
|
121 |
if(loadClass)
|
122 |
xml.putProperty("raster.class", clase);
|
123 |
|
124 |
if(transparency!=255) |
125 |
xml.putProperty("raster.opacityLevel", ""+transparency); |
126 |
|
127 |
xml.putProperty("raster.bandR", ""+bandR); |
128 |
xml.putProperty("raster.bandG", ""+bandG); |
129 |
xml.putProperty("raster.bandB", ""+bandB); |
130 |
|
131 |
if(files!=null && files.size()!=0){ |
132 |
for(int i=0;i<files.size();i++) |
133 |
xml.putProperty("raster.file"+i, ""+((String)files.get(i))); |
134 |
} |
135 |
|
136 |
//salvamos la pila de filtros
|
137 |
|
138 |
RasterFilterStackManager stackManager |
139 |
= new RasterFilterStackManager(layer.getSource().getFilterStack());
|
140 |
ArrayList l = stackManager.getStringsFromStack();
|
141 |
for(int i=0;i<l.size();i++){ |
142 |
xml.putProperty(getElem((String)l.get(i)), getValue((String)l.get(i))); |
143 |
//System.out.println("==>"+getElem((String)l.get(i))+" "+getValue((String)l.get(i)));
|
144 |
} |
145 |
} |
146 |
|
147 |
/**
|
148 |
* Obtiene el valor de una cadena de la forma elemento=valor
|
149 |
* @param cadena
|
150 |
* @return
|
151 |
*/
|
152 |
private String getValue(String cadena){ |
153 |
if(cadena!=null) |
154 |
return cadena.substring(cadena.indexOf("=")+1, cadena.length()); |
155 |
else
|
156 |
return null; |
157 |
} |
158 |
|
159 |
/**
|
160 |
* Obtiene el elemento de una cadena de la forma elemento=valor
|
161 |
* @param cadena
|
162 |
* @return
|
163 |
*/
|
164 |
private String getElem(String cadena){ |
165 |
if(cadena!=null) |
166 |
return cadena.substring(0, cadena.indexOf("=")); |
167 |
else
|
168 |
return null; |
169 |
} |
170 |
|
171 |
/* (non-Javadoc)
|
172 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getFilters()
|
173 |
*/
|
174 |
public ArrayList getFilters(){ |
175 |
return this.filters; |
176 |
} |
177 |
|
178 |
/* (non-Javadoc)
|
179 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#applyStatus(com.iver.cit.gvsig.fmap.layers.RasterFileAdapter)
|
180 |
*/
|
181 |
public void applyStatus(FLyrRaster layer){ |
182 |
|
183 |
//Asigna la transparencia
|
184 |
if(transparency!=255) |
185 |
layer.getSource().setTransparency(transparency); |
186 |
|
187 |
//Crea la pila de filtros a partir de las propiedades recuperadas desde el XML
|
188 |
RasterFilterStackManager stackManager |
189 |
= new RasterFilterStackManager(layer.getSource().getFilterStack());
|
190 |
|
191 |
stackManager.createStackFromStrings(this.filters);
|
192 |
|
193 |
//Eliminamos el fichero inicial y cargamos las bandas si hay para que se carguen
|
194 |
//en el orden correcto
|
195 |
if(files.size()!=0){ |
196 |
layer.delFile(layer.getSource().getFiles()[0].getName());
|
197 |
for(int i=0;i<files.size();i++) |
198 |
layer.addFiles((String)files.get(i));
|
199 |
} |
200 |
|
201 |
//Asigna las bandas
|
202 |
layer.getSource().setBand(GeoRasterFile.RED_BAND, bandR); |
203 |
layer.getSource().setBand(GeoRasterFile.GREEN_BAND, bandG); |
204 |
layer.getSource().setBand(GeoRasterFile.BLUE_BAND, bandB); |
205 |
} |
206 |
} |