root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / filter / ui / FilterPanel.java @ 19567
History | View | Annotate | Download (14.8 KB)
1 |
/* 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 |
package org.gvsig.rastertools.filter.ui; |
20 |
|
21 |
import java.awt.BorderLayout; |
22 |
import java.awt.Dimension; |
23 |
import java.awt.GridBagConstraints; |
24 |
import java.awt.GridBagLayout; |
25 |
import java.awt.Insets; |
26 |
import java.util.ArrayList; |
27 |
import java.util.Hashtable; |
28 |
|
29 |
import javax.swing.BorderFactory; |
30 |
import javax.swing.DefaultListModel; |
31 |
import javax.swing.JCheckBox; |
32 |
import javax.swing.JPanel; |
33 |
import javax.swing.border.TitledBorder; |
34 |
|
35 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
36 |
import org.gvsig.gui.beans.propertiespanel.PropertiesComponent; |
37 |
import org.gvsig.gui.beans.treelist.TreeListContainer; |
38 |
import org.gvsig.raster.beans.previewbase.IPreviewRenderProcess; |
39 |
import org.gvsig.raster.beans.previewbase.ParamStruct; |
40 |
import org.gvsig.raster.beans.previewbase.PreviewBasePanel; |
41 |
import org.gvsig.raster.dataset.Params; |
42 |
import org.gvsig.raster.dataset.Params.Param; |
43 |
import org.gvsig.raster.grid.filter.FilterTypeException; |
44 |
import org.gvsig.raster.grid.filter.RasterFilter; |
45 |
import org.gvsig.raster.grid.filter.RasterFilterList; |
46 |
import org.gvsig.raster.grid.filter.RasterFilterListManager; |
47 |
import org.gvsig.raster.grid.render.Rendering; |
48 |
import org.gvsig.raster.hierarchy.IRasterRendering; |
49 |
import org.gvsig.raster.util.RasterToolsUtil; |
50 |
import org.gvsig.rastertools.filter.FilterListener; |
51 |
|
52 |
import com.iver.andami.PluginServices; |
53 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
54 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
55 |
/**
|
56 |
* Dialogo para los filtros de raster.
|
57 |
*
|
58 |
* @version 30/05/2007
|
59 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
60 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
61 |
*/
|
62 |
public class FilterPanel extends JPanel implements IPreviewRenderProcess { |
63 |
private static final long serialVersionUID = 7152780112689637266L; |
64 |
|
65 |
private PreviewBasePanel previewBasePanel = null; |
66 |
private FLayer layer = null; |
67 |
private FilterListener filterListener = null; |
68 |
private PropertiesComponent propertiesComponent = null; |
69 |
|
70 |
private ArrayList filterStatus = null; |
71 |
private JCheckBox jCBShowFilters = null; |
72 |
private String viewName = null; |
73 |
private JPanel jPanelOptions = null; |
74 |
private FilterMainPanel filterMain = null; |
75 |
private FilterDialog filterDialog = null; |
76 |
private NewOrSaveLayerPanel newLayerPanel = null; |
77 |
|
78 |
/**
|
79 |
* Constructor
|
80 |
* @param width Ancho del panel
|
81 |
* @param height Alto del panel
|
82 |
*/
|
83 |
public FilterPanel(FLayer layer, FilterDialog filterDialog) {
|
84 |
this.filterDialog = filterDialog;
|
85 |
setLayer(layer); |
86 |
initialize(); |
87 |
} |
88 |
|
89 |
private void initialize() { |
90 |
translate(); |
91 |
setLayout(new BorderLayout()); |
92 |
add(getPreviewBasePanel(), BorderLayout.CENTER);
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Seccion donde ir?n todas las traducciones invariables del componente
|
97 |
*/
|
98 |
private void translate() { |
99 |
getCBShowFilters().setText(PluginServices.getText(this, "aplicar_vista_previa")); |
100 |
} |
101 |
|
102 |
/**
|
103 |
* Obtiene el panel con el histograma
|
104 |
* @return HistogramPanel
|
105 |
*/
|
106 |
private PreviewBasePanel getPreviewBasePanel() {
|
107 |
if (previewBasePanel == null) { |
108 |
ArrayList list = new ArrayList(); |
109 |
list.add(getMainPanel()); |
110 |
previewBasePanel = new PreviewBasePanel(list, null, panelOptions(), this, (FLyrRasterSE) layer); |
111 |
previewBasePanel.setPreviewSize(new Dimension(230, 215)); |
112 |
previewBasePanel.addButtonPressedListener(filterDialog); |
113 |
} |
114 |
return previewBasePanel;
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* Devuelve el componente <code>FilterListener</code>, que contendr? el
|
119 |
* proceso en si del panel
|
120 |
*/
|
121 |
private FilterListener getFilterListener() {
|
122 |
if (filterListener == null) { |
123 |
filterListener = new FilterListener(this); |
124 |
} |
125 |
|
126 |
return filterListener;
|
127 |
} |
128 |
|
129 |
/**
|
130 |
* Devuelve el panel de Opciones, en caso de no existir, lo crea.
|
131 |
* @return
|
132 |
*/
|
133 |
private JPanel panelOptions() { |
134 |
if (jPanelOptions == null) { |
135 |
jPanelOptions = new JPanel(); |
136 |
|
137 |
GridBagConstraints gridBagConstraints;
|
138 |
|
139 |
jPanelOptions.setLayout(new GridBagLayout()); |
140 |
|
141 |
gridBagConstraints = new GridBagConstraints(); |
142 |
gridBagConstraints.gridx = 0;
|
143 |
gridBagConstraints.gridy = 1;
|
144 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
145 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
146 |
jPanelOptions.add(getCBShowFilters(), gridBagConstraints); |
147 |
|
148 |
gridBagConstraints = new GridBagConstraints(); |
149 |
gridBagConstraints.gridx = 0;
|
150 |
gridBagConstraints.gridy = 4;
|
151 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
152 |
gridBagConstraints.insets = new Insets(3, 3, 3, 3); |
153 |
jPanelOptions.add(getNewLayerPanel(), gridBagConstraints); |
154 |
|
155 |
gridBagConstraints = new GridBagConstraints(); |
156 |
gridBagConstraints.gridx = 0;
|
157 |
gridBagConstraints.gridy = 5;
|
158 |
gridBagConstraints.weightx = 1.0;
|
159 |
gridBagConstraints.weighty = 1.0;
|
160 |
jPanelOptions.add(new JPanel(), gridBagConstraints); |
161 |
} |
162 |
|
163 |
return jPanelOptions;
|
164 |
} |
165 |
|
166 |
public NewOrSaveLayerPanel getNewLayerPanel() {
|
167 |
if (newLayerPanel == null) { |
168 |
newLayerPanel = new NewOrSaveLayerPanel();
|
169 |
} |
170 |
return newLayerPanel;
|
171 |
} |
172 |
|
173 |
/**
|
174 |
* Construye el arbol para el men? de filtros disponibles
|
175 |
*/
|
176 |
private void menuBuild() { |
177 |
Hashtable keys = new Hashtable(); |
178 |
RasterFilterList filterList = ((FLyrRasterSE) layer).getRenderFilterList(); |
179 |
// Creamos un stackManager para recorrer los filtros registrados en gvSIG
|
180 |
RasterFilterListManager stackManager = new RasterFilterListManager(filterList);
|
181 |
|
182 |
int count = 0; |
183 |
RasterFilter obj = null;
|
184 |
|
185 |
for (int i = 0; i < stackManager.getRasterFilterList().size(); i++) { |
186 |
Class classFilter = (Class) stackManager.getRasterFilterList().get(i); |
187 |
|
188 |
try {
|
189 |
obj = (RasterFilter) classFilter.newInstance(); |
190 |
|
191 |
initFilter(obj); |
192 |
|
193 |
if (!obj.isVisible())
|
194 |
continue;
|
195 |
|
196 |
// Crear grupos de los filtros
|
197 |
if (!keys.containsKey(PluginServices.getText(this, new String(obj.getGroup())))) { |
198 |
keys.put(PluginServices.getText(this, new String(obj.getGroup())), obj); |
199 |
getMainPanel().getTreeListContainer().addClass(PluginServices.getText(this, new String(obj.getGroup())), count); |
200 |
count++; |
201 |
|
202 |
} |
203 |
// Crear cada entrada de los filtro
|
204 |
String[] names = obj.getNames(); |
205 |
for (int j = 0; j < names.length; j++) { |
206 |
obj.setName(names[j]); |
207 |
getFilterListener().addNewParam(names[j], initFilterParam(obj.getUIParams(names[j])), classFilter); |
208 |
getMainPanel().getTreeListContainer().addEntry(PluginServices.getText(this, names[j]), PluginServices.getText(this, obj.getGroup()), names[j]); |
209 |
} |
210 |
} catch (InstantiationException e) { |
211 |
RasterToolsUtil.debug("No se ha podido meter el filtro en la lista", this, e); |
212 |
} catch (IllegalAccessException e) { |
213 |
RasterToolsUtil.debug("No se ha podido meter el filtro en la lista", this, e); |
214 |
} |
215 |
} |
216 |
|
217 |
getMainPanel().getTreeListContainer().getTree().expandRow(0);
|
218 |
} |
219 |
|
220 |
/**
|
221 |
* Pasamos los parametros basicos a un filtro
|
222 |
* @param filter
|
223 |
*/
|
224 |
private void initFilter(RasterFilter filter) { |
225 |
if (layer != null) { |
226 |
filter.getEnv().put("MultiRasterDataset", ((FLyrRasterSE) layer).getDataSource());
|
227 |
filter.getEnv().put("initRaster", layer);
|
228 |
} |
229 |
} |
230 |
|
231 |
/**
|
232 |
* Sirve para a?adir mas parametros genericos por defecto al panel, de momento
|
233 |
* solo he puesto para activar o desactivar un filtro.
|
234 |
* @param params
|
235 |
* @return
|
236 |
*/
|
237 |
private Params initFilterParam(Params params) {
|
238 |
params.setParam("enabled", new Boolean(true), Params.CHECK, null); |
239 |
Param param = params.getParamById("enabled");
|
240 |
params.getParams().remove(params.getParams().size() - 1);
|
241 |
params.getParams().add(0, param);
|
242 |
return params;
|
243 |
} |
244 |
|
245 |
/**
|
246 |
* Comprueba que el nombre del filtro esta cargado en las extensiones
|
247 |
* @param filter
|
248 |
* @return
|
249 |
*/
|
250 |
private boolean hasThisFilter(String filter) { |
251 |
RasterFilterList filterList = new RasterFilterList();
|
252 |
RasterFilterListManager stackManager = new RasterFilterListManager(filterList);
|
253 |
|
254 |
boolean error;
|
255 |
RasterFilter obj = null;
|
256 |
|
257 |
for (int i = 0; i < stackManager.getRasterFilterList().size(); i++) { |
258 |
Class classFilter = (Class) stackManager.getRasterFilterList().get(i); |
259 |
error = true;
|
260 |
|
261 |
try {
|
262 |
obj = (RasterFilter) classFilter.newInstance(); |
263 |
error = false;
|
264 |
} catch (InstantiationException e) { |
265 |
} catch (IllegalAccessException e) { |
266 |
} |
267 |
|
268 |
if (!error) {
|
269 |
String[] names = obj.getNames(); |
270 |
for (int j = 0; j < names.length; j++) |
271 |
if (filter.equals(names[j]))
|
272 |
return true; |
273 |
} |
274 |
} |
275 |
return false; |
276 |
} |
277 |
|
278 |
/**
|
279 |
* Definir el FLayer del panel, haciendo todas las cargas necesarias despues
|
280 |
* de especificarlo.
|
281 |
* @param layer
|
282 |
*/
|
283 |
private void setLayer(FLayer layer) { |
284 |
if (layer == null) |
285 |
return;
|
286 |
|
287 |
this.layer = layer;
|
288 |
getPreviewBasePanel().setLayer((FLyrRasterSE) layer); |
289 |
|
290 |
// Construimos el arbol de filtros
|
291 |
menuBuild(); |
292 |
|
293 |
View view = (View) PluginServices.getMDIManager().getActiveWindow(); |
294 |
viewName = PluginServices.getMDIManager().getWindowInfo(view).getTitle(); |
295 |
|
296 |
//Comprobamos que el raster de salida no exceda los 4GB que es el m?ximo
|
297 |
//admisible por un TIFF. Si es as? se hace un setCompress para salvar en JPEG2000
|
298 |
long sizeB = (long)((((FLyrRasterSE) layer).getPxWidth() * ((FLyrRasterSE) layer).getPxWidth() * ((FLyrRasterSE) layer).getBandCount())); |
299 |
int sizeMB = (int)(sizeB / 1048576); |
300 |
if(sizeMB >= 4096) { |
301 |
RasterToolsUtil.messageBoxInfo("file_too_big", this); |
302 |
getNewLayerPanel().setCompress(true);
|
303 |
} |
304 |
|
305 |
RasterFilterList rfl = ((FLyrRasterSE) layer).getRenderFilterList(); |
306 |
filterStatus = rfl.getStatusCloned(); |
307 |
|
308 |
//Carga el listado de filtros que ya estaban aplicados en la capa al abrir
|
309 |
|
310 |
int i = 0; |
311 |
boolean filters = false; |
312 |
while (rfl.get(i) != null) { |
313 |
DefaultListModel list = (DefaultListModel) getMainPanel().getTreeListContainer().getListModel(); |
314 |
if (rfl.get(i).isVisible() && hasThisFilter(rfl.get(i).getName())) {
|
315 |
list.addElement(PluginServices.getText(this, rfl.get(i).getName()));
|
316 |
for (int j = 0; j < getFilterListener().getParamsList().size(); j++) { |
317 |
if (((ParamStruct) getFilterListener().getParamsList().get(j)).getFilterName().equals(rfl.get(i).getName())) {
|
318 |
filters = true;
|
319 |
initFilter(rfl.get(i)); |
320 |
((ParamStruct) getFilterListener().getParamsList().get(j)).setFilterParam(initFilterParam(rfl.get(i).getUIParams(rfl.get(i).getName()))); |
321 |
} |
322 |
} |
323 |
} |
324 |
i++; |
325 |
} |
326 |
|
327 |
// Si existen filtros ya en la capa, pondremos los RadioButton para que
|
328 |
// los cambios se hagan sobre la visualizaci?n
|
329 |
if (filters)
|
330 |
getNewLayerPanel().setOnlyView(true);
|
331 |
|
332 |
// Selecciona el primer item del arbol
|
333 |
TreeListContainer lc = getMainPanel().getTreeListContainer(); |
334 |
lc.getTree().expandRow(1);
|
335 |
lc.getTree().setSelectionInterval(2, 2); |
336 |
} |
337 |
|
338 |
public FilterMainPanel getMainPanel() {
|
339 |
if (filterMain == null) { |
340 |
filterMain = new FilterMainPanel(getFilterListener());
|
341 |
JPanel panel = getNewLayerPanel().getFileNamePanel();
|
342 |
panel.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "nombre_capa"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); |
343 |
filterMain.getCentralPanel().add(panel, BorderLayout.SOUTH);
|
344 |
} |
345 |
return filterMain;
|
346 |
} |
347 |
|
348 |
/**
|
349 |
* Volvemos todo a la normalidad cuando se cancela
|
350 |
*/
|
351 |
public void cancel() { |
352 |
if (layer != null) |
353 |
layer.getMapContext().invalidate(); |
354 |
} |
355 |
|
356 |
/**
|
357 |
* Cuando se aceptan los cambios en el panel ejecutaremos el aceptar del
|
358 |
* listener
|
359 |
*/
|
360 |
public void accept() { |
361 |
filterListener.accept(); |
362 |
} |
363 |
|
364 |
/**
|
365 |
* Volvemos todo a la normalidad cuando se cancela
|
366 |
*/
|
367 |
public void restoreFilters() { |
368 |
Rendering rendering = ((FLyrRasterSE) layer).getRender(); |
369 |
rendering.getFilterList().setStatus(getFilterStatus()); |
370 |
} |
371 |
|
372 |
/**
|
373 |
* Obtener el PropertiesComponent del panel de filtros, en caso de no existir,
|
374 |
* lo crea.
|
375 |
* @return
|
376 |
*/
|
377 |
public PropertiesComponent getPropertiesComponent() {
|
378 |
if (propertiesComponent == null) { |
379 |
propertiesComponent = new PropertiesComponent();
|
380 |
getMainPanel().getCentralPanel().add(propertiesComponent, BorderLayout.CENTER);
|
381 |
|
382 |
propertiesComponent.addStateChangedListener(getFilterListener()); |
383 |
} |
384 |
return propertiesComponent;
|
385 |
} |
386 |
|
387 |
/**
|
388 |
* Asignar un nuevo componente de PropertiesComponent, eliminando el anterior
|
389 |
* que hubiera.
|
390 |
* @param component
|
391 |
* @param name
|
392 |
*/
|
393 |
public void setNewPropertiesComponent(PropertiesComponent component, String name) { |
394 |
getPropertiesComponent().setVisible(false);
|
395 |
this.remove(propertiesComponent);
|
396 |
propertiesComponent = null;
|
397 |
propertiesComponent = component; |
398 |
getMainPanel().getCentralPanel().add(propertiesComponent, BorderLayout.CENTER);
|
399 |
propertiesComponent.addStateChangedListener(getFilterListener()); |
400 |
setTitle(name); |
401 |
this.validate();
|
402 |
} |
403 |
|
404 |
|
405 |
/**
|
406 |
* Asigna el t?tulo al panel
|
407 |
* @param title T?tulo del panel
|
408 |
*/
|
409 |
public void setTitle(String title) { |
410 |
getPropertiesComponent().setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "filtro_de") + " " + PluginServices.getText(this, title), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
411 |
} |
412 |
|
413 |
/**
|
414 |
* Devuelve el arrayList de filtros inicial
|
415 |
* @return
|
416 |
*/
|
417 |
public ArrayList getFilterStatus() { |
418 |
return filterStatus;
|
419 |
} |
420 |
|
421 |
/**
|
422 |
* Actualizamos la vista previa
|
423 |
*/
|
424 |
public void refreshPreview() { |
425 |
getPreviewBasePanel().refreshPreview(); |
426 |
} |
427 |
|
428 |
/**
|
429 |
* Devuelve el FLayer asignado al panel
|
430 |
* @return
|
431 |
*/
|
432 |
public FLayer getLayer() {
|
433 |
return layer;
|
434 |
} |
435 |
|
436 |
|
437 |
/**
|
438 |
* @return the jLabelShowFilters
|
439 |
*/
|
440 |
public JCheckBox getCBShowFilters() { |
441 |
if (jCBShowFilters == null) { |
442 |
jCBShowFilters = new JCheckBox(); |
443 |
jCBShowFilters.addActionListener(getFilterListener()); |
444 |
jCBShowFilters.setSelected(true);
|
445 |
} |
446 |
return jCBShowFilters;
|
447 |
} |
448 |
|
449 |
/**
|
450 |
* Obtiene el nombre de la vista
|
451 |
* @return
|
452 |
*/
|
453 |
public String getViewName() { |
454 |
return viewName;
|
455 |
} |
456 |
|
457 |
/**
|
458 |
* Especificar el nombre de la nueva capa para el recuadro de texto asign?ndo
|
459 |
* en cada llamada un nombre consecutivo.
|
460 |
*/
|
461 |
public void updateNewLayerText() { |
462 |
getNewLayerPanel().updateNewLayerText(); |
463 |
} |
464 |
|
465 |
/*
|
466 |
* (non-Javadoc)
|
467 |
* @see org.gvsig.raster.beans.previewbase.IPreviewRenderProcess#process(org.gvsig.raster.hierarchy.IRasterRendering)
|
468 |
*/
|
469 |
public void process(IRasterRendering rendering) throws FilterTypeException { |
470 |
getFilterListener().drawImage(rendering); |
471 |
} |
472 |
} |