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