Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / filter / ui / FilterDialog.java @ 21641

History | View | Annotate | Download (4.26 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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

    
23
import javax.swing.JPanel;
24

    
25
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
26
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
27
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
28
import org.gvsig.raster.RasterLibrary;
29

    
30
import com.iver.andami.PluginServices;
31
import com.iver.andami.ui.mdiManager.IWindow;
32
import com.iver.andami.ui.mdiManager.IWindowListener;
33
import com.iver.andami.ui.mdiManager.WindowInfo;
34
import com.iver.cit.gvsig.fmap.layers.FLayer;
35
/**
36
 * Dialogo para los filtros de raster.
37
 * 
38
 * @version 25/02/2008
39
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
40
 */
41
public class FilterDialog extends JPanel implements IWindow, IWindowListener, ButtonsPanelListener {
42
        private static final long serialVersionUID = 818691082984915388L;
43
        private FLayer      layer       = null;
44
        private FilterPanel filterPanel = null;
45

    
46
        /**
47
         * Controla si se ha presionado el boton aceptar para el cerrado de la ventana
48
         */
49
        private boolean     accepted    = false;
50

    
51
        /**
52
         * Constructor
53
         * @param width Ancho
54
         * @param height Alto
55
         */
56
        public FilterDialog(FLayer layer, int width, int height) {
57
                this.layer = layer;
58
                setSize(width, height);
59
                setLayout(new BorderLayout(5, 5));
60
                add(getFilterPanel(), java.awt.BorderLayout.CENTER);
61
        }
62
        
63
        /**
64
         * Obtiene el panel con el histograma
65
         * @return HistogramPanel
66
         */
67
        private FilterPanel getFilterPanel() {
68
                if (filterPanel == null) {
69
                        filterPanel = new FilterPanel(layer, this);
70
                }
71
                return filterPanel;
72
        }
73
        
74
        /**
75
         * Acciones a ejecutar cuando se cancela
76
         */
77
        private void close() {
78
                try {
79
                        RasterLibrary.removeOnlyLayerNameListener(getFilterPanel().getNewLayerPanel());
80
                        PluginServices.getMDIManager().closeWindow(this);
81
                } catch (ArrayIndexOutOfBoundsException e) {
82
                        //Si la ventana no se puede eliminar no hacemos nada
83
                }
84
        }
85
        
86
        /*
87
         * (non-Javadoc)
88
         * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
89
         */
90
        public WindowInfo getWindowInfo() {
91
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
92
                if (layer != null)
93
                        m_viewinfo.setAdditionalInfo(layer.getName());
94
                m_viewinfo.setTitle(PluginServices.getText(this, "filtros"));
95
                m_viewinfo.setHeight(this.getHeight());
96
                m_viewinfo.setWidth(this.getWidth());
97
                return m_viewinfo;
98
        }
99

    
100
        /*
101
         * (non-Javadoc)
102
         * @see com.iver.andami.ui.mdiManager.IWindowListener#windowClosed()
103
         */
104
        public void windowClosed() {
105
                if (!accepted) {
106
                        getFilterPanel().restoreFilters();
107
                        getFilterPanel().cancel();
108
                }
109
        }
110
        
111
        /*
112
         * (non-Javadoc)
113
         * @see org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener#actionButtonPressed(org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent)
114
         */
115
        public void actionButtonPressed(ButtonsPanelEvent e) {
116
                // Restauramos la vista con los filtros originales antes de cualquier acci?n
117
                getFilterPanel().restoreFilters();
118
        
119
                // Al pulsar Aceptar o Aplicar se ejecuta el aceptar del panel
120
                if (e.getButton() == ButtonsPanel.BUTTON_APPLY || e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
121
                        getFilterPanel().accept();
122
                }
123
        
124
                // Al pulsar Cancelar la ventana se cierra y se refresca la vista
125
                if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
126
                        getFilterPanel().cancel();
127
                        close();
128
                }
129
        
130
                // Al pulsar Aceptar simplemente la ventana se cierra
131
                if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
132
                        accepted = true;
133
                        close();
134
                }
135
        }
136
        
137
        public void windowActivated() {}
138
}