svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / beans / previewbase / PreviewFiltering.java @ 19307
History | View | Annotate | Download (6.71 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.raster.beans.previewbase; |
20 |
|
21 |
import java.util.ArrayList; |
22 |
|
23 |
import org.gvsig.raster.dataset.Params; |
24 |
import org.gvsig.raster.grid.filter.FilterTypeException; |
25 |
import org.gvsig.raster.grid.filter.IRasterFilterListManager; |
26 |
import org.gvsig.raster.grid.filter.RasterFilter; |
27 |
import org.gvsig.raster.grid.filter.RasterFilterList; |
28 |
import org.gvsig.raster.grid.filter.RasterFilterListManager; |
29 |
import org.gvsig.raster.hierarchy.IRasterRendering; |
30 |
import org.gvsig.raster.util.RasterToolsUtil; |
31 |
|
32 |
import com.iver.andami.PluginServices; |
33 |
|
34 |
/**
|
35 |
* Procesado de la imagen para la previsualizaci?n. Para poder usar esta clase despu?s de instanciarla
|
36 |
* habr? que asignarle un valor a showFiltersSelected aunque por defecto est? a true por lo que se
|
37 |
* visualizaran los cambios sin problemas, asigna una lista de filtros inicial (que ya tenga el raster
|
38 |
* aplicado) con setFilterStatus y asignar los filtros que queramos aplicar con addNewParam (una llamada
|
39 |
* por cada filtro).
|
40 |
*
|
41 |
* 19/02/2008
|
42 |
* @author Nacho Brodin nachobrodin@gmail.com
|
43 |
*/
|
44 |
public class PreviewFiltering implements IPreviewRenderProcess { |
45 |
|
46 |
private boolean showFiltersSelected = true; |
47 |
private ArrayList paramsList = new ArrayList(); |
48 |
private ArrayList filtersInit = null; |
49 |
|
50 |
/**
|
51 |
* Flag de selecci?n de activaci?n y desactivaci?n
|
52 |
* @param show
|
53 |
*/
|
54 |
public void showFiltersSelected(boolean show) { |
55 |
this.showFiltersSelected = show;
|
56 |
} |
57 |
|
58 |
/**
|
59 |
* Obtiene la lista de par?metros
|
60 |
* @return the paramsList
|
61 |
*/
|
62 |
public ArrayList getParamsList() { |
63 |
return paramsList;
|
64 |
} |
65 |
|
66 |
/**
|
67 |
* Asigna la lista de par?metros
|
68 |
* @param params
|
69 |
*/
|
70 |
public void setParamsList(ArrayList params) { |
71 |
this.paramsList = params;
|
72 |
} |
73 |
|
74 |
/**
|
75 |
* Asigna el arrayList de filtros inicial
|
76 |
* @param params
|
77 |
*/
|
78 |
public void setFilterStatus(ArrayList filtersInit) { |
79 |
this.filtersInit = filtersInit;
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* Devuelve el arrayList de filtros inicial
|
84 |
* @return
|
85 |
*/
|
86 |
public ArrayList getFilterStatus() { |
87 |
return filtersInit;
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* A?adir un nuevo Params a la lista de Params que podemos manejar. Un Params
|
92 |
* equivale a un filtro cargado. El hecho de trabajar con Params y no con
|
93 |
* filtros, simplifica totalmente el panel. Sin tener que depender de los
|
94 |
* filtros nada m?s que para el momento de dibujado o guardado.
|
95 |
* @param name
|
96 |
* @param params
|
97 |
* @param classFilter
|
98 |
*/
|
99 |
public void addNewParam(String name, Params params, Class classFilter) { |
100 |
ParamStruct param = new ParamStruct();
|
101 |
param.setFilterName(name); |
102 |
param.setFilterParam(params); |
103 |
param.setFilterClass(classFilter); |
104 |
paramsList.add(param); |
105 |
} |
106 |
|
107 |
/**
|
108 |
* Procesa la imagen con la lista de filtros si el flag showFilterSelected est? a true.
|
109 |
* Esta funci?n llama a addFilter por cada filtro a?adido pero es applyFilters la encargada
|
110 |
* de construir la lista.
|
111 |
*/
|
112 |
public void process(IRasterRendering rendering) throws FilterTypeException { |
113 |
rendering.getRenderFilterList().clear(); |
114 |
|
115 |
if (showFiltersSelected) {
|
116 |
RasterFilterList filterList = rendering.getRenderFilterList(); |
117 |
RasterFilterListManager stackManager = new RasterFilterListManager(filterList);
|
118 |
|
119 |
ArrayList listFilterUsed = applyFilters(rendering);
|
120 |
ArrayList exc = new ArrayList(); |
121 |
for (int i = 0; i < listFilterUsed.size(); i++) { |
122 |
IRasterFilterListManager filterManager = stackManager.getManagerByFilterClass(((ParamStruct) listFilterUsed.get(i)).getFilterClass()); |
123 |
try {
|
124 |
filterManager.addFilter(((ParamStruct) listFilterUsed.get(i)).getFilterClass(), ((ParamStruct) listFilterUsed.get(i)).getFilterParam()); |
125 |
} catch (FilterTypeException e) {
|
126 |
exc.add(e); |
127 |
} |
128 |
} |
129 |
if(exc.size() != 0) { |
130 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_adding_filters"), this, exc); |
131 |
exc.clear(); |
132 |
} |
133 |
} |
134 |
} |
135 |
|
136 |
/**
|
137 |
* Aqui se seleccionan que filtros se van a aplicar y se devuelven en forma
|
138 |
* de ArrayList tanto para el dibujado como cuando aceptan o aplican el panel.
|
139 |
* @param rendering
|
140 |
* @return
|
141 |
*/
|
142 |
public ArrayList applyFilters(IRasterRendering rendering) { |
143 |
ArrayList listFilterUsed = new ArrayList(); |
144 |
|
145 |
RasterFilterList filterList = new RasterFilterList();
|
146 |
filterList.setEnv(rendering.getRenderFilterList().getEnv()); |
147 |
RasterFilterListManager stackManager = new RasterFilterListManager(filterList);
|
148 |
|
149 |
if(filtersInit == null) |
150 |
return listFilterUsed;
|
151 |
|
152 |
// Conservamos filtros no visibles ya existentes
|
153 |
for (int i = 0; i < filtersInit.size(); i++) { |
154 |
// Si es visible no hacemos nada
|
155 |
if (((RasterFilter) filtersInit.get(i)).isVisible())
|
156 |
continue;
|
157 |
|
158 |
RasterFilter obj = null;
|
159 |
for (int j = 0; j < stackManager.getRasterFilterList().size(); j++) { |
160 |
Class classFilter = (Class) stackManager.getRasterFilterList().get(j); |
161 |
try {
|
162 |
obj = (RasterFilter) classFilter.newInstance(); |
163 |
if (obj.getName().equals(((RasterFilter) filtersInit.get(i)).getName()))
|
164 |
break;
|
165 |
} catch (InstantiationException e) { |
166 |
RasterToolsUtil.messageBoxError("error_creando_filtro", this, e); |
167 |
} catch (IllegalAccessException e) { |
168 |
RasterToolsUtil.messageBoxError("error_creando_filtro", this, e); |
169 |
} |
170 |
} |
171 |
|
172 |
// Si no encontramos el filtro apropiado, nos olvidamos de el
|
173 |
if (obj == null) |
174 |
continue;
|
175 |
|
176 |
// Si no es visible tenemos que conservar el filtro
|
177 |
try {
|
178 |
Params params = (Params) ((RasterFilter) filtersInit.get(i)).getUIParams(((RasterFilter) filtersInit.get(i)).getName()).clone(); |
179 |
// A?ado el parametro RenderBands a los parametros del filtro
|
180 |
String rgb = rendering.getRenderBands()[0] + " " + rendering.getRenderBands()[1] + " " + rendering.getRenderBands()[2]; |
181 |
params.setParam("RenderBands", rgb, 0, null); |
182 |
|
183 |
ParamStruct newParam = new ParamStruct();
|
184 |
newParam.setFilterClass(obj.getClass()); |
185 |
newParam.setFilterName(((RasterFilter) filtersInit.get(i)).getName()); |
186 |
newParam.setFilterParam(params); |
187 |
listFilterUsed.add(newParam); |
188 |
} catch (CloneNotSupportedException e) { |
189 |
} |
190 |
} |
191 |
return listFilterUsed;
|
192 |
} |
193 |
|
194 |
} |