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