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