gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / DefaultRasterFilterList.java @ 2308
History | View | Annotate | Download (22 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.dataset.Buffer; |
33 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
34 |
import org.gvsig.fmap.dal.coverage.exception.FilterAddException; |
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.fmap.dal.coverage.store.props.Transparency; |
45 |
import org.gvsig.raster.impl.store.ParamsImpl; |
46 |
import org.gvsig.tools.ToolsLocator; |
47 |
import org.gvsig.tools.dynobject.DynStruct; |
48 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
49 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
50 |
import org.gvsig.tools.persistence.PersistenceManager; |
51 |
import org.gvsig.tools.persistence.PersistentState; |
52 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
53 |
/**
|
54 |
* Esta clase representa la lista de filtros que debe ser manejada desde el
|
55 |
* RasterFilterListManager.
|
56 |
*
|
57 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
58 |
*/
|
59 |
public class DefaultRasterFilterList implements RasterFilterList { |
60 |
public static final String PERSISTENT_NAME = "RasterFilterList_Persistent"; |
61 |
public static final String PERSISTENT_DESCRIPTION = "RasterFilterList Persistent"; |
62 |
private Buffer initialRasterBuffer = null; |
63 |
private Buffer outputRasterBuffer = null; |
64 |
private int typeFilter = -1; |
65 |
private TreeMap<String, Object> |
66 |
environment = new TreeMap<String, Object>(); |
67 |
|
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 |
public void remove(Class<?> baseFilterClass) throws FilterTypeException { |
207 |
boolean changed = false; |
208 |
for (int i = 0; i < lenght(); i++) |
209 |
if (baseFilterClass.isInstance(list.get(i))) {
|
210 |
list.remove(i); |
211 |
i--; |
212 |
changed = true;
|
213 |
} |
214 |
if (changed)
|
215 |
controlTypes(); |
216 |
callFilterListChanged(this);
|
217 |
} |
218 |
|
219 |
/**
|
220 |
* Devuelve el tipo de dato de retorno al aplicar la pila de filtros
|
221 |
* @return
|
222 |
*/
|
223 |
public int getOutDataType() { |
224 |
if (list.size() > 0) |
225 |
return ((BaseRasterFilter) list.get(list.size() - 1)).getOutRasterDataType(); |
226 |
else
|
227 |
if(outputRasterBuffer != null) |
228 |
return outputRasterBuffer.getDataType();
|
229 |
else
|
230 |
return initialRasterBuffer.getDataType();
|
231 |
} |
232 |
|
233 |
/**
|
234 |
* Devuelve el raster resultado de la aplicacion de la pila de filtros
|
235 |
* @return
|
236 |
*/
|
237 |
public Buffer getResult() { |
238 |
return outputRasterBuffer;
|
239 |
} |
240 |
|
241 |
/**
|
242 |
* Obtiene la cantidad de filtros en la lista
|
243 |
* @return N?mero de filtros apilados
|
244 |
*/
|
245 |
public int lenght() { |
246 |
return list.size();
|
247 |
} |
248 |
|
249 |
/**
|
250 |
* Obtiene el filtro apilado de la posici?n i o null si el indice es incorrecto
|
251 |
* @param i Posici?n a acceder en la pila
|
252 |
* @return Filtro
|
253 |
*/
|
254 |
public RasterFilter get(int i) { |
255 |
if (i >= list.size() || i < 0) |
256 |
return null; |
257 |
return (BaseRasterFilter) list.get(i);
|
258 |
} |
259 |
|
260 |
/**
|
261 |
* Obtiene el filtro apilado de nombre name o null si no existe
|
262 |
* @param i Nombre del filtro buscado
|
263 |
* @return Filtro
|
264 |
*/
|
265 |
public RasterFilter get(String name) { |
266 |
for (int i = list.size() - 1; i >= 0; i--) |
267 |
if (((BaseRasterFilter) list.get(i)).getName().equals(name))
|
268 |
return (BaseRasterFilter) list.get(i);
|
269 |
return null; |
270 |
} |
271 |
|
272 |
/**
|
273 |
* Obtiene el filtro apilado que corresponde con el nombre
|
274 |
* @param name Nombre de filtro
|
275 |
* @return Filtro en caso de que exista un filtro apilado de ese tipo
|
276 |
* o null si no hay ninguno.
|
277 |
*/
|
278 |
public RasterFilter getByName(String name) { |
279 |
for (int i = 0; i < lenght(); i++) |
280 |
if (((BaseRasterFilter) list.get(i)).getName().equals(name))
|
281 |
return (BaseRasterFilter) list.get(i);
|
282 |
return null; |
283 |
} |
284 |
|
285 |
/**
|
286 |
* Obtiene el primer filtro de la lista que es instancia de la clase pasada por
|
287 |
* par?metro
|
288 |
* @param baseFilterClass Filtro base
|
289 |
* @return RasterFilter
|
290 |
*/
|
291 |
public RasterFilter getFilterByBaseClass(Class<?> baseFilterClass) { |
292 |
for (int i = 0; i < lenght(); i++) |
293 |
if (baseFilterClass.isInstance(list.get(i)))
|
294 |
return (BaseRasterFilter) list.get(i);
|
295 |
return null; |
296 |
} |
297 |
|
298 |
/**
|
299 |
* Obtiene el tipo del filtro de la pila de la posici?n i
|
300 |
* @param i Posici?n a acceder en la pila
|
301 |
* @return tipo de filtro
|
302 |
*/
|
303 |
public String getName(int i) { |
304 |
return ((BaseRasterFilter) list.get(i)).getName();
|
305 |
} |
306 |
|
307 |
/**
|
308 |
* Removes all filter of this stack
|
309 |
*/
|
310 |
public void clear() { |
311 |
list.clear(); |
312 |
callFilterListChanged(this);
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* Replaces a filter in the i position by another
|
317 |
* @param filter
|
318 |
* @param i
|
319 |
*/
|
320 |
public void replace(RasterFilter filter, int i) { |
321 |
filter.setEnv(environment); |
322 |
list.remove(i); |
323 |
list.add(i, filter); |
324 |
callFilterListChanged(this);
|
325 |
} |
326 |
|
327 |
/**
|
328 |
* Moves a specific filter to anothe position
|
329 |
* @param filter
|
330 |
* Filter to move
|
331 |
* @param position
|
332 |
* New position
|
333 |
* @return If the filter existed returns true else it will return false
|
334 |
*/
|
335 |
public boolean move(Class<?> filter, int position) { |
336 |
BaseRasterFilter f = null;
|
337 |
for (int i = 0; i < list.size(); i++) |
338 |
if(filter.isInstance(list.get(i))) {
|
339 |
f = (BaseRasterFilter) list.get(i); |
340 |
list.remove(i); |
341 |
break;
|
342 |
} |
343 |
if(f != null) { |
344 |
list.add(position, f); |
345 |
return true; |
346 |
} |
347 |
return false; |
348 |
} |
349 |
|
350 |
/**
|
351 |
* Asigna el raster de entrada inicial
|
352 |
* @param raster
|
353 |
*/
|
354 |
public void setInitRasterBuf(Buffer raster) { |
355 |
initialRasterBuffer = raster; |
356 |
if(initialRasterBuffer != null) |
357 |
typeFilter = initialRasterBuffer.getDataType(); |
358 |
} |
359 |
|
360 |
/**
|
361 |
* Devuelve el tipo de datos inicial de la lista
|
362 |
* @return Tipo de dato del raster inicial
|
363 |
*/
|
364 |
public int getInitDataType() { |
365 |
return typeFilter;
|
366 |
} |
367 |
|
368 |
/**
|
369 |
* Asigna el tipo de dato inicial
|
370 |
* @param dt
|
371 |
*/
|
372 |
public void setInitDataType(int dt) { |
373 |
this.typeFilter = dt;
|
374 |
} |
375 |
|
376 |
/**
|
377 |
* M?todo que devuelve true si el tipo de filtro pasado por par?metro est? en la
|
378 |
* pila y false si no lo est?.
|
379 |
* @param type Tipo de par?metro a comprobar
|
380 |
* @return true si est? en la pila y false si no lo est?
|
381 |
*/
|
382 |
public boolean isActive(String name) { |
383 |
for (int i = list.size() - 1; i >= 0; i--) |
384 |
if (((RasterFilter) list.get(i)).getName().equals(name))
|
385 |
return true; |
386 |
return false; |
387 |
} |
388 |
|
389 |
/**
|
390 |
* M?todo que devuelve true si el tipo de filtro pasado por par?metro est? en
|
391 |
* la pila y false si no lo est?.
|
392 |
*
|
393 |
* @param filter Tipo de filtro a comprobar
|
394 |
* @return true si est? en la pila y false si no lo est?
|
395 |
*/
|
396 |
public boolean isActive(RasterFilter filter) { |
397 |
for (int i = list.size() - 1; i >= 0; i--) |
398 |
if (((RasterFilter) list.get(i)).equals(filter))
|
399 |
return true; |
400 |
return false; |
401 |
} |
402 |
|
403 |
/**
|
404 |
* Devuelve la posici?n en la lista de una clase de filtro concreta
|
405 |
*
|
406 |
* @param c Clase a buscar en la lista
|
407 |
* @return posici?n en la lista
|
408 |
*/
|
409 |
public int getPosition(Class<?> c) { |
410 |
for (int i = 0; i < list.size(); i++) |
411 |
if (c.isInstance(list.get(i)))
|
412 |
return i;
|
413 |
return -1; |
414 |
} |
415 |
|
416 |
/**
|
417 |
* Aplica los filtros de la pila sobre el buffer correspondiente
|
418 |
* @param dataType
|
419 |
* @throws ProcessInterruptedException
|
420 |
*/
|
421 |
private void executeFilterByDataType(int dataType) throws ProcessInterruptedException, FilterAddException { |
422 |
if(outputRasterBuffer != null && initialRasterBuffer != outputRasterBuffer) { |
423 |
outputRasterBuffer.dispose(); |
424 |
outputRasterBuffer = null;
|
425 |
} |
426 |
|
427 |
Buffer bufferToProcess = initialRasterBuffer;
|
428 |
for (int i = 0; i < list.size(); i++) { |
429 |
BaseRasterFilter filter = (BaseRasterFilter) list.get(i); |
430 |
|
431 |
// TODO: Arquitectura. Quitar el ControlTypes y en este momento
|
432 |
// cerciorarse de si el tipo del filtro es totalmente el correcto o hay
|
433 |
// que recrearlo. Ejemplo:
|
434 |
// Si el filtro que tenemos antes de preprocesar es de tipo Byte y la
|
435 |
// entrada de datos es de tipo float, reconstruir solo este filtro para
|
436 |
// que sea de tipo float
|
437 |
|
438 |
filter.addParam("raster", bufferToProcess);
|
439 |
filter.execute(); |
440 |
|
441 |
if (filter.getResult(RasterFilter.RESULT_BUFFER) != null) { |
442 |
//Si no es el ?ltimo filtro se asigna el buffer de la pr?xima iteraci?n y se libera el anterior
|
443 |
if(i < (list.size() - 1)) { |
444 |
if(bufferToProcess != null && initialRasterBuffer != bufferToProcess) |
445 |
bufferToProcess.dispose(); |
446 |
bufferToProcess = (Buffer) filter.getResult(RasterFilter.RESULT_BUFFER);
|
447 |
} else {
|
448 |
//Si es el ?ltimo se carga el de salida
|
449 |
outputRasterBuffer = (Buffer) filter.getResult(RasterFilter.RESULT_BUFFER);
|
450 |
} |
451 |
} |
452 |
|
453 |
if (i == list.size() - 1 && filter.getResult(RasterFilter.RESULT_TRANSPARENCY) != null) { |
454 |
addEnvParam("Transparency", filter.getResult(RasterFilter.RESULT_TRANSPARENCY));
|
455 |
} |
456 |
} |
457 |
} |
458 |
|
459 |
/**
|
460 |
* Aplica los filtros sobre un RasterBuf
|
461 |
* @return Buffer de salida
|
462 |
* @throws ProcessInterruptedException
|
463 |
* @throws FilterAddException
|
464 |
*/
|
465 |
public Buffer execute() throws ProcessInterruptedException, FilterAddException { |
466 |
if (initialRasterBuffer == null) |
467 |
return null; |
468 |
executeFilterByDataType(initialRasterBuffer.getDataType()); |
469 |
return initialRasterBuffer;
|
470 |
} |
471 |
|
472 |
/**
|
473 |
* Muestra el contenido de la pila de filtros para depuraci?n
|
474 |
*/
|
475 |
public void show() { |
476 |
System.out.println("--------------------------------------------"); |
477 |
|
478 |
for (int i = 0; i < list.size() ; i++) |
479 |
System.out.println("FILTRO:" + i + " NAME:" + ((BaseRasterFilter) list.get(i)).getName() + " FIL:" + ((BaseRasterFilter) list.get(i)).toString()); |
480 |
} |
481 |
|
482 |
public void resetPercent() { |
483 |
for (int i = 0; i < list.size(); i++) |
484 |
((BaseRasterFilter) list.get(i)).resetPercent(); |
485 |
} |
486 |
|
487 |
public int getPercent() { |
488 |
int percent = 0; |
489 |
if (list == null || list.size() == 0) |
490 |
return 0; |
491 |
for (int i = 0; i < list.size(); i++) |
492 |
percent += ((BaseRasterFilter) list.get(i)).getPercent(); |
493 |
|
494 |
percent = percent / list.size(); |
495 |
return percent;
|
496 |
} |
497 |
|
498 |
/**
|
499 |
* Guarda el estado de la lista de filtros en una pila, que se podr?
|
500 |
* ir recuperando con popStatus()
|
501 |
*/
|
502 |
public void pushStatus() { |
503 |
status.push(getStatusCloned()); |
504 |
} |
505 |
|
506 |
/**
|
507 |
* Obtiene el estado actual de los filtros, el ArrayList devuelto es una
|
508 |
* clonaci?n del original, asi no compartiran datos.
|
509 |
* @return
|
510 |
*/
|
511 |
public List<RasterFilter> getStatusCloned() { |
512 |
List<RasterFilter> newArray = new ArrayList<RasterFilter>(); |
513 |
for (int i = 0; i < list.size(); i++) |
514 |
try {
|
515 |
newArray.add((RasterFilter)(((BaseRasterFilter) list.get(i)).clone())); |
516 |
} catch (CloneNotSupportedException e) { |
517 |
System.out.println("No se ha podido clonar"); |
518 |
} |
519 |
return newArray;
|
520 |
} |
521 |
|
522 |
/**
|
523 |
* Saves the current status of the filters
|
524 |
* @param newArray
|
525 |
*/
|
526 |
public void setStatus(List<RasterFilter> newArray) { |
527 |
if(list != null) |
528 |
list.clear(); |
529 |
if(newArray == null) |
530 |
return;
|
531 |
for (int i = 0; i < newArray.size(); i++) |
532 |
if(list != null) |
533 |
list.add(newArray.get(i)); |
534 |
callFilterListChanged(this);
|
535 |
} |
536 |
|
537 |
/**
|
538 |
* Gets a status saved before through the call <code>pushStatus()</code>
|
539 |
*/
|
540 |
public void popStatus() { |
541 |
if (status.size() <= 0) |
542 |
return;
|
543 |
|
544 |
setStatus((List<RasterFilter>) status.pop());
|
545 |
} |
546 |
|
547 |
/**
|
548 |
* Gets a TreeMap with the environment parameters
|
549 |
* @return TreeMap
|
550 |
*/
|
551 |
public TreeMap<String, Object> getEnv() { |
552 |
return environment;
|
553 |
} |
554 |
|
555 |
/**
|
556 |
* Sets a TreeMap with the environment parameters
|
557 |
* @param env
|
558 |
*/
|
559 |
public void setEnv(TreeMap<String, Object> env) { |
560 |
this.environment = env;
|
561 |
} |
562 |
|
563 |
public void createFilterListFromStrings(List<String> f) throws FilterTypeException { |
564 |
RasterFilterListManagerImpl.createFilterListFromStrings(this, f);
|
565 |
} |
566 |
|
567 |
public RasterFilterListManager getManagerByID(String id) throws FilterManagerException { |
568 |
return new RasterFilterListManagerImpl(this).getManagerByID(id); |
569 |
} |
570 |
|
571 |
public RasterFilterListManager getManagerByFilterClass(Class<?> c) { |
572 |
if(manager == null) |
573 |
manager = new RasterFilterListManagerImpl(this); |
574 |
return manager.getManagerByFilterClass(c);
|
575 |
} |
576 |
|
577 |
public RasterFilterListManager getManagerByClass(Class<?> clase) { |
578 |
Object obj = null; |
579 |
Class<?>[] args = { RasterFilterList.class }; |
580 |
try {
|
581 |
Constructor<?> hazNuevo = clase.getConstructor(args);
|
582 |
Object[] args2 = { this }; |
583 |
obj = hazNuevo.newInstance(args2); |
584 |
} catch (SecurityException e) { |
585 |
e.printStackTrace(); |
586 |
} catch (NoSuchMethodException e) { |
587 |
e.printStackTrace(); |
588 |
} catch (IllegalArgumentException e) { |
589 |
e.printStackTrace(); |
590 |
} catch (InstantiationException e) { |
591 |
e.printStackTrace(); |
592 |
} catch (IllegalAccessException e) { |
593 |
e.printStackTrace(); |
594 |
} catch (InvocationTargetException e) { |
595 |
e.printStackTrace(); |
596 |
} |
597 |
return (RasterFilterListManager)obj;
|
598 |
} |
599 |
|
600 |
public Class<?> getFilterClassByID(String id) { |
601 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
602 |
ExtensionPoint point = extensionPoints.get("RasterFilter");
|
603 |
Iterator<?> it = point.iterator();
|
604 |
while(it.hasNext()) {
|
605 |
ExtensionPoint.Extension entry = (ExtensionPoint.Extension) it.next(); |
606 |
if (entry != null) { |
607 |
Class<?> managerClass = entry.getExtension();
|
608 |
RasterFilterListManager manager = getManagerByClass(managerClass); |
609 |
if(manager != null) { |
610 |
Class<?> c = manager.getFilterClassByID(id);
|
611 |
if(c != null) |
612 |
return c;
|
613 |
} |
614 |
} |
615 |
} |
616 |
return null; |
617 |
} |
618 |
|
619 |
public Params createEmptyFilterParams() {
|
620 |
return new ParamsImpl(); |
621 |
} |
622 |
|
623 |
public List<Class<?>> getRegisteredFilterList() { |
624 |
if(manager == null) |
625 |
manager = new RasterFilterListManagerImpl(this); |
626 |
return manager.getRasterFilterList();
|
627 |
} |
628 |
|
629 |
public List<Class<?>> getRegisteredFilterListByDataType(int dataType) { |
630 |
if(manager == null) |
631 |
manager = new RasterFilterListManagerImpl(this); |
632 |
return manager.getRasterFilterListByDataType(dataType);
|
633 |
} |
634 |
|
635 |
public RasterFilter createEmptyFilter(String strPackage) throws FilterTypeException { |
636 |
Class<?> filterClass = null; |
637 |
try {
|
638 |
filterClass = Class.forName(strPackage.trim());
|
639 |
} catch (ClassNotFoundException e) { |
640 |
throw new FilterTypeException("No puedo instanciar " + strPackage.trim()); |
641 |
} |
642 |
|
643 |
Constructor<?> con = null; |
644 |
try {
|
645 |
con = filterClass.getConstructor(); |
646 |
} catch (SecurityException e) { |
647 |
throw new FilterTypeException(""); |
648 |
} catch (NoSuchMethodException e) { |
649 |
throw new FilterTypeException(""); |
650 |
} |
651 |
|
652 |
BaseRasterFilter newFilter = null;
|
653 |
try {
|
654 |
newFilter = (BaseRasterFilter) con.newInstance(); |
655 |
} catch (IllegalArgumentException e) { |
656 |
throw new FilterTypeException(""); |
657 |
} catch (InstantiationException e) { |
658 |
throw new FilterTypeException(""); |
659 |
} catch (IllegalAccessException e) { |
660 |
throw new FilterTypeException(""); |
661 |
} catch (InvocationTargetException e) { |
662 |
throw new FilterTypeException(""); |
663 |
} |
664 |
return newFilter;
|
665 |
} |
666 |
|
667 |
public void loadFromState(PersistentState state) |
668 |
throws PersistenceException {
|
669 |
this.typeFilter = state.getInt("typeFilter"); |
670 |
|
671 |
/*List<PersistencyFilterParam> listFilterUsed = state.getList("paramlist");
|
672 |
|
673 |
ArrayList<Exception> exc = new ArrayList<Exception>();
|
674 |
for (int i = 0; i < listFilterUsed.size(); i++) {
|
675 |
try {
|
676 |
PersistencyFilterParam pfp = (PersistencyFilterParam) listFilterUsed.get(i);
|
677 |
if(pfp != null && pfp.getFilterClass() != null && pfp.getFilterParam() != null) {
|
678 |
RasterFilterListManager filterManager = getManagerByFilterClass(pfp.getFilterClass());
|
679 |
filterManager.setFilterList(this);
|
680 |
if(filterManager != null)
|
681 |
filterManager.addFilter(pfp.getFilterClass(), pfp.getFilterParam());
|
682 |
}
|
683 |
} catch (FilterTypeException e) {
|
684 |
exc.add(e);
|
685 |
}
|
686 |
}*/
|
687 |
|
688 |
} |
689 |
|
690 |
public void saveToState(PersistentState state) throws PersistenceException { |
691 |
state.set("typeFilter", typeFilter);
|
692 |
|
693 |
/*ArrayList<PersistencyFilterParam> filters = new ArrayList<PersistencyFilterParam>();
|
694 |
for (int i = 0; i < list.size(); i++) {
|
695 |
RasterFilter f = list.get(i);
|
696 |
Params uipar = f.getUIParams(f.getName());
|
697 |
PersistencyFilterParam param = new PersistencyFilterParam();
|
698 |
param.setFilterParam(uipar);
|
699 |
param.setFilterClass(f.getClass());
|
700 |
param.setFilterName(f.getName());
|
701 |
filters.add(param);
|
702 |
}
|
703 |
state.set("paramlist", filters);*/
|
704 |
} |
705 |
|
706 |
public static void registerPersistence() { |
707 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
708 |
DynStruct definition = manager.getDefinition(PERSISTENT_NAME); |
709 |
if( definition == null ) { |
710 |
definition = manager.addDefinition( |
711 |
DefaultRasterFilterList.class, |
712 |
PERSISTENT_NAME, |
713 |
PERSISTENT_DESCRIPTION, |
714 |
null,
|
715 |
null
|
716 |
); |
717 |
|
718 |
definition.addDynFieldInt("typeFilter").setMandatory(false); |
719 |
//definition.addDynFieldList("paramlist").setClassOfItems(PersistencyFilterParam.class).setMandatory(false);
|
720 |
} |
721 |
} |
722 |
|
723 |
/**
|
724 |
* Releases buffer resources
|
725 |
*/
|
726 |
public void dispose() { |
727 |
if (initialRasterBuffer != null) |
728 |
initialRasterBuffer.dispose(); |
729 |
try {
|
730 |
finalize(); |
731 |
} catch (Throwable e) { |
732 |
} |
733 |
} |
734 |
|
735 |
public Transparency getTransparency() { |
736 |
return (Transparency)getEnvParam("Transparency"); |
737 |
} |
738 |
|
739 |
protected void finalize() throws Throwable { |
740 |
initialRasterBuffer = null;
|
741 |
if(filterListListener != null) { |
742 |
filterListListener.clear(); |
743 |
filterListListener = null;
|
744 |
} |
745 |
if(status != null) { |
746 |
status.clear(); |
747 |
status = null;
|
748 |
} |
749 |
if(list != null) { |
750 |
list.clear(); |
751 |
list = null;
|
752 |
} |
753 |
super.finalize();
|
754 |
} |
755 |
} |