Revision 4181 org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/layers/StatusLayerRaster.java

View differences:

StatusLayerRaster.java
2 2
*
3 3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4 4
* of the Valencian Government (CIT)
5
* 
5
*
6 6
* This program is free software; you can redistribute it and/or
7 7
* modify it under the terms of the GNU General Public License
8 8
* as published by the Free Software Foundation; either version 2
9 9
* of the License, or (at your option) any later version.
10
* 
10
*
11 11
* This program is distributed in the hope that it will be useful,
12 12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
* GNU General Public License for more details.
15
* 
15
*
16 16
* You should have received a copy of the GNU General Public License
17 17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 19
* MA  02110-1301, USA.
20
* 
20
*
21 21
*/
22 22
package org.gvsig.raster.fmap.layers;
23 23

  
24
import java.io.File;
24 25
import java.util.ArrayList;
25 26
import java.util.List;
26 27

  
......
50 51

  
51 52
/**
52 53
 * Esta clase almacena el estado de un raster en cuanto a las caracteristicas
53
 * de opacidad, bandas y filtros. Estas caracter?sticas pueden ser salvadas a 
54
 * un xml y recuperadas por la capa a trav?s de las funciones setXMLEntity y 
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
55 56
 * getXMLEntity
56
 * 
57
 *
57 58
 * @deprecated
58 59
 * @author Nacho Brodin (nachobrodin@gmail.com)
59 60
 */
60 61
public class StatusLayerRaster implements IStatusRaster {
61 62

  
62 63
	public static String 			defaultClass    = "org.gvsig.fmap.raster.layers.StatusLayerRaster";
63
	
64

  
64 65
	//Valor de opacidad global de la imagen
65 66
	public int						transparency    = 255;
66
	
67

  
67 68
	//Rangos de transparencia
68
	public ArrayList<TransparencyRange>		
69
	public ArrayList<TransparencyRange>
69 70
	                                ranges          = new ArrayList<TransparencyRange>();
70
		
71
	//(Selecci?n de bandas)N?mero de banda  asignado al Rojo, verde y azul 	
71

  
72
	//(Selecci?n de bandas)N?mero de banda  asignado al Rojo, verde y azul
72 73
	public int 						bandR           = 0;
73 74
	public int 						bandG           = 1;
74 75
	public int 						bandB           = 2;
75
	
76
	public List<String>		        files           = new ArrayList<String>();
77
	
76

  
77
	public List<File>		        files           = new ArrayList<File>();
78

  
78 79
	//Filtros para poder montar una nueva pila
79 80
	public List<String>		        filters         = new ArrayList<String>();
80 81
	private DefaultFLyrRaster       layer           = null;
81 82
	private int                     alphaBandNumber = -1;
82
	
83

  
83 84
	//Utilizado para la persistencia
84 85
	private boolean 				loadClass		= false;
85
	
86

  
86 87
	public void loadFromState(PersistentState state, DefaultFLyrRaster layer)throws PersistenceException {
87 88
//		this.layer = layer;
88 89
//		//RECUPERAR PROPIEDADES
89
//		
90
//
90 91
//		//Recuperamos las propiedades de los filtros
91 92
//		for(int i = 0; i < xml.getPropertyCount(); i++) {
92
//			if(xml.getPropertyName(i).startsWith("filter."))	
93
//			if(xml.getPropertyName(i).startsWith("filter."))
93 94
//				filters.add(xml.getPropertyName(i) + "=" + xml.getPropertyValue(i));
94 95
//		}
95
//		
96
//
96 97
//		//Rangos de transparencia
97 98
//		if (xml.contains("filter.transparency.active") && xml.getBooleanProperty("filter.transparency.active")) {
98 99
//			int i = 0;
......
114 115
//					if(alpha != 0)
115 116
//						range.setAlpha(alpha);
116 117
//					ranges.add(range);
117
//				} else 
118
//				} else
118 119
//					break;
119 120
//				i ++;
120 121
//			}
121 122
//		}
122
//		
123
//		if(xml.contains("filter.transparency.bandnumber")) 
123
//
124
//		if(xml.contains("filter.transparency.bandnumber"))
124 125
//			alphaBandNumber = xml.getIntProperty("filter.transparency.bandnumber");
125
//		
126
//
126 127
//		if (xml.contains("raster.opacityLevel")) {
127 128
//			transparency = xml.getIntProperty("raster.opacityLevel");
128 129
//			//Esto soluciona un problema de compatibilidad entre branch v10 y HEAD. Eliminar en futuras versiones
129 130
//			if(nameClass != null && nameClass.compareTo("com.iver.cit.gvsig.fmap.layers.StatusLayerRaster") == 0)
130 131
//				transparency = 255 - transparency;
131 132
//		}
132
//				
133
//		if (xml.contains("raster.bandR")) 
133
//
134
//		if (xml.contains("raster.bandR"))
134 135
//			bandR = xml.getIntProperty("raster.bandR");
135
//		
136
//		if (xml.contains("raster.bandG")) 
136
//
137
//		if (xml.contains("raster.bandG"))
137 138
//			bandG = xml.getIntProperty("raster.bandG");
138
//		
139
//		if (xml.contains("raster.bandB")) 
139
//
140
//		if (xml.contains("raster.bandB"))
140 141
//			bandB = xml.getIntProperty("raster.bandB");
141
//		
142
//	
142
//
143
//
143 144
//		int cont = 0;
144 145
//		while(true && cont < 50) {
145 146
//			if (xml.contains("raster.file" + cont)) {
146 147
//				files.add(xml.getStringProperty("raster.file" + cont));
147 148
//				cont++;
148
//			}else 
149
//			}else
149 150
//				break;
150 151
//		}
151
	}	
152
	
153
	
152
	}
153

  
154

  
154 155
	@SuppressWarnings("unchecked")
155 156
	public void loadFromState(PersistentState state)
156 157
			throws PersistenceException {
......
160 161
		this.bandB = state.getInt("bandB");
161 162
		this.alphaBandNumber = state.getInt("alphaBandNumber");
162 163
		this.loadClass = state.getBoolean("loadClass");
163
		
164

  
164 165
		this.layer = (DefaultFLyrRaster)state.get("layer");
165
		
166

  
166 167
		this.ranges = new ArrayList(state.getList("ranges"));
167 168
		this.files = new ArrayList(state.getList("files"));
168 169
		this.filters = new ArrayList(state.getList("filters"));
......
185 186
		this.layer = layer;
186 187
		this.loadClass = loadClass;
187 188
	}
188
	
189

  
189 190
	public static void registerPersistence() {
190 191
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
191 192
		DynStruct definition = manager.addDefinition(StatusLayerRaster.class,
......
197 198
		definition.addDynFieldInt("bandB").setMandatory(true);
198 199
		definition.addDynFieldInt("alphaBandNumber");
199 200
		definition.addDynFieldBoolean("loadClass");
200
		
201

  
201 202
		definition.addDynFieldObject("layer")
202 203
			.setClassOfValue(DefaultFLyrRaster.class);
203
		
204

  
204 205
		definition.addDynFieldList("ranges")
205 206
			.setClassOfItems(TransparencyRange.class);
206
		
207

  
207 208
		definition.addDynFieldList("files")
208 209
			.setClassOfItems(String.class);
209 210

  
210 211
		definition.addDynFieldList("filters")
211 212
			.setClassOfItems(String.class);
212 213
	}
213
	
214

  
214 215
	public List<String> getFilters() {
215 216
		return this.filters;
216 217
	}
217
	
218

  
218 219
	public void applyStatus(DefaultFLyrRaster layer) throws NotSupportedExtensionException, RasterDriverException, FilterTypeException, FileNotFoundInListException, OperationNotSupportedException, FilterManagerException, InvalidSourceException {
219
										
220
		//Eliminamos el fichero inicial y cargamos las bandas si hay para que se carguen 
220

  
221
		//Eliminamos el fichero inicial y cargamos las bandas si hay para que se carguen
221 222
		//en el orden correcto
222 223
		if(layer instanceof DefaultFLyrRaster) {
223 224
			if(files != null && files.size() != 0){
224 225
				//((FLyrRasterSE)layer).delFile((String)files.get(0));
225
				for (int i = 1; i < files.size(); i++) 
226
					((DefaultFLyrRaster)layer).addFile((String)files.get(i));
226
				for (int i = 1; i < files.size(); i++)
227
					((DefaultFLyrRaster)layer).addFile(files.get(i));
227 228
			}
228 229
		}
229
		
230

  
230 231
		//Asigna las bandas
231 232
		String[] valuesCI = new String[layer.getDataStore().getBandCount()];
232 233
		valuesCI[bandR] = ColorInterpretation.RED_BAND;
......
235 236
		ColorInterpretation ci = RasterLocator.getManager().getDataStructFactory().createColorInterpretation(valuesCI);
236 237
		if(layer.getRender() != null)
237 238
			layer.getRender().setRenderColorInterpretation(ci);
238
				
239

  
239 240
		//Asigna la transparencia
240
		Transparency transp = layer.getRender().getRenderingTransparency(); 
241
		if(transp != null && transparency != 255) { 
241
		Transparency transp = layer.getRender().getRenderingTransparency();
242
		if(transp != null && transparency != 255) {
242 243
			transp.setOpacity(transparency);
243 244
			transp.activeTransparency();
244 245
		}
245
		
246

  
246 247
		//Rangos de transparencia
247 248
		if(transp != null && ranges != null) {
248 249
			transp.setTransparencyRangeList(ranges);
249 250
			transp.activeTransparency();
250 251
		}
251
		
252

  
252 253
		//Banda de transparencia
253 254
		if(transp != null && alphaBandNumber != -1) {
254 255
			transp.setTransparencyBand(alphaBandNumber);
255 256
			transp.activeTransparency();
256 257
		}
257
		
258

  
258 259
		//Filtros
259 260
		/*if (layer.getRender().getFilterList() != null) {
260 261
			layer.getRender().getFilterList().createFilterListFromStrings((ArrayList<String>)filters);
261 262
			enhancedCompV10((ArrayList<String>)filters, layer);
262 263
			//sortFilters(layer.getRenderFilterList());
263 264
		}*/
264
		
265

  
265 266
		//Refrescamos todas las vistas
266 267
		layer.getMapContext().invalidate();
267 268
		/*IWindow[] w = PluginServices.getMDIManager().getAllWindows();
268 269
		for (int i = 0; i < w.length; i++) {
269
			if(w[i] != null && w[i] instanceof AbstractViewPanel) 
270
				((AbstractViewPanel)w[i]).getMapControl().getMapContext().invalidate();	
270
			if(w[i] != null && w[i] instanceof AbstractViewPanel)
271
				((AbstractViewPanel)w[i]).getMapControl().getMapContext().invalidate();
271 272
		}*/
272 273
	}
273
	
274

  
274 275
	/**
275 276
	 * M?todo para mantener la compatibilidad con la v10 del realce. El realce de la v10 no
276 277
	 * aporta suficiente informaci?n por lo que se a?ade un filtro de realce generico v1.9
......
278 279
	 * @param layer
279 280
	 * @param filterListManager
280 281
	 * @throws FilterTypeException
281
	 * @throws FilterManagerException 
282
	 * @throws FilterManagerException
282 283
	 */
283 284
	public static void enhancedCompV10(ArrayList<String> filterArguments, DefaultFLyrRaster layer) throws FilterTypeException, FilterManagerException {
284 285
		RasterFilterList filterList = layer.getRender().getFilterList();
285 286
		filterList.remove("enhanced_stretch");
286 287
		filterList.remove("tailTrim");
287
		
288

  
288 289
		/*boolean removed = false;
289 290
		RasterFilterList list = layer.getRender().getFilterList();
290 291
		for (int i = 0; i < list.lenght(); i++) {
291
			RasterFilter f = list.get(i); 
292
			if(f instanceof TailTrimFilter || f instanceof LinearEnhancementFilter) { 
292
			RasterFilter f = list.get(i);
293
			if(f instanceof TailTrimFilter || f instanceof LinearEnhancementFilter) {
293 294
				list.remove(f.getName());
294 295
				removed = true;
295 296
			}
296 297
		}
297 298
		if(removed)
298 299
			list.controlTypes();*/
299
		
300

  
300 301
		//Para compatibilidad de realce con proyectos antiguos
301
		for (int i = 0; i < filterArguments.size(); i++) { 
302
		for (int i = 0; i < filterArguments.size(); i++) {
302 303
			if(((String)filterArguments.get(i)).startsWith("filter.enhanced.active=true")) {
303 304
				RasterFilterListManager enhancementManager = filterList.getManagerByID("EnhancementStretch");
304 305
				Params params = filterList.createEmptyFilterParams();
......
310 311
			}
311 312
		}
312 313
	}
313
	
314

  
314 315
	public int[] getRenderBands() {
315 316
		return new int[]{bandR, bandG, bandB};
316 317
	}
317
	
318

  
318 319
	public RasterFilterList getFilterList() throws FilterTypeException {
319 320
		/*RasterManager rManager = RasterLocator.getManager();
320 321
		try {
......
324 325
			else {
325 326
				filterList = rManager.createEmptyFilterList(Buffer.TYPE_BYTE);
326 327
			}
327
			
328

  
328 329
			return filterList;
329 330
		} catch (NullPointerException e) {
330 331
			return null;
331 332
		}*/
332 333
		return null;
333 334
	}
334
	
335

  
335 336
	public ColorTable getColorTable() throws FilterTypeException {
336 337
		return layer.getRender().getColorTable();
337 338
	}
338
	
339

  
339 340
	public List<String> getFilterArguments() {
340 341
		return filters;
341 342
	}
342
	
343

  
343 344
	String nameClass = null;
344 345
	/**
345 346
	 * Asigna el nombre de la clase que se ha leido desde el proyecto
346 347
	 * @param nameClass
347 348
	 */
348 349
	public void setNameClass(String nameClass) {
349
		this.nameClass = nameClass;		
350
		this.nameClass = nameClass;
350 351
	}
351 352
}

Also available in: Unified diff