root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / filter / FilterListener.java @ 12118
History | View | Annotate | Download (18.1 KB)
1 | 11750 | bsanchez | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2006 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 | 11572 | bsanchez | package org.gvsig.rastertools.filter; |
20 | |||
21 | 11856 | bsanchez | import java.awt.Component; |
22 | 11572 | bsanchez | import java.awt.Dimension; |
23 | import java.awt.Graphics2D; |
||
24 | import java.awt.event.ActionEvent; |
||
25 | import java.awt.event.ActionListener; |
||
26 | import java.awt.geom.AffineTransform; |
||
27 | import java.awt.geom.Dimension2D; |
||
28 | 11831 | bsanchez | import java.io.File; |
29 | 11715 | bsanchez | import java.util.ArrayList; |
30 | import java.util.EventObject; |
||
31 | 11750 | bsanchez | import java.util.Hashtable; |
32 | 11572 | bsanchez | |
33 | 11831 | bsanchez | import javax.swing.JFileChooser; |
34 | 11856 | bsanchez | import javax.swing.JOptionPane; |
35 | 11750 | bsanchez | import javax.swing.ListModel; |
36 | |||
37 | 11572 | bsanchez | import org.gvsig.fmap.layers.FLyrRasterSE; |
38 | import org.gvsig.gui.beans.imagenavigator.IClientImageNavigator; |
||
39 | 11815 | bsanchez | import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
40 | 11750 | bsanchez | import org.gvsig.gui.beans.propertiespanel.PropertiesComponent; |
41 | 11715 | bsanchez | import org.gvsig.gui.beans.propertiespanel.PropertiesComponentListener; |
42 | 11750 | bsanchez | import org.gvsig.gui.beans.propertiespanel.PropertyStruct; |
43 | 11654 | bsanchez | import org.gvsig.gui.beans.treelist.event.TreeListChangeEvent; |
44 | import org.gvsig.gui.beans.treelist.event.TreeListEvent; |
||
45 | import org.gvsig.gui.beans.treelist.listeners.TreeListChangeListener; |
||
46 | import org.gvsig.gui.beans.treelist.listeners.TreeListComponentListener; |
||
47 | 11972 | bsanchez | import org.gvsig.raster.dataset.GeoRasterWriter; |
48 | 11856 | bsanchez | import org.gvsig.raster.dataset.MultiRasterDataset; |
49 | 11750 | bsanchez | import org.gvsig.raster.dataset.Params; |
50 | import org.gvsig.raster.dataset.Params.Param; |
||
51 | import org.gvsig.raster.grid.filter.IRasterFilterListManager; |
||
52 | import org.gvsig.raster.grid.filter.RasterFilterList; |
||
53 | import org.gvsig.raster.grid.filter.RasterFilterListManager; |
||
54 | 11572 | bsanchez | import org.gvsig.raster.grid.render.Rendering; |
55 | import org.gvsig.raster.shared.Extent; |
||
56 | import org.gvsig.raster.shared.ViewPortData; |
||
57 | 11893 | nacho | import org.gvsig.rastertools.RasterModule; |
58 | 11572 | bsanchez | import org.gvsig.rastertools.filter.ui.FilterPanel; |
59 | |||
60 | 11831 | bsanchez | import com.iver.andami.PluginServices; |
61 | import com.iver.andami.Utilities; |
||
62 | 11856 | bsanchez | import com.iver.andami.ui.mdiManager.IWindow; |
63 | import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
||
64 | 11572 | bsanchez | import com.iver.cit.gvsig.fmap.ViewPort; |
65 | 11856 | bsanchez | import com.iver.cit.gvsig.fmap.layers.FLayer; |
66 | import com.iver.cit.gvsig.project.documents.view.gui.View; |
||
67 | 11803 | bsanchez | /**
|
68 | * <code>FilterListener</code> es la clase donde se procesar? gran parte del
|
||
69 | * c?digo que controla el panel para el manejo de un layer en la aplicaci?n de
|
||
70 | * filtros.
|
||
71 | *
|
||
72 | * @version 24/05/2007
|
||
73 | * @author Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
||
74 | */
|
||
75 | 11715 | bsanchez | public class FilterListener implements ActionListener, IClientImageNavigator, TreeListComponentListener, TreeListChangeListener, PropertiesComponentListener { |
76 | 11942 | bsanchez | FilterPanel filterPanel = null;
|
77 | public int actualParam = -1; |
||
78 | public ArrayList paramsList = new ArrayList(); |
||
79 | 11831 | bsanchez | |
80 | 11750 | bsanchez | public class ParamStruct { |
81 | String filterName = null; |
||
82 | Params filterParam = null;
|
||
83 | Class filterClass = null; |
||
84 | 11572 | bsanchez | |
85 | 11715 | bsanchez | /**
|
86 | 11750 | bsanchez | * @return the filterName
|
87 | 11715 | bsanchez | */
|
88 | 11750 | bsanchez | public String getFilterName() { |
89 | return filterName;
|
||
90 | 11715 | bsanchez | } |
91 | |||
92 | /**
|
||
93 | 11750 | bsanchez | * @param filterName the filterName to set
|
94 | 11715 | bsanchez | */
|
95 | 11750 | bsanchez | public void setFilterName(String filterName) { |
96 | this.filterName = filterName;
|
||
97 | 11715 | bsanchez | } |
98 | |||
99 | /**
|
||
100 | 11750 | bsanchez | * @return the filterParam
|
101 | 11715 | bsanchez | */
|
102 | 11750 | bsanchez | public Params getFilterParam() {
|
103 | return filterParam;
|
||
104 | 11715 | bsanchez | } |
105 | |||
106 | /**
|
||
107 | 11750 | bsanchez | * @param filterParam the filterParam to set
|
108 | 11715 | bsanchez | */
|
109 | 11750 | bsanchez | public void setFilterParam(Params filterParam) { |
110 | this.filterParam = filterParam;
|
||
111 | 11715 | bsanchez | } |
112 | |||
113 | 11750 | bsanchez | /**
|
114 | * @return the filterClass
|
||
115 | */
|
||
116 | public Class getFilterClass() { |
||
117 | return filterClass;
|
||
118 | } |
||
119 | |||
120 | /**
|
||
121 | * @param filterClass the filterClass to set
|
||
122 | */
|
||
123 | public void setFilterClass(Class filterClass) { |
||
124 | this.filterClass = filterClass;
|
||
125 | } |
||
126 | 11897 | bsanchez | } |
127 | |||
128 | 11750 | bsanchez | /**
|
129 | * Construye un FilterListener especificando el FilterPanel asociado
|
||
130 | * @param fp
|
||
131 | */
|
||
132 | 11572 | bsanchez | public FilterListener(FilterPanel fp) {
|
133 | filterPanel = fp; |
||
134 | } |
||
135 | |||
136 | 11750 | bsanchez | /**
|
137 | 11897 | bsanchez | * Asignamos los valores del PropertiesComponent al Params seleccionado
|
138 | */
|
||
139 | public void RefreshDataProperties() { |
||
140 | 11750 | bsanchez | if (actualParam == -1) return; |
141 | 11897 | bsanchez | |
142 | 11856 | bsanchez | ArrayList listValues = getFilterPanel().getPropertiesComponent().getValues();
|
143 | 11897 | bsanchez | |
144 | 11750 | bsanchez | Params params = ((ParamStruct) paramsList.get(actualParam)).getFilterParam(); |
145 | for (int j=0; j<listValues.size(); j++) { |
||
146 | PropertyStruct ps = (PropertyStruct) listValues.get(j); |
||
147 | params.changeParamValue(ps.getKey(), ps.getNewValue().toString()); |
||
148 | } |
||
149 | 11572 | bsanchez | } |
150 | |||
151 | 11897 | bsanchez | /**
|
152 | * Obtener la posici?n del Param seleccionado en el ArrayList
|
||
153 | * @param filterName
|
||
154 | * @return
|
||
155 | */
|
||
156 | private int getParamSelected(String filterName) { |
||
157 | for (int i = 0; i < paramsList.size(); i++) { |
||
158 | 11750 | bsanchez | if (((ParamStruct) paramsList.get(i)).getFilterName().equals(filterName))
|
159 | return i;
|
||
160 | } |
||
161 | 11897 | bsanchez | return -1; |
162 | 11750 | bsanchez | } |
163 | 11572 | bsanchez | |
164 | 11897 | bsanchez | /**
|
165 | * Cambiar el panel de propiedades central por el nuevo panel, segun el filtro
|
||
166 | * seleccionado que se pasa por par?metro.
|
||
167 | * @param filter
|
||
168 | */
|
||
169 | 11750 | bsanchez | public void changePanel(String filter) { |
170 | int posParam = getParamSelected(filter);
|
||
171 | 11572 | bsanchez | |
172 | 11750 | bsanchez | RefreshDataProperties(); |
173 | actualParam = posParam; |
||
174 | 11897 | bsanchez | |
175 | 11750 | bsanchez | PropertiesComponent propertiesComponent = new PropertiesComponent();
|
176 | 11897 | bsanchez | |
177 | 11750 | bsanchez | if (posParam != -1) { |
178 | 11897 | bsanchez | |
179 | 11750 | bsanchez | Params params = ((ParamStruct) paramsList.get(actualParam)).getFilterParam(); |
180 | if (params != null) { |
||
181 | for (int i = 0; i < params.getNumParams(); i++) { |
||
182 | Param p = params.getParam(i); |
||
183 | String name = p.id;
|
||
184 | String key = p.id;
|
||
185 | 12030 | bsanchez | if (name.equals("FilterName")) continue; |
186 | 11750 | bsanchez | Object[] types = null; |
187 | int selectedValue = 0; |
||
188 | 11654 | bsanchez | |
189 | 11750 | bsanchez | switch (params.getParam(i).type) {
|
190 | case Params.CHECK:
|
||
191 | propertiesComponent.addValue(name, key, new Boolean(p.defaultValue), types); |
||
192 | break;
|
||
193 | case Params.CHOICE:
|
||
194 | ArrayList list = new ArrayList(); |
||
195 | for (int j = 0; j < p.list.length; j++) { |
||
196 | list.add(p.list[j]); |
||
197 | if (p.defaultValue.compareTo(p.list[j]) == 0) |
||
198 | selectedValue = j; |
||
199 | } |
||
200 | types = new Object[] { new Integer(PropertiesComponent.TYPE_COMBO), list }; |
||
201 | propertiesComponent.addValue(name, key, new Integer(selectedValue), types); |
||
202 | break;
|
||
203 | case Params.SLIDER:
|
||
204 | 11897 | bsanchez | types = new Object[]{new Integer(PropertiesComponent.TYPE_SLIDER), new Integer(p.list[0]), new Integer(p.list[1])}; |
205 | propertiesComponent.addValue(name, key, new Integer((int) Math.round(new Double(p.defaultValue).doubleValue())), types); |
||
206 | break;
|
||
207 | 11750 | bsanchez | default:
|
208 | propertiesComponent.addValue(params.getParam(i).id, params.getParam(i).id, params.getParam(i).defaultValue, null);
|
||
209 | break;
|
||
210 | 11654 | bsanchez | } |
211 | } |
||
212 | } |
||
213 | 11572 | bsanchez | } |
214 | 11856 | bsanchez | getFilterPanel().setNewPropertiesComponent(propertiesComponent, filter); |
215 | 11572 | bsanchez | } |
216 | 11803 | bsanchez | |
217 | /**
|
||
218 | * A?adir un nuevo Params a la lista de Params que podemos manejar. Un Params
|
||
219 | * equivale a un filtro cargado. El hecho de trabajar con Params y no con
|
||
220 | * filtros, simplifica totalmente el panel. Sin tener que depender de los
|
||
221 | * filtros nada m?s que para el momento de dibujado o guardado.
|
||
222 | * @param name
|
||
223 | * @param params
|
||
224 | * @param classFilter
|
||
225 | */
|
||
226 | 11750 | bsanchez | public void addNewParam(String name, Params params, Class classFilter) { |
227 | ParamStruct param = new ParamStruct();
|
||
228 | param.setFilterName(name); |
||
229 | param.setFilterParam(params); |
||
230 | param.setFilterClass(classFilter); |
||
231 | paramsList.add(param); |
||
232 | } |
||
233 | 11654 | bsanchez | |
234 | 11750 | bsanchez | /*
|
235 | 11754 | bsanchez | * (non-Javadoc)
|
236 | * @see org.gvsig.gui.beans.imagenavigator.IClientImageNavigator#drawImage(java.awt.Graphics2D, double, double, double, double, double, int, int)
|
||
237 | */
|
||
238 | public void drawImage(Graphics2D g, double x1, double y1, double x2, double y2, double zoom, int width, int height) { |
||
239 | 11856 | bsanchez | if (getFilterPanel().getLayer() == null) |
240 | 11754 | bsanchez | return;
|
241 | |||
242 | 11856 | bsanchez | Rendering rendering = ((FLyrRasterSE) getFilterPanel().getLayer()).getRender(); |
243 | 11754 | bsanchez | |
244 | if ((rendering == null) || ((x2 - x1) == 0.0) || ((y2 - y1) == 0.0)) |
||
245 | return;
|
||
246 | |||
247 | 11864 | bsanchez | rendering.getFilterList().pushStatus(); |
248 | |||
249 | 11754 | bsanchez | rendering.getFilterList().clear(); |
250 | |||
251 | RasterFilterList filterList = rendering.getFilterList(); |
||
252 | RasterFilterListManager stackManager = new RasterFilterListManager(filterList);
|
||
253 | 11897 | bsanchez | |
254 | 11856 | bsanchez | if (getFilterPanel().getCBShowFilters().isSelected()) {
|
255 | ListModel list = getFilterPanel().getTreeListContainer().getListModel();
|
||
256 | 11784 | bsanchez | for (int i = 0; i < list.getSize(); i++) { |
257 | 11856 | bsanchez | Hashtable hastTable = getFilterPanel().getTreeListContainer().getMap();
|
258 | 11784 | bsanchez | for (int j = 0; j < paramsList.size(); j++) { |
259 | 11831 | bsanchez | boolean active = true; |
260 | 11856 | bsanchez | Param param = ((ParamStruct) paramsList.get(j)).getFilterParam().getParamById(PluginServices.getText(this, "enabled")); |
261 | 11831 | bsanchez | if ((param != null) && ((new Boolean(param.defaultValue).booleanValue()) == false)) |
262 | active = false;
|
||
263 | 11897 | bsanchez | if (active) {
|
264 | 11831 | bsanchez | if (((ParamStruct) paramsList.get(j)).getFilterName().equals(hastTable.get(list.getElementAt(i)))) {
|
265 | IRasterFilterListManager filterManager = stackManager.getManagerByFilterClass(((ParamStruct) paramsList.get(j)).getFilterClass()); |
||
266 | 11897 | bsanchez | |
267 | 11986 | bsanchez | Params params; |
268 | try {
|
||
269 | params = (Params) ((ParamStruct) paramsList.get(j)).getFilterParam().clone(); |
||
270 | String rgb = rendering.getRenderBands()[0] + " " + rendering.getRenderBands()[1] + " " + rendering.getRenderBands()[2]; |
||
271 | params.setParam("RenderBands", rgb, 0, null); |
||
272 | 11897 | bsanchez | |
273 | 11986 | bsanchez | filterManager.addFilter(((ParamStruct) paramsList.get(j)).getFilterClass(), params); |
274 | } catch (CloneNotSupportedException e) { |
||
275 | } |
||
276 | 11831 | bsanchez | } |
277 | 11750 | bsanchez | } |
278 | } |
||
279 | } |
||
280 | 11754 | bsanchez | } |
281 | 11831 | bsanchez | |
282 | ViewPort vp = new ViewPort(null); |
||
283 | |||
284 | Dimension2D dimension = new Dimension(width, height); |
||
285 | Extent extent = new Extent(x1, y1, x2, y2);
|
||
286 | |||
287 | ViewPortData vp2 = new ViewPortData(vp.getProjection(), extent, dimension);
|
||
288 | vp2.setMat(new AffineTransform(zoom, 0.0, 0.0, zoom, -x1*zoom, -y1*zoom)); |
||
289 | |||
290 | 11856 | bsanchez | Extent extent2 = ((FLyrRasterSE) getFilterPanel().getLayer()).getDatasource().getExtent(); |
291 | 11831 | bsanchez | |
292 | AffineTransform trans = g.getTransform();
|
||
293 | // Calcular cuanto sobresale la imagen y rectificar ese desplazamiento
|
||
294 | if (y1 > extent2.maxY()) {
|
||
295 | g.translate(0.0, (-(extent2.maxY() - y1) * zoom)*2.0); |
||
296 | } |
||
297 | |||
298 | 11754 | bsanchez | rendering.draw(g, vp2); |
299 | 11831 | bsanchez | g.setTransform(trans); |
300 | 11864 | bsanchez | |
301 | rendering.getFilterList().popStatus(); |
||
302 | 11754 | bsanchez | } |
303 | 11750 | bsanchez | |
304 | /*
|
||
305 | 11754 | bsanchez | * (non-Javadoc)
|
306 | * @see org.gvsig.gui.beans.propertiespanel.PropertiesComponentListener#actionChangeProperties(java.util.EventObject)
|
||
307 | */
|
||
308 | public void actionChangeProperties(EventObject e) { |
||
309 | RefreshDataProperties(); |
||
310 | 11856 | bsanchez | getFilterPanel().refreshPreview(); |
311 | 11754 | bsanchez | } |
312 | 11750 | bsanchez | |
313 | 11754 | bsanchez | /*
|
314 | * (non-Javadoc)
|
||
315 | * @see org.gvsig.gui.beans.treelist.listeners.TreeListChangeListener#actionChangeSelection(org.gvsig.gui.beans.treelist.event.TreeListChangeEvent)
|
||
316 | */
|
||
317 | public void actionChangeSelection(TreeListChangeEvent e) { |
||
318 | changePanel(e.getItem()); |
||
319 | } |
||
320 | 11654 | bsanchez | |
321 | 11754 | bsanchez | /*
|
322 | * (non-Javadoc)
|
||
323 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||
324 | */
|
||
325 | public void actionPerformed(ActionEvent e) { |
||
326 | 11856 | bsanchez | getFilterPanel().refreshPreview(); |
327 | 11754 | bsanchez | } |
328 | 11654 | bsanchez | |
329 | 11754 | bsanchez | /*
|
330 | * (non-Javadoc)
|
||
331 | * @see org.gvsig.gui.beans.treelist.listeners.TreeListComponentListener#elementAdded(org.gvsig.gui.beans.treelist.event.TreeListEvent)
|
||
332 | */
|
||
333 | public void elementAdded(TreeListEvent e) { |
||
334 | 11856 | bsanchez | getFilterPanel().refreshPreview(); |
335 | 11754 | bsanchez | } |
336 | 11654 | bsanchez | |
337 | 11754 | bsanchez | /*
|
338 | * (non-Javadoc)
|
||
339 | * @see org.gvsig.gui.beans.treelist.listeners.TreeListComponentListener#elementMoved(org.gvsig.gui.beans.treelist.event.TreeListEvent)
|
||
340 | */
|
||
341 | public void elementMoved(TreeListEvent e) { |
||
342 | 11856 | bsanchez | getFilterPanel().refreshPreview(); |
343 | 11754 | bsanchez | } |
344 | 11715 | bsanchez | |
345 | 11754 | bsanchez | /*
|
346 | * (non-Javadoc)
|
||
347 | * @see org.gvsig.gui.beans.treelist.listeners.TreeListComponentListener#elementRemoved(org.gvsig.gui.beans.treelist.event.TreeListEvent)
|
||
348 | */
|
||
349 | public void elementRemoved(TreeListEvent e) { |
||
350 | 11856 | bsanchez | getFilterPanel().refreshPreview(); |
351 | 11754 | bsanchez | } |
352 | 11784 | bsanchez | |
353 | /**
|
||
354 | * @return the paramsList
|
||
355 | */
|
||
356 | public ArrayList getParamsList() { |
||
357 | return paramsList;
|
||
358 | } |
||
359 | 11897 | bsanchez | |
360 | /**
|
||
361 | * Devuelve la ruta del fichero donde se va a guardar, en caso de guardarse
|
||
362 | * en memoria, calcula el nombre sin preguntar y devuelve la ruta.
|
||
363 | * @return
|
||
364 | */
|
||
365 | public String getFileSelected() { |
||
366 | 11831 | bsanchez | String path = ""; |
367 | 11856 | bsanchez | if (getFilterPanel().getRadioFileGenerate().isSelected()) {
|
368 | 11893 | nacho | JFileChooser chooser = new JFileChooser(RasterModule.getPath()); |
369 | 11897 | bsanchez | chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero")); |
370 | |||
371 | //A?adimos las extensiones que hayan sido registradas en el driver
|
||
372 | String[] extList = GeoRasterWriter.getDriversExtensions(); |
||
373 | for(int i=0;i<extList.length;i++) |
||
374 | chooser.addChoosableFileFilter(new WriterFilter(extList[i]));
|
||
375 | |||
376 | 11856 | bsanchez | if (chooser.showOpenDialog(getFilterPanel()) != JFileChooser.APPROVE_OPTION) |
377 | 11897 | bsanchez | return null; |
378 | |||
379 | 11831 | bsanchez | String fName = chooser.getSelectedFile().toString();
|
380 | String ext = ((WriterFilter)chooser.getFileFilter()).getDescription();
|
||
381 | 11897 | bsanchez | |
382 | 11831 | bsanchez | ext = ext.toLowerCase().substring(ext.lastIndexOf(".") + 1, ext.length()); |
383 | 11897 | bsanchez | |
384 | 11831 | bsanchez | if ((fName != null) && !fName.equals("")) |
385 | 11897 | bsanchez | if (!fName.endsWith("." + ext)) |
386 | fName = fName + "." + ext;
|
||
387 | |||
388 | 11893 | nacho | RasterModule.setPath(chooser.getSelectedFile().getPath().substring(0, chooser.getSelectedFile().getPath().lastIndexOf(File.separator))); |
389 | 11831 | bsanchez | path = fName; |
390 | } else {
|
||
391 | 11905 | bsanchez | path = Utilities.createTempDirectory() + File.separator + getFilterPanel().getFilenameTextField().getText() + ".tif"; |
392 | 11945 | bsanchez | filterPanel.setNewLayerText(); |
393 | 11831 | bsanchez | } |
394 | 11897 | bsanchez | return path;
|
395 | } |
||
396 | |||
397 | 11912 | bsanchez | /**
|
398 | * Que acciones se ejecutaran al haber presionado el bot?n aceptar o aplicar
|
||
399 | */
|
||
400 | 11897 | bsanchez | public void accept() { |
401 | MultiRasterDataset multiRasterDataset = (MultiRasterDataset)((FLyrRasterSE) getFilterPanel().getLayer()).getGeoRasterMultiDataset(); |
||
402 | 11856 | bsanchez | if (multiRasterDataset == null) |
403 | return;
|
||
404 | 11831 | bsanchez | |
405 | 11905 | bsanchez | String path = null; |
406 | if (!getFilterPanel().getRadioOnlyView().isSelected()) {
|
||
407 | path = getFileSelected(); |
||
408 | if (path == null) |
||
409 | return;
|
||
410 | } |
||
411 | 11897 | bsanchez | |
412 | // Array para guardar los filtros que se van a usar en forma de ParamStruct
|
||
413 | ArrayList listFilterUsed = new ArrayList(); |
||
414 | |||
415 | 11856 | bsanchez | Rendering rendering = ((FLyrRasterSE) getFilterPanel().getLayer()).getRender(); |
416 | 11815 | bsanchez | |
417 | 11856 | bsanchez | ListModel list = getFilterPanel().getTreeListContainer().getListModel();
|
418 | for (int i = 0; i < list.getSize(); i++) { |
||
419 | Hashtable hastTable = getFilterPanel().getTreeListContainer().getMap();
|
||
420 | for (int j = 0; j < paramsList.size(); j++) { |
||
421 | boolean active = true; |
||
422 | Param param = ((ParamStruct) paramsList.get(j)).getFilterParam().getParamById(PluginServices.getText(this, "enabled")); |
||
423 | if ((param != null) && ((new Boolean(param.defaultValue).booleanValue()) == false)) |
||
424 | active = false;
|
||
425 | 11897 | bsanchez | if (active) {
|
426 | 11856 | bsanchez | if (((ParamStruct) paramsList.get(j)).getFilterName().equals(hastTable.get(list.getElementAt(i)))) {
|
427 | 11897 | bsanchez | try {
|
428 | Params params = (Params) ((ParamStruct) paramsList.get(j)).getFilterParam().clone(); |
||
429 | 11856 | bsanchez | |
430 | 11897 | bsanchez | // A?ado el parametro RenderBands a los parametros del filtro
|
431 | String rgb = rendering.getRenderBands()[0] + " " + rendering.getRenderBands()[1] + " " + rendering.getRenderBands()[2]; |
||
432 | params.setParam("RenderBands", rgb, 0, null); |
||
433 | |||
434 | ParamStruct newParam = new ParamStruct();
|
||
435 | newParam.setFilterClass(((ParamStruct) paramsList.get(j)).getFilterClass()); |
||
436 | newParam.setFilterName(((ParamStruct) paramsList.get(j)).getFilterName()); |
||
437 | newParam.setFilterParam(params); |
||
438 | listFilterUsed.add(newParam); |
||
439 | |||
440 | } catch (CloneNotSupportedException e) { |
||
441 | // TODO Auto-generated catch block
|
||
442 | } |
||
443 | 11856 | bsanchez | } |
444 | } |
||
445 | } |
||
446 | } |
||
447 | 11864 | bsanchez | |
448 | 11897 | bsanchez | if (filterPanel.getRadioOnlyView().isSelected()) {
|
449 | FilterProcess.addSelectedFilters(rendering.getFilterList(), listFilterUsed); |
||
450 | getFilterPanel().getLayer().getMapContext().invalidate(); |
||
451 | } else {
|
||
452 | FilterProcess filterProcess = new FilterProcess(this, path, multiRasterDataset, listFilterUsed); |
||
453 | 11856 | bsanchez | IncrementableTask incrementableTask = new IncrementableTask(filterProcess);
|
454 | filterProcess.setIncrementableTask(incrementableTask); |
||
455 | incrementableTask.showWindow(); |
||
456 | 11897 | bsanchez | |
457 | 11856 | bsanchez | filterProcess.start(); |
458 | incrementableTask.start(); |
||
459 | } |
||
460 | 11815 | bsanchez | } |
461 | 11897 | bsanchez | |
462 | 11912 | bsanchez | /**
|
463 | * Devuelve el FilterPanel asociado al FilterListener
|
||
464 | * @return
|
||
465 | */
|
||
466 | 11856 | bsanchez | public FilterPanel getFilterPanel() {
|
467 | return filterPanel;
|
||
468 | } |
||
469 | 11897 | bsanchez | |
470 | 11856 | bsanchez | /**
|
471 | * Acciones que se realizan al finalizar de crear los recortes de imagen.
|
||
472 | * Este m?todo es llamado por el thread TailRasterProcess al finalizar.
|
||
473 | */
|
||
474 | public void loadLayerInToc(String fileName) { |
||
475 | if (!getFilterPanel().getRadioNewLayer().isSelected())
|
||
476 | return;
|
||
477 | if(!new File(fileName).exists()) |
||
478 | return;
|
||
479 | // seleccionamos la vista de gvSIG
|
||
480 | com.iver.cit.gvsig.project.documents.view.gui.View theView = null;
|
||
481 | try {
|
||
482 | IWindow[] allViews = PluginServices.getMDIManager().getAllWindows();
|
||
483 | for (int i = 0; i < allViews.length; i++) { |
||
484 | if (allViews[i] instanceof com.iver.cit.gvsig.project.documents.view.gui.View |
||
485 | && PluginServices.getMDIManager().getWindowInfo((View) allViews[i])
|
||
486 | .getTitle().equals(getFilterPanel().getViewName())) |
||
487 | theView = (com.iver.cit.gvsig.project.documents.view.gui.View) allViews[i]; |
||
488 | } |
||
489 | if (theView == null) |
||
490 | return;
|
||
491 | } catch (ClassCastException ex) { |
||
492 | // logger.error(PluginServices.getText(this,"cant_get_view "), ex);
|
||
493 | return;
|
||
494 | } |
||
495 | |||
496 | // Cargamos las capas
|
||
497 | theView.getMapControl().getMapContext().beginAtomicEvent(); |
||
498 | 11897 | bsanchez | |
499 | 11856 | bsanchez | //Driver driver = LayerFactory.getDM().getDriver("gvSIG Raster Driver");
|
500 | int endIndex = fileName.lastIndexOf("."); |
||
501 | if (endIndex < 0) |
||
502 | endIndex = fileName.length(); |
||
503 | FLayer lyr = null;
|
||
504 | try {
|
||
505 | lyr = FLyrRasterSE.createLayer(fileName.substring( |
||
506 | fileName.lastIndexOf(File.separator) + 1, endIndex), |
||
507 | new File(fileName), theView.getMapControl().getProjection()); |
||
508 | } catch (LoadLayerException e) {
|
||
509 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
||
510 | PluginServices.getText(this, "error_cargar_capa")); |
||
511 | } |
||
512 | theView.getMapControl().getMapContext().getLayers().addLayer(lyr); |
||
513 | theView.getMapControl().getMapContext().endAtomicEvent(); |
||
514 | |||
515 | 11897 | bsanchez | getFilterPanel().getLayer().getMapContext().invalidate(); |
516 | 11856 | bsanchez | } |
517 | 11831 | bsanchez | } |
518 | |||
519 | /**
|
||
520 | * @author Nacho Brodin <brodin_ign@gva.es>
|
||
521 | * Filtro para el selector de formatos de escritura
|
||
522 | */
|
||
523 | class WriterFilter extends javax.swing.filechooser.FileFilter { |
||
524 | private String filter; |
||
525 | |||
526 | 11838 | bsanchez | public WriterFilter(String fil) { |
527 | 11831 | bsanchez | this.filter = fil;
|
528 | } |
||
529 | |||
530 | public boolean accept(File f) { |
||
531 | return f.isDirectory() || f.getName().toLowerCase().endsWith("." + filter); |
||
532 | } |
||
533 | |||
534 | public String getDescription() { |
||
535 | return "." + filter; |
||
536 | } |
||
537 | 11572 | bsanchez | } |