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