svn-gvsig-desktop / tags / v1_0_2_Build_914 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / StatusLayerRaster.java @ 12200
History | View | Annotate | Download (6.52 KB)
1 | 2183 | fernando | /* 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 | 5979 | nacho | import org.cresques.filter.RasterFilterStackManager; |
46 | 2183 | fernando | 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 | 4586 | nacho | * getXMLEntity
|
55 | *
|
||
56 | * @author Nacho Brodin (brodin_ign@gva.es)
|
||
57 | 2183 | fernando | */
|
58 | public class StatusLayerRaster implements StatusRasterInterface{ |
||
59 | |||
60 | 4234 | nacho | public static String defaultClass = "com.iver.cit.gvsig.fmap.layers.StatusLayerRaster"; |
61 | 2183 | fernando | |
62 | //Valor de opacidad global de la imagen
|
||
63 | 2767 | nacho | public int transparency = 0; |
64 | 2183 | fernando | |
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 | 4600 | nacho | |
76 | 2183 | fernando | /* (non-Javadoc)
|
77 | * @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
78 | */
|
||
79 | 2623 | nacho | public void setXMLEntity(XMLEntity xml, RasterOperations layer)throws XMLException { |
80 | 4234 | nacho | |
81 | //Recuperamos las propiedades de los filtros
|
||
82 | for(int i=0;i<xml.getPropertyCount();i++){ |
||
83 | 4592 | nacho | if(xml.getPropertyName(i).startsWith("filter.")) |
84 | 4234 | nacho | filters.add(xml.getPropertyName(i)+"="+xml.getPropertyValue(i));
|
85 | } |
||
86 | |||
87 | 2183 | fernando | 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 | 2653 | nacho | |
100 | 2183 | fernando | 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 | 2623 | nacho | public void getXMLEntity(XMLEntity xml, boolean loadClass, RasterOperations layer) throws XMLException { |
115 | 2183 | fernando | |
116 | if(loadClass)
|
||
117 | 4234 | nacho | xml.putProperty("raster.class", StatusLayerRaster.defaultClass);
|
118 | 2183 | fernando | |
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 | 2647 | nacho | |
127 | 2183 | fernando | 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 | 2633 | nacho | //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 | 2183 | fernando | |
138 | 2633 | nacho | RasterFilterStackManager stackManager = null;
|
139 | ArrayList l = null; |
||
140 | if(layer.getFilterStack()!=null){ |
||
141 | stackManager = new RasterFilterStackManager(layer.getFilterStack());
|
||
142 | l = stackManager.getStringsFromStack(); |
||
143 | 2647 | nacho | if(l == null || l.size() == 0) |
144 | l = filters; |
||
145 | 2633 | nacho | }else
|
146 | l = filters; |
||
147 | |||
148 | 4234 | nacho | for(int i=0;i<l.size();i++) |
149 | 2183 | fernando | 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 | 4586 | nacho | |
184 | 2183 | fernando | /* (non-Javadoc)
|
185 | * @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#applyStatus(com.iver.cit.gvsig.fmap.layers.RasterFileAdapter)
|
||
186 | */
|
||
187 | 2623 | nacho | public void applyStatus(RasterOperations layer){ |
188 | 4234 | nacho | |
189 | 2183 | fernando | //Eliminamos el fichero inicial y cargamos las bandas si hay para que se carguen
|
190 | //en el orden correcto
|
||
191 | 2623 | nacho | if(layer instanceof FLyrRaster){ |
192 | if(files.size()!=0){ |
||
193 | 10195 | nacho | ((FLyrRaster)layer).delFile((String)files.get(0)); |
194 | 2623 | nacho | for(int i=0;i<files.size();i++) |
195 | ((FLyrRaster)layer).addFiles((String)files.get(i));
|
||
196 | } |
||
197 | 2183 | fernando | } |
198 | |||
199 | //Asigna las bandas
|
||
200 | 2372 | igbrotru | if(bandR==-1)bandR=0; |
201 | if(bandG==-1)bandG=0; |
||
202 | if(bandB==-1)bandB=0; |
||
203 | 2623 | nacho | layer.setBand(GeoRasterFile.RED_BAND, bandR); |
204 | layer.setBand(GeoRasterFile.GREEN_BAND, bandG); |
||
205 | layer.setBand(GeoRasterFile.BLUE_BAND, bandB); |
||
206 | 2378 | igbrotru | |
207 | //Asigna la transparencia
|
||
208 | 6007 | nacho | if(transparency != 255) |
209 | 2378 | igbrotru | layer.setTransparency(transparency); |
210 | 4234 | nacho | |
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 | 7106 | nacho | if(layer instanceof FLyrRaster) |
215 | stackManager.createStackFromStrings(this.filters, ((FLyrRaster)layer).getSource().getFiles());
|
||
216 | else
|
||
217 | stackManager.createStackFromStrings(this.filters, new Integer(0)); |
||
218 | 4234 | nacho | } |
219 | 2378 | igbrotru | |
220 | 2183 | fernando | } |
221 | } |