gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / DefaultRasterFilterList.java @ 1427
History | View | Annotate | Download (22.7 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.impl.grid.filter; |
23 |
|
24 |
import java.lang.reflect.Constructor; |
25 |
import java.lang.reflect.InvocationTargetException; |
26 |
import java.util.ArrayList; |
27 |
import java.util.Iterator; |
28 |
import java.util.List; |
29 |
import java.util.Stack; |
30 |
import java.util.TreeMap; |
31 |
|
32 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
33 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
34 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
35 |
import org.gvsig.fmap.dal.coverage.exception.FilterManagerException; |
36 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
37 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
38 |
import org.gvsig.fmap.dal.coverage.grid.FilterListChangeEvent; |
39 |
import org.gvsig.fmap.dal.coverage.grid.FilterListChangeListener; |
40 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
41 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
42 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager; |
43 |
import org.gvsig.fmap.dal.coverage.grid.filter.BaseRasterFilter; |
44 |
import org.gvsig.raster.impl.store.ParamsImpl; |
45 |
import org.gvsig.tools.ToolsLocator; |
46 |
import org.gvsig.tools.dynobject.DynStruct; |
47 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
48 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
49 |
import org.gvsig.tools.persistence.PersistenceManager; |
50 |
import org.gvsig.tools.persistence.PersistentState; |
51 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
52 |
/**
|
53 |
* Esta clase representa la lista de filtros que debe ser manejada desde el
|
54 |
* RasterFilterListManager.
|
55 |
*
|
56 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
57 |
*/
|
58 |
public class DefaultRasterFilterList implements RasterFilterList { |
59 |
public static final String PERSISTENT_NAME = "RasterFilterList_Persistent"; |
60 |
public static final String PERSISTENT_DESCRIPTION = "RasterFilterList Persistent"; |
61 |
private Buffer rasterBuf = null; |
62 |
private Buffer alphaBand = null; |
63 |
private int typeFilter = -1; |
64 |
private TreeMap<String, Object> |
65 |
environment = new TreeMap<String, Object>(); |
66 |
|
67 |
// Pila de objetos Filter (Contiene un RasterFilter)
|
68 |
private List<RasterFilter> |
69 |
list = new ArrayList<RasterFilter>(); |
70 |
private Stack<List<RasterFilter>> |
71 |
status = new Stack<List<RasterFilter>>(); |
72 |
/**
|
73 |
* Array de listeners que ser?n informados cuando cambia la lista de filtros
|
74 |
*/
|
75 |
private List<FilterListChangeListener> |
76 |
filterListListener = new ArrayList<FilterListChangeListener>(); |
77 |
private RasterFilterListManagerImpl
|
78 |
manager = null;
|
79 |
|
80 |
/**
|
81 |
* Asigna un listener a la lista que ser? informado cuando cambie un
|
82 |
* filtro o posici?n en la lista.
|
83 |
* @param listener FilterListListener
|
84 |
*/
|
85 |
public void addFilterListListener(FilterListChangeListener listener) { |
86 |
filterListListener.add(listener); |
87 |
} |
88 |
|
89 |
/**
|
90 |
* M?todo llamado cuando hay un cambio en una propiedad de visualizaci?n
|
91 |
*/
|
92 |
private void callFilterListChanged(Object obj) { |
93 |
for (int i = 0; i < filterListListener.size(); i++) { |
94 |
FilterListChangeEvent ev = new FilterListChangeEvent(obj);
|
95 |
((FilterListChangeListener)filterListListener.get(i)).filterListChanged(ev); |
96 |
} |
97 |
} |
98 |
|
99 |
/**
|
100 |
* A?ade un par?metro a la lista de filtros. Estos par?metros luego pueden ser
|
101 |
* utilizados por los managers que se registren
|
102 |
* @param key Nombre del par?metro que coincide con el nombre de la clase.
|
103 |
* @param value Objeto
|
104 |
*/
|
105 |
public void addEnvParam(String key, Object value) { |
106 |
environment.put(key, value); |
107 |
} |
108 |
|
109 |
/**
|
110 |
* Obtiene un par?metro de la lista de filtros.
|
111 |
* @param key Identificador del par?metro. Coincide con el nombre de la clase del par?metro.
|
112 |
*/
|
113 |
public Object getEnvParam(String key) { |
114 |
return environment.get(key);
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* Controla que los tipos de entrada y salida de los filtros sean los
|
119 |
* correctos
|
120 |
* @throws FilterTypeException
|
121 |
*/
|
122 |
public void controlTypes() throws FilterTypeException { |
123 |
RasterFilterListManagerImpl stackManager = new RasterFilterListManagerImpl(this); |
124 |
stackManager.controlTypes(); |
125 |
} |
126 |
|
127 |
/**
|
128 |
* A?ade un filtro al final de la lista
|
129 |
* @param filter filtro a?adido
|
130 |
* @throws FilterTypeException
|
131 |
*/
|
132 |
public void add(RasterFilter filter) throws FilterTypeException { |
133 |
if (isActive(filter.getName()))
|
134 |
replace(filter, filter.getName()); |
135 |
else {
|
136 |
list.add(filter); |
137 |
controlTypes(); |
138 |
} |
139 |
filter.setEnv(environment); |
140 |
callFilterListChanged(this);
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* Sustituye un filtro de una posici?n de la pila por otro
|
145 |
* @param filter
|
146 |
* @param i
|
147 |
* @throws FilterTypeException
|
148 |
*/
|
149 |
public void replace(RasterFilter filter, String name) throws FilterTypeException { |
150 |
boolean changed = false; |
151 |
filter.setEnv(environment); |
152 |
for (int i = list.size() - 1; i >= 0; i--) |
153 |
if (((BaseRasterFilter) list.get(i)).getName().equals(name)) {
|
154 |
list.remove(i); |
155 |
list.add(i, filter); |
156 |
changed = true;
|
157 |
} |
158 |
|
159 |
if (changed)
|
160 |
controlTypes(); |
161 |
callFilterListChanged(this);
|
162 |
} |
163 |
|
164 |
/**
|
165 |
* A?ade un filtro en la lista en la posici?n indicada.
|
166 |
* @param filter filtro a?adido
|
167 |
* @param pos posici?n
|
168 |
* @throws FilterTypeException
|
169 |
*/
|
170 |
public void add(RasterFilter filter, int pos) throws FilterTypeException { |
171 |
try {
|
172 |
list.add(pos, filter); |
173 |
controlTypes(); |
174 |
} catch (IndexOutOfBoundsException e) { |
175 |
add(filter); |
176 |
} |
177 |
filter.setEnv(environment); |
178 |
callFilterListChanged(this);
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* Elimina un filtro a partir de su nombre
|
183 |
* @param name Nombre del filtro a eliminar
|
184 |
* @throws FilterTypeException
|
185 |
*/
|
186 |
public void remove(String name) throws FilterTypeException { |
187 |
boolean changed = false; |
188 |
for (int i = list.size() - 1; i >= 0; i--) |
189 |
if (((BaseRasterFilter) list.get(i)).getName().equals(name)) {
|
190 |
list.remove(i); |
191 |
changed = true;
|
192 |
} |
193 |
if (changed)
|
194 |
controlTypes(); |
195 |
callFilterListChanged(this);
|
196 |
} |
197 |
|
198 |
/**
|
199 |
* Elimina un filtro por clase.
|
200 |
*
|
201 |
* @param baseFilterClass
|
202 |
* @throws FilterTypeException
|
203 |
*/
|
204 |
@SuppressWarnings("unchecked") |
205 |
public void remove(Class baseFilterClass) throws FilterTypeException { |
206 |
boolean changed = false; |
207 |
for (int i = 0; i < lenght(); i++) |
208 |
if (baseFilterClass.isInstance(list.get(i))) {
|
209 |
list.remove(i); |
210 |
i--; |
211 |
changed = true;
|
212 |
} |
213 |
if (changed)
|
214 |
controlTypes(); |
215 |
callFilterListChanged(this);
|
216 |
} |
217 |
|
218 |
/**
|
219 |
* Devuelve el tipo de dato de retorno al aplicar la pila de filtros
|
220 |
* @return
|
221 |
*/
|
222 |
public int getOutDataType() { |
223 |
if (list.size() > 0) |
224 |
return ((BaseRasterFilter) list.get(list.size() - 1)).getOutRasterDataType(); |
225 |
else
|
226 |
return rasterBuf.getDataType();
|
227 |
} |
228 |
|
229 |
/**
|
230 |
* Devuelve el raster resultado de la aplicacion de la pila de filtros
|
231 |
* @return
|
232 |
*/
|
233 |
public Buffer getResult() { |
234 |
return rasterBuf;
|
235 |
} |
236 |
|
237 |
/**
|
238 |
* Devuelve la banda alpha para los filtros que generan una
|
239 |
* @return
|
240 |
*/
|
241 |
public Buffer getAlphaBand() { |
242 |
return alphaBand;
|
243 |
} |
244 |
|
245 |
/**
|
246 |
* Obtiene la cantidad de filtros en la lista
|
247 |
* @return N?mero de filtros apilados
|
248 |
*/
|
249 |
public int lenght() { |
250 |
return list.size();
|
251 |
} |
252 |
|
253 |
/**
|
254 |
* Obtiene el filtro apilado de la posici?n i o null si el indice es incorrecto
|
255 |
* @param i Posici?n a acceder en la pila
|
256 |
* @return Filtro
|
257 |
*/
|
258 |
public RasterFilter get(int i) { |
259 |
if (i >= list.size() || i < 0) |
260 |
return null; |
261 |
return (BaseRasterFilter) list.get(i);
|
262 |
} |
263 |
|
264 |
/**
|
265 |
* Obtiene el filtro apilado de nombre name o null si no existe
|
266 |
* @param i Nombre del filtro buscado
|
267 |
* @return Filtro
|
268 |
*/
|
269 |
public RasterFilter get(String name) { |
270 |
for (int i = list.size() - 1; i >= 0; i--) |
271 |
if (((BaseRasterFilter) list.get(i)).getName().equals(name))
|
272 |
return (BaseRasterFilter) list.get(i);
|
273 |
return null; |
274 |
} |
275 |
|
276 |
/**
|
277 |
* Obtiene el filtro apilado que corresponde con el nombre
|
278 |
* @param name Nombre de filtro
|
279 |
* @return Filtro en caso de que exista un filtro apilado de ese tipo
|
280 |
* o null si no hay ninguno.
|
281 |
*/
|
282 |
public RasterFilter getByName(String name) { |
283 |
for (int i = 0; i < lenght(); i++) |
284 |
if (((BaseRasterFilter) list.get(i)).getName().equals(name))
|
285 |
return (BaseRasterFilter) list.get(i);
|
286 |
return null; |
287 |
} |
288 |
|
289 |
/**
|
290 |
* Obtiene el primer filtro de la lista que es instancia de la clase pasada por
|
291 |
* par?metro
|
292 |
* @param baseFilterClass Filtro base
|
293 |
* @return RasterFilter
|
294 |
*/
|
295 |
@SuppressWarnings("unchecked") |
296 |
public RasterFilter getFilterByBaseClass(Class baseFilterClass) { |
297 |
for (int i = 0; i < lenght(); i++) |
298 |
if (baseFilterClass.isInstance(list.get(i)))
|
299 |
return (BaseRasterFilter) list.get(i);
|
300 |
return null; |
301 |
} |
302 |
|
303 |
/**
|
304 |
* Obtiene el tipo del filtro de la pila de la posici?n i
|
305 |
* @param i Posici?n a acceder en la pila
|
306 |
* @return tipo de filtro
|
307 |
*/
|
308 |
public String getName(int i) { |
309 |
return ((BaseRasterFilter) list.get(i)).getName();
|
310 |
} |
311 |
|
312 |
/**
|
313 |
* Elimina todos los filtros de la pila
|
314 |
*/
|
315 |
public void clear() { |
316 |
list.clear(); |
317 |
callFilterListChanged(this);
|
318 |
} |
319 |
|
320 |
/**
|
321 |
* Sustituye un filtro de una posici?n de la pila por otro
|
322 |
* @param filter
|
323 |
* @param i
|
324 |
*/
|
325 |
public void replace(RasterFilter filter, int i) { |
326 |
filter.setEnv(environment); |
327 |
list.remove(i); |
328 |
list.add(i, filter); |
329 |
callFilterListChanged(this);
|
330 |
} |
331 |
|
332 |
/**
|
333 |
* Move un filtro determinado a la posici?n especificada.
|
334 |
* @param filter Filtro a mover
|
335 |
* @param position Posici?n a asignar
|
336 |
* @return Devuelve true si el filtro existia y lo ha movido y false si no lo ha hecho.
|
337 |
*/
|
338 |
@SuppressWarnings("unchecked") |
339 |
public boolean move(Class filter, int position) { |
340 |
BaseRasterFilter f = null;
|
341 |
for (int i = 0; i < list.size(); i++) |
342 |
if(filter.isInstance(list.get(i))) {
|
343 |
f = (BaseRasterFilter) list.get(i); |
344 |
list.remove(i); |
345 |
break;
|
346 |
} |
347 |
if(f != null) { |
348 |
list.add(position, f); |
349 |
return true; |
350 |
} |
351 |
return false; |
352 |
} |
353 |
|
354 |
/**
|
355 |
* Asigna el raster de entrada inicial
|
356 |
* @param raster
|
357 |
*/
|
358 |
public void setInitRasterBuf(Buffer raster) { |
359 |
rasterBuf = raster; |
360 |
if(rasterBuf != null) |
361 |
typeFilter = rasterBuf.getDataType(); |
362 |
} |
363 |
|
364 |
/**
|
365 |
* Devuelve el tipo de datos inicial de la lista
|
366 |
* @return Tipo de dato del raster inicial
|
367 |
*/
|
368 |
public int getInitDataType() { |
369 |
return typeFilter;
|
370 |
} |
371 |
|
372 |
/**
|
373 |
* Asigna el tipo de dato inicial
|
374 |
* @param dt
|
375 |
*/
|
376 |
public void setInitDataType(int dt) { |
377 |
this.typeFilter = dt;
|
378 |
} |
379 |
|
380 |
/**
|
381 |
* M?todo que devuelve true si el tipo de filtro pasado por par?metro est? en la
|
382 |
* pila y false si no lo est?.
|
383 |
* @param type Tipo de par?metro a comprobar
|
384 |
* @return true si est? en la pila y false si no lo est?
|
385 |
*/
|
386 |
public boolean isActive(String name) { |
387 |
for (int i = list.size() - 1; i >= 0; i--) |
388 |
if (((RasterFilter) list.get(i)).getName().equals(name))
|
389 |
return true; |
390 |
return false; |
391 |
} |
392 |
|
393 |
/**
|
394 |
* M?todo que devuelve true si el tipo de filtro pasado por par?metro est? en
|
395 |
* la pila y false si no lo est?.
|
396 |
*
|
397 |
* @param filter Tipo de filtro a comprobar
|
398 |
* @return true si est? en la pila y false si no lo est?
|
399 |
*/
|
400 |
public boolean isActive(RasterFilter filter) { |
401 |
for (int i = list.size() - 1; i >= 0; i--) |
402 |
if (((RasterFilter) list.get(i)).equals(filter))
|
403 |
return true; |
404 |
return false; |
405 |
} |
406 |
|
407 |
/**
|
408 |
* Devuelve la posici?n en la lista de una clase de filtro concreta
|
409 |
*
|
410 |
* @param c Clase a buscar en la lista
|
411 |
* @return posici?n en la lista
|
412 |
*/
|
413 |
@SuppressWarnings("unchecked") |
414 |
public int getPosition(Class c) { |
415 |
for (int i = 0; i < list.size(); i++) |
416 |
if (c.isInstance(list.get(i)))
|
417 |
return i;
|
418 |
return -1; |
419 |
} |
420 |
|
421 |
/**
|
422 |
* Aplica los filtros de la pila sobre el buffer correspondiente
|
423 |
* @param dataType
|
424 |
* @throws ProcessInterruptedException
|
425 |
*/
|
426 |
private void executeFilterByDataType(int dataType) throws ProcessInterruptedException { |
427 |
environment.put("FirstUseTransparency", Boolean.TRUE); |
428 |
environment.put("HasNoDataFilter", Boolean.valueOf(isActive("nodata"))); |
429 |
|
430 |
environment.put("FirstRaster", rasterBuf);
|
431 |
alphaBand = null;
|
432 |
for (int i = 0; i < list.size(); i++) { |
433 |
BaseRasterFilter filter = (BaseRasterFilter) list.get(i); |
434 |
|
435 |
// TODO: Arquitectura. Quitar el ControlTypes y en este momento
|
436 |
// cerciorarse de si el tipo del filtro es totalmente el correcto o hay
|
437 |
// que recrearlo. Ejemplo:
|
438 |
// Si el filtro que tenemos antes de preprocesar es de tipo Byte y la
|
439 |
// entrada de datos es de tipo float, reconstruir solo este filtro para
|
440 |
// que sea de tipo float
|
441 |
|
442 |
filter.addParam("raster", rasterBuf);
|
443 |
filter.execute(); |
444 |
|
445 |
if (filter.getResult("raster") != null) |
446 |
this.rasterBuf = (Buffer) filter.getResult("raster"); |
447 |
|
448 |
//Si el filtro genera una banda alpha se mezcla con la que han generado otros
|
449 |
if (filter.getResult("alphaBand") != null) |
450 |
if(alphaBand != null) |
451 |
alphaBand = RasterLocator.getManager().getColorConversion().mergeTransparencyBuffers(alphaBand, (Buffer)filter.getResult("alphaBand")); |
452 |
else
|
453 |
alphaBand = (Buffer)filter.getResult("alphaBand"); |
454 |
} |
455 |
environment.remove("FirstRaster");
|
456 |
} |
457 |
|
458 |
/**
|
459 |
* Aplica los filtros sobre un RasterBuf
|
460 |
* @return Buffer de salida
|
461 |
* @throws ProcessInterruptedException
|
462 |
*/
|
463 |
public Buffer execute() throws ProcessInterruptedException { |
464 |
if (rasterBuf == null) |
465 |
return null; |
466 |
executeFilterByDataType(rasterBuf.getDataType()); |
467 |
return rasterBuf;
|
468 |
} |
469 |
|
470 |
/**
|
471 |
* Muestra el contenido de la pila de filtros para depuraci?n
|
472 |
*/
|
473 |
public void show() { |
474 |
System.out.println("--------------------------------------------"); |
475 |
|
476 |
for (int i = 0; i < list.size() ; i++) |
477 |
System.out.println("FILTRO:" + i + " NAME:" + ((BaseRasterFilter) list.get(i)).getName() + " FIL:" + ((BaseRasterFilter) list.get(i)).toString()); |
478 |
} |
479 |
|
480 |
public void resetPercent() { |
481 |
for (int i = 0; i < list.size(); i++) |
482 |
((BaseRasterFilter) list.get(i)).resetPercent(); |
483 |
} |
484 |
|
485 |
public int getPercent() { |
486 |
int percent = 0; |
487 |
if (list.size() == 0) |
488 |
return 0; |
489 |
for (int i = 0; i < list.size(); i++) |
490 |
percent += ((BaseRasterFilter) list.get(i)).getPercent(); |
491 |
|
492 |
percent = percent / list.size(); |
493 |
return percent;
|
494 |
} |
495 |
|
496 |
/**
|
497 |
* Guarda el estado de la lista de filtros en una pila, que se podr?
|
498 |
* ir recuperando con popStatus()
|
499 |
*/
|
500 |
public void pushStatus() { |
501 |
status.push(getStatusCloned()); |
502 |
} |
503 |
|
504 |
/**
|
505 |
* Obtiene el estado actual de los filtros, el ArrayList devuelto es una
|
506 |
* clonaci?n del original, asi no compartiran datos.
|
507 |
* @return
|
508 |
*/
|
509 |
public List<RasterFilter> getStatusCloned() { |
510 |
List<RasterFilter> newArray = new ArrayList<RasterFilter>(); |
511 |
for (int i = 0; i < list.size(); i++) |
512 |
try {
|
513 |
newArray.add((RasterFilter)(((BaseRasterFilter) list.get(i)).clone())); |
514 |
} catch (CloneNotSupportedException e) { |
515 |
System.out.println("No se ha podido clonar"); |
516 |
} |
517 |
return newArray;
|
518 |
} |
519 |
|
520 |
/**
|
521 |
* Define el estado actual de los filtros
|
522 |
* @param newArray
|
523 |
*/
|
524 |
public void setStatus(List<RasterFilter> newArray) { |
525 |
list.clear(); |
526 |
if(newArray == null) |
527 |
return;
|
528 |
for (int i = 0; i < newArray.size(); i++) |
529 |
list.add(newArray.get(i)); |
530 |
callFilterListChanged(this);
|
531 |
} |
532 |
|
533 |
/**
|
534 |
* Recupera un estado guardado con antelaci?n mediante el m?todo pushStatus()
|
535 |
*/
|
536 |
public void popStatus() { |
537 |
if (status.size() <= 0) |
538 |
return;
|
539 |
|
540 |
setStatus((List<RasterFilter>) status.pop());
|
541 |
} |
542 |
|
543 |
/**
|
544 |
* Obtiene el TreeMap con los par?metros
|
545 |
* @return TreeMap
|
546 |
*/
|
547 |
public TreeMap<String, Object> getEnv() { |
548 |
return environment;
|
549 |
} |
550 |
|
551 |
/**
|
552 |
* Asigna el TreeMap con los par?metros del entorno
|
553 |
* @param env
|
554 |
*/
|
555 |
public void setEnv(TreeMap<String, Object> env) { |
556 |
this.environment = env;
|
557 |
} |
558 |
|
559 |
/*
|
560 |
* (non-Javadoc)
|
561 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterList#createFilterListFromStrings(java.util.ArrayList)
|
562 |
*/
|
563 |
public void createFilterListFromStrings(List<String> f) throws FilterTypeException { |
564 |
RasterFilterListManagerImpl.createFilterListFromStrings(this, f);
|
565 |
} |
566 |
|
567 |
/*
|
568 |
* (non-Javadoc)
|
569 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterList#getManagerByID(java.lang.String)
|
570 |
*/
|
571 |
public RasterFilterListManager getManagerByID(String id) throws FilterManagerException { |
572 |
return new RasterFilterListManagerImpl(this).getManagerByID(id); |
573 |
} |
574 |
|
575 |
/*
|
576 |
* (non-Javadoc)
|
577 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterList#getManagerByFilterClass(java.lang.Class)
|
578 |
*/
|
579 |
@SuppressWarnings("unchecked") |
580 |
public RasterFilterListManager getManagerByFilterClass(Class c) { |
581 |
if(manager == null) |
582 |
manager = new RasterFilterListManagerImpl(this); |
583 |
return manager.getManagerByFilterClass(c);
|
584 |
} |
585 |
|
586 |
/*
|
587 |
* (non-Javadoc)
|
588 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterList#getManagerByClass(java.lang.Class)
|
589 |
*/
|
590 |
@SuppressWarnings("unchecked") |
591 |
public RasterFilterListManager getManagerByClass(Class clase) { |
592 |
Object obj = null; |
593 |
Class[] args = { RasterFilterList.class }; |
594 |
try {
|
595 |
Constructor hazNuevo = clase.getConstructor(args);
|
596 |
Object[] args2 = { this }; |
597 |
obj = hazNuevo.newInstance(args2); |
598 |
} catch (SecurityException e) { |
599 |
e.printStackTrace(); |
600 |
} catch (NoSuchMethodException e) { |
601 |
e.printStackTrace(); |
602 |
} catch (IllegalArgumentException e) { |
603 |
e.printStackTrace(); |
604 |
} catch (InstantiationException e) { |
605 |
e.printStackTrace(); |
606 |
} catch (IllegalAccessException e) { |
607 |
e.printStackTrace(); |
608 |
} catch (InvocationTargetException e) { |
609 |
e.printStackTrace(); |
610 |
} |
611 |
return (RasterFilterListManager)obj;
|
612 |
} |
613 |
|
614 |
public Class<?> getFilterClassByID(String id) { |
615 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
616 |
ExtensionPoint point = extensionPoints.get("RasterFilter");
|
617 |
Iterator<?> it = point.iterator();
|
618 |
while(it.hasNext()) {
|
619 |
ExtensionPoint.Extension entry = (ExtensionPoint.Extension) it.next(); |
620 |
if (entry != null) { |
621 |
Class<?> managerClass = entry.getExtension();
|
622 |
RasterFilterListManager manager = getManagerByClass(managerClass); |
623 |
if(manager != null) { |
624 |
Class<?> c = manager.getFilterClassByID(id);
|
625 |
if(c != null) |
626 |
return c;
|
627 |
} |
628 |
} |
629 |
} |
630 |
return null; |
631 |
} |
632 |
|
633 |
/*
|
634 |
* (non-Javadoc)
|
635 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterList#getEmptyFilterParams()
|
636 |
*/
|
637 |
public Params createEmptyFilterParams() {
|
638 |
return new ParamsImpl(); |
639 |
} |
640 |
|
641 |
public List<Class<?>> getRegisteredFilterList() { |
642 |
if(manager == null) |
643 |
manager = new RasterFilterListManagerImpl(this); |
644 |
return manager.getRasterFilterList();
|
645 |
} |
646 |
|
647 |
public List<Class<?>> getRegisteredFilterListByDataType(int dataType) { |
648 |
if(manager == null) |
649 |
manager = new RasterFilterListManagerImpl(this); |
650 |
return manager.getRasterFilterListByDataType(dataType);
|
651 |
} |
652 |
|
653 |
public RasterFilter createEmptyFilter(String strPackage) throws FilterTypeException { |
654 |
Class<?> filterClass = null; |
655 |
try {
|
656 |
filterClass = Class.forName(strPackage.trim());
|
657 |
} catch (ClassNotFoundException e) { |
658 |
throw new FilterTypeException("No puedo instanciar " + strPackage.trim()); |
659 |
} |
660 |
|
661 |
Constructor<?> con = null; |
662 |
try {
|
663 |
con = filterClass.getConstructor(); |
664 |
} catch (SecurityException e) { |
665 |
throw new FilterTypeException(""); |
666 |
} catch (NoSuchMethodException e) { |
667 |
throw new FilterTypeException(""); |
668 |
} |
669 |
|
670 |
BaseRasterFilter newFilter = null;
|
671 |
try {
|
672 |
newFilter = (BaseRasterFilter) con.newInstance(); |
673 |
} catch (IllegalArgumentException e) { |
674 |
throw new FilterTypeException(""); |
675 |
} catch (InstantiationException e) { |
676 |
throw new FilterTypeException(""); |
677 |
} catch (IllegalAccessException e) { |
678 |
throw new FilterTypeException(""); |
679 |
} catch (InvocationTargetException e) { |
680 |
throw new FilterTypeException(""); |
681 |
} |
682 |
return newFilter;
|
683 |
} |
684 |
|
685 |
/*
|
686 |
* (non-Javadoc)
|
687 |
* @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState)
|
688 |
*/
|
689 |
public void loadFromState(PersistentState state) |
690 |
throws PersistenceException {
|
691 |
this.typeFilter = state.getInt("typeFilter"); |
692 |
|
693 |
/*List<PersistencyFilterParam> listFilterUsed = state.getList("paramlist");
|
694 |
|
695 |
ArrayList<Exception> exc = new ArrayList<Exception>();
|
696 |
for (int i = 0; i < listFilterUsed.size(); i++) {
|
697 |
try {
|
698 |
PersistencyFilterParam pfp = (PersistencyFilterParam) listFilterUsed.get(i);
|
699 |
if(pfp != null && pfp.getFilterClass() != null && pfp.getFilterParam() != null) {
|
700 |
RasterFilterListManager filterManager = getManagerByFilterClass(pfp.getFilterClass());
|
701 |
filterManager.setFilterList(this);
|
702 |
if(filterManager != null)
|
703 |
filterManager.addFilter(pfp.getFilterClass(), pfp.getFilterParam());
|
704 |
}
|
705 |
} catch (FilterTypeException e) {
|
706 |
exc.add(e);
|
707 |
}
|
708 |
}*/
|
709 |
|
710 |
} |
711 |
|
712 |
/*
|
713 |
* (non-Javadoc)
|
714 |
* @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState)
|
715 |
*/
|
716 |
public void saveToState(PersistentState state) throws PersistenceException { |
717 |
state.set("typeFilter", typeFilter);
|
718 |
|
719 |
/*ArrayList<PersistencyFilterParam> filters = new ArrayList<PersistencyFilterParam>();
|
720 |
for (int i = 0; i < list.size(); i++) {
|
721 |
RasterFilter f = list.get(i);
|
722 |
Params uipar = f.getUIParams(f.getName());
|
723 |
PersistencyFilterParam param = new PersistencyFilterParam();
|
724 |
param.setFilterParam(uipar);
|
725 |
param.setFilterClass(f.getClass());
|
726 |
param.setFilterName(f.getName());
|
727 |
filters.add(param);
|
728 |
}
|
729 |
state.set("paramlist", filters);*/
|
730 |
} |
731 |
|
732 |
public static void registerPersistence() { |
733 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
734 |
DynStruct definition = manager.getDefinition(PERSISTENT_NAME); |
735 |
if( definition == null ) { |
736 |
definition = manager.addDefinition( |
737 |
DefaultRasterFilterList.class, |
738 |
PERSISTENT_NAME, |
739 |
PERSISTENT_DESCRIPTION, |
740 |
null,
|
741 |
null
|
742 |
); |
743 |
|
744 |
definition.addDynFieldInt("typeFilter").setMandatory(false); |
745 |
//definition.addDynFieldList("paramlist").setClassOfItems(PersistencyFilterParam.class).setMandatory(false);
|
746 |
} |
747 |
} |
748 |
|
749 |
/**
|
750 |
* Releases buffer resources
|
751 |
*/
|
752 |
public void dispose() { |
753 |
if (rasterBuf != null) |
754 |
rasterBuf.dispose(); |
755 |
if (alphaBand != null) |
756 |
alphaBand.dispose(); |
757 |
/*if(list != null) {
|
758 |
for (int i = 0; i < lenght(); i++)
|
759 |
((BaseRasterFilter) list.get(i)).dispose();
|
760 |
}*/
|
761 |
try {
|
762 |
finalize(); |
763 |
} catch (Throwable e) { |
764 |
} |
765 |
} |
766 |
|
767 |
/*
|
768 |
* (non-Javadoc)
|
769 |
* @see java.lang.Object#finalize()
|
770 |
*/
|
771 |
protected void finalize() throws Throwable { |
772 |
rasterBuf = null;
|
773 |
alphaBand = null;
|
774 |
if(filterListListener != null) { |
775 |
filterListListener.clear(); |
776 |
filterListListener = null;
|
777 |
} |
778 |
if(status != null) { |
779 |
status.clear(); |
780 |
status = null;
|
781 |
} |
782 |
if(list != null) { |
783 |
list.clear(); |
784 |
list = null;
|
785 |
} |
786 |
super.finalize();
|
787 |
} |
788 |
} |