svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / StatusLayerRaster.java @ 4910
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 | 4586 | nacho | import java.lang.reflect.Constructor; |
44 | import java.lang.reflect.InvocationTargetException; |
||
45 | 2183 | fernando | import java.util.ArrayList; |
46 | |||
47 | import org.cresques.io.GeoRasterFile; |
||
48 | import org.cresques.io.raster.RasterFilterStackManager; |
||
49 | |||
50 | import com.iver.utiles.XMLEntity; |
||
51 | |||
52 | /**
|
||
53 | * Esta clase almacena el estado de un raster en cuanto a las caracteristicas
|
||
54 | * de opacidad, bandas y filtros. Estas caracter?sticas pueden ser salvadas a
|
||
55 | * un xml y recuperadas por la capa a trav?s de las funciones setXMLEntity y
|
||
56 | 4586 | nacho | * getXMLEntity
|
57 | *
|
||
58 | * @author Nacho Brodin (brodin_ign@gva.es)
|
||
59 | 2183 | fernando | */
|
60 | public class StatusLayerRaster implements StatusRasterInterface{ |
||
61 | |||
62 | 4234 | nacho | public static String defaultClass = "com.iver.cit.gvsig.fmap.layers.StatusLayerRaster"; |
63 | 2183 | fernando | |
64 | //Valor de opacidad global de la imagen
|
||
65 | 2767 | nacho | public int transparency = 0; |
66 | 2183 | fernando | |
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 | 4600 | nacho | |
78 | 2183 | fernando | /* (non-Javadoc)
|
79 | * @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
80 | */
|
||
81 | 2623 | nacho | public void setXMLEntity(XMLEntity xml, RasterOperations layer)throws XMLException { |
82 | 4234 | nacho | |
83 | //Recuperamos las propiedades de los filtros
|
||
84 | for(int i=0;i<xml.getPropertyCount();i++){ |
||
85 | 4592 | nacho | if(xml.getPropertyName(i).startsWith("filter.")) |
86 | 4234 | nacho | filters.add(xml.getPropertyName(i)+"="+xml.getPropertyValue(i));
|
87 | } |
||
88 | |||
89 | 2183 | fernando | if (xml.contains("raster.opacityLevel")) { |
90 | transparency = xml.getIntProperty("raster.opacityLevel");
|
||
91 | } |
||
92 | if (xml.contains("raster.bandR")) { |
||
93 | bandR = xml.getIntProperty("raster.bandR");
|
||
94 | } |
||
95 | if (xml.contains("raster.bandG")) { |
||
96 | bandG = xml.getIntProperty("raster.bandG");
|
||
97 | } |
||
98 | if (xml.contains("raster.bandB")) { |
||
99 | bandB = xml.getIntProperty("raster.bandB");
|
||
100 | } |
||
101 | 2653 | nacho | |
102 | 2183 | fernando | int cont = 0; |
103 | while(true && cont<50){ |
||
104 | if (xml.contains("raster.file"+cont)) { |
||
105 | files.add(xml.getStringProperty("raster.file"+cont));
|
||
106 | cont++; |
||
107 | }else
|
||
108 | break;
|
||
109 | } |
||
110 | } |
||
111 | |||
112 | |||
113 | /* (non-Javadoc)
|
||
114 | * @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getXMLEntity(com.iver.utiles.XMLEntity)
|
||
115 | */
|
||
116 | 2623 | nacho | public void getXMLEntity(XMLEntity xml, boolean loadClass, RasterOperations layer) throws XMLException { |
117 | 2183 | fernando | |
118 | if(loadClass)
|
||
119 | 4234 | nacho | xml.putProperty("raster.class", StatusLayerRaster.defaultClass);
|
120 | 2183 | fernando | |
121 | if(transparency!=255) |
||
122 | xml.putProperty("raster.opacityLevel", ""+transparency); |
||
123 | |||
124 | xml.putProperty("raster.bandR", ""+bandR); |
||
125 | xml.putProperty("raster.bandG", ""+bandG); |
||
126 | xml.putProperty("raster.bandB", ""+bandB); |
||
127 | |||
128 | 2647 | nacho | |
129 | 2183 | fernando | if(files!=null && files.size()!=0){ |
130 | for(int i=0;i<files.size();i++) |
||
131 | xml.putProperty("raster.file"+i, ""+((String)files.get(i))); |
||
132 | } |
||
133 | |||
134 | 2633 | nacho | //Salvamos la pila de filtros.
|
135 | //Si la pila es null (esto puede ocurrir cuando se abre un
|
||
136 | //proyecto que tiene WCS y no se abre la vista de este) entonces hay que leer los filtros
|
||
137 | //que van a salvarse a disco directamente de la variable filters que es la que se ha cargado
|
||
138 | //al hacer el setXMLEntity.
|
||
139 | 2183 | fernando | |
140 | 2633 | nacho | RasterFilterStackManager stackManager = null;
|
141 | ArrayList l = null; |
||
142 | if(layer.getFilterStack()!=null){ |
||
143 | stackManager = new RasterFilterStackManager(layer.getFilterStack());
|
||
144 | l = stackManager.getStringsFromStack(); |
||
145 | 2647 | nacho | if(l == null || l.size() == 0) |
146 | l = filters; |
||
147 | 2633 | nacho | }else
|
148 | l = filters; |
||
149 | |||
150 | 4234 | nacho | for(int i=0;i<l.size();i++) |
151 | 2183 | fernando | xml.putProperty(getElem((String)l.get(i)), getValue((String)l.get(i))); |
152 | } |
||
153 | |||
154 | /**
|
||
155 | * Obtiene el valor de una cadena de la forma elemento=valor
|
||
156 | * @param cadena
|
||
157 | * @return
|
||
158 | */
|
||
159 | private String getValue(String cadena){ |
||
160 | if(cadena!=null) |
||
161 | return cadena.substring(cadena.indexOf("=")+1, cadena.length()); |
||
162 | else
|
||
163 | return null; |
||
164 | } |
||
165 | |||
166 | /**
|
||
167 | * Obtiene el elemento de una cadena de la forma elemento=valor
|
||
168 | * @param cadena
|
||
169 | * @return
|
||
170 | */
|
||
171 | private String getElem(String cadena){ |
||
172 | if(cadena!=null) |
||
173 | return cadena.substring(0, cadena.indexOf("=")); |
||
174 | else
|
||
175 | return null; |
||
176 | } |
||
177 | |||
178 | /* (non-Javadoc)
|
||
179 | * @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getFilters()
|
||
180 | */
|
||
181 | public ArrayList getFilters(){ |
||
182 | return this.filters; |
||
183 | } |
||
184 | |||
185 | 4586 | nacho | |
186 | 2183 | fernando | /* (non-Javadoc)
|
187 | * @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#applyStatus(com.iver.cit.gvsig.fmap.layers.RasterFileAdapter)
|
||
188 | */
|
||
189 | 2623 | nacho | public void applyStatus(RasterOperations layer){ |
190 | 4234 | nacho | |
191 | 2183 | fernando | //Eliminamos el fichero inicial y cargamos las bandas si hay para que se carguen
|
192 | //en el orden correcto
|
||
193 | 2623 | nacho | if(layer instanceof FLyrRaster){ |
194 | if(files.size()!=0){ |
||
195 | ((FLyrRaster)layer).delFile(layer.getSource().getFiles()[0].getName());
|
||
196 | for(int i=0;i<files.size();i++) |
||
197 | ((FLyrRaster)layer).addFiles((String)files.get(i));
|
||
198 | } |
||
199 | 2183 | fernando | } |
200 | |||
201 | //Asigna las bandas
|
||
202 | 2372 | igbrotru | if(bandR==-1)bandR=0; |
203 | if(bandG==-1)bandG=0; |
||
204 | if(bandB==-1)bandB=0; |
||
205 | 2623 | nacho | layer.setBand(GeoRasterFile.RED_BAND, bandR); |
206 | layer.setBand(GeoRasterFile.GREEN_BAND, bandG); |
||
207 | layer.setBand(GeoRasterFile.BLUE_BAND, bandB); |
||
208 | 2378 | igbrotru | |
209 | //Asigna la transparencia
|
||
210 | |||
211 | if(transparency!=255) |
||
212 | layer.setTransparency(transparency); |
||
213 | 4234 | nacho | |
214 | //Crea la pila de filtros a partir de las propiedades recuperadas desde el XML
|
||
215 | if(layer.getFilterStack() != null){ |
||
216 | RasterFilterStackManager stackManager = new RasterFilterStackManager(layer.getFilterStack());
|
||
217 | 4592 | nacho | stackManager.createStackFromStrings(this.filters, ((FLyrRaster)layer).getSource().getFiles());
|
218 | 4234 | nacho | } |
219 | 2378 | igbrotru | |
220 | 2183 | fernando | } |
221 | } |