Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / reproject / ui / LayerReprojectPanel.java @ 21913

History | View | Annotate | Download (9.78 KB)

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

    
21
import java.awt.BorderLayout;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.Insets;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27

    
28
import javax.swing.BorderFactory;
29
import javax.swing.JLabel;
30
import javax.swing.JPanel;
31

    
32
import org.cresques.cts.IProjection;
33
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
34
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
35
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
36
import org.gvsig.raster.beans.createlayer.NewLayerPanel;
37
import org.gvsig.raster.util.RasterToolsUtil;
38

    
39
import com.iver.andami.PluginServices;
40
import com.iver.andami.ui.mdiManager.IWindow;
41
import com.iver.andami.ui.mdiManager.WindowInfo;
42
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
43
import com.iver.cit.gvsig.gui.panels.CRSSelectPanel;
44
import com.iver.cit.gvsig.project.documents.view.gui.View;
45
/**
46
 * Panel para la reproyecci?n de capas cargadas.
47
 * 
48
 * 28/04/2008
49
 * @author Nacho Brodin nachobrodin@gmail.com
50
 */
51
public class LayerReprojectPanel extends DefaultButtonsPanel implements IWindow {
52
        private static final long serialVersionUID = -1011688195806336071L;
53
        private NewLayerPanel          newLayerPanel         = null;
54
        private JPanel                 nameFile              = null;
55
        private CRSSelectPanel         projectionSrcSelector = null;
56
        private CRSSelectPanel         projectionDstSelector = null;
57
        private IProjection            projSrc               = null;
58
        private IProjection            projDst               = null;
59
        private JPanel                 filePanel             = null;
60
        private LayerReprojectListener reprojectListener     = null;
61
        private FLyrRasterSE           lyr                   = null;
62
        private String                 viewName              = null;
63
        private Boolean                closeSrc              = Boolean.FALSE;
64

    
65
        /**
66
         * Constructor
67
         */
68
        public LayerReprojectPanel(FLyrRasterSE lyr, Boolean closeSrc) {
69
                super(ButtonsPanel.BUTTONS_ACCEPTCANCEL);
70
                this.closeSrc = closeSrc;
71
                setLayer(lyr);
72
                init();
73
                projSrc = getProjectionSrcSelector().getCurProj();
74
                projDst = getProjectionDstSelector().getCurProj();
75
        }
76
        
77
        /*
78
         * (non-Javadoc)
79
         * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
80
         */
81
        public WindowInfo getWindowInfo() {
82
                WindowInfo windowInfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
83
                windowInfo.setTitle(PluginServices.getText(this, "capa_a_reproyectar"));
84
                windowInfo.setWidth(320);
85
                windowInfo.setHeight(320);
86
                return windowInfo;
87
        }
88
        
89
        private void setLayer(FLyrRasterSE lyr) {
90
                this.lyr = lyr;
91

    
92
                if (this.lyr == null)
93
                        return;
94

    
95
                
96
                View view = (View) PluginServices.getMDIManager().getActiveWindow();
97
                viewName = PluginServices.getMDIManager().getWindowInfo(view).getTitle();
98
                
99
                projSrc = this.lyr.readProjection();
100
                if (projSrc == null)
101
                        projSrc = CRSFactory.getCRS("EPSG:23030");
102

    
103
                projDst = CRSFactory.getCRS("EPSG:23030");
104

    
105
                getLayerReprojectListener().setCloseSrc(closeSrc);
106
                getLayerReprojectListener().setLayer(this.lyr);
107
        }
108
        
109
        private LayerReprojectListener getLayerReprojectListener() {
110
                if (reprojectListener == null) {
111
                        reprojectListener = new LayerReprojectListener(this);
112
                        addButtonPressedListener(reprojectListener);
113
                }
114
                return reprojectListener;
115
        }
116
        
117
        /**
118
         * Inicializaci?n de los componentes gr?ficos.
119
         */
120
        private void init() {
121
                GridBagConstraints gridBagConstraints;
122

    
123
                setLayout(new GridBagLayout());
124
                
125
                int posy = 0;
126
                
127
                gridBagConstraints = new GridBagConstraints();
128
                gridBagConstraints.fill = GridBagConstraints.BOTH;
129
                gridBagConstraints.gridx = 0;
130
                gridBagConstraints.gridy = posy;
131
                gridBagConstraints.weightx = 1.0;
132
                gridBagConstraints.insets = new Insets(5, 5, 2, 5);
133
                JPanel panelFile = new JPanel();
134
                panelFile.setLayout(new BorderLayout());
135
                panelFile.setBorder(BorderFactory.createTitledBorder(RasterToolsUtil.getText(this, "origen")));
136
                JLabel label = new JLabel("<html><b>" + lyr.getName() + "</b></html>");
137
                panelFile.add(label, BorderLayout.CENTER);
138
                add(panelFile, gridBagConstraints);
139
                
140
                posy++;
141
                gridBagConstraints = new GridBagConstraints();
142
                gridBagConstraints.fill = GridBagConstraints.BOTH;
143
                gridBagConstraints.gridx = 0;
144
                gridBagConstraints.gridy = posy;
145
                gridBagConstraints.weightx = 1.0;
146
                gridBagConstraints.insets = new Insets(2, 5, 2, 5);
147
                add(getProjectionSrcSelector(), gridBagConstraints);
148

    
149
                posy++;
150
                gridBagConstraints = new GridBagConstraints();
151
                gridBagConstraints.fill = GridBagConstraints.BOTH;
152
                gridBagConstraints.gridx = 0;
153
                gridBagConstraints.gridy = posy;
154
                gridBagConstraints.weightx = 1.0;
155
                gridBagConstraints.insets = new Insets(2, 5, 2, 5);
156
                add(getProjectionDstSelector(), gridBagConstraints);
157
                
158
                posy++;
159
                gridBagConstraints = new GridBagConstraints();
160
                gridBagConstraints.gridx = 0;
161
                gridBagConstraints.gridy = posy;
162
                gridBagConstraints.fill = GridBagConstraints.BOTH;
163
                gridBagConstraints.insets = new Insets(2, 5, 2, 5);
164
                add(getNewLayerPanel().getJPanel(), gridBagConstraints);
165
                
166
                posy++;
167
                gridBagConstraints = new GridBagConstraints();
168
                gridBagConstraints.gridx = 0;
169
                gridBagConstraints.gridy = posy;
170
                gridBagConstraints.fill = GridBagConstraints.BOTH;
171
                gridBagConstraints.insets = new Insets(2, 5, 0, 5);
172
                add(getFilePanel(), gridBagConstraints);
173

    
174
                // Insertamos un panel vacio
175
                posy++;
176
                gridBagConstraints = new GridBagConstraints();
177
                gridBagConstraints.gridx = 0;
178
                gridBagConstraints.gridy = posy;
179
                gridBagConstraints.weighty = 1.0;
180
                gridBagConstraints.insets = new Insets(0, 0, 0, 0);
181
                JPanel emptyPanel = new JPanel();
182
                add(emptyPanel, gridBagConstraints);
183
        }
184
        
185
        /**
186
         * Obtiene el panel de destino de fichero y nombre de capa
187
         * @return JPanel
188
         */
189
        private JPanel getFilePanel() {
190
                if (filePanel == null) {
191
                        filePanel = new JPanel();
192
                        filePanel.setBorder(BorderFactory.createTitledBorder(RasterToolsUtil.getText(this, "dest_file")));
193
                        filePanel.setLayout(new GridBagLayout());
194

    
195
                        GridBagConstraints gbc = new GridBagConstraints();
196
                        gbc.gridx = 0;
197
                        gbc.gridy = 0;
198
                        gbc.weightx = 1D;
199
                        gbc.fill = GridBagConstraints.HORIZONTAL;
200
                        gbc.anchor = GridBagConstraints.WEST;
201
                        gbc.insets = new Insets(0, 0, 0, 5);
202
                        filePanel.add(getNameFilePanel(), gbc);
203
                }
204
                return filePanel;
205
        }
206

    
207
        /**
208
         * Obtiene el desplegable con la lista de capas
209
         * @return JComboBox
210
         */
211
        protected NewLayerPanel getNewLayerPanel() {
212
                if (newLayerPanel == null) {
213
                        newLayerPanel = new NewLayerPanel();
214
                        newLayerPanel.getJPanel().setBorder(BorderFactory.createTitledBorder(RasterToolsUtil.getText(this, "capa")));
215
                }
216
                return newLayerPanel;
217
        }
218
        
219
        /**
220
         * Obtiene el nombre de la vista
221
         * @return
222
         */
223
        public String getViewName() {
224
                return viewName;
225
        }
226
        
227
        /**
228
         * Obtiene el desplegable con la lista de capas
229
         * @return JComboBox
230
         */
231
        private JPanel getNameFilePanel() {
232
                if(nameFile == null) {
233
                        nameFile = getNewLayerPanel().getFileNamePanel();
234
                }
235
                return nameFile;
236
        }
237

    
238
        /**
239
         * Obtiene el bot?n que lanza el panel de selecci?n de proyecciones.
240
         * @return
241
         */
242
        private CRSSelectPanel getProjectionSrcSelector() {
243
                if (projectionSrcSelector == null) {
244
                        
245
                        IProjection projectionAux = null;
246
                        IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow();
247
                        if (activeWindow instanceof View) {                
248
                                View activeView = (com.iver.cit.gvsig.project.documents.view.gui.View) activeWindow;
249
                                projectionAux = activeView.getProjection();
250
                                activeView.setProjection(projSrc);
251
                        }
252
                        
253
                        projectionSrcSelector = CRSSelectPanel.getPanel(projSrc);
254
                        
255
                        if (activeWindow instanceof View) {                
256
                                View activeView = (com.iver.cit.gvsig.project.documents.view.gui.View) activeWindow;
257
                                activeView.setProjection(projectionAux);
258
                        }
259
                        
260
                        projectionSrcSelector.setTransPanelActive(true);
261
                        projectionSrcSelector.setPreferredSize(null);
262
                        projectionSrcSelector.addActionListener(new ActionListener() {
263
                                public void actionPerformed(ActionEvent e) {
264
                                        if (projectionSrcSelector.isOkPressed()) {
265
                                                projSrc = projectionSrcSelector.getCurProj();
266
                                        }
267
                                }
268
                        });
269
                        projectionSrcSelector.setBorder(BorderFactory.createTitledBorder(RasterToolsUtil.getText(this, "src_proj")));
270
                }
271
                return projectionSrcSelector;
272
        }
273
        
274
        /**
275
         * Obtiene el bot?n que lanza el panel de selecci?n de proyecciones.
276
         * @return
277
         */
278
        private CRSSelectPanel getProjectionDstSelector() {
279
                if (projectionDstSelector == null) {
280
                        projectionDstSelector = CRSSelectPanel.getPanel(projDst);
281
                        projectionDstSelector.setTransPanelActive(true);
282
                        projectionDstSelector.setPreferredSize(null);
283
                        projectionDstSelector.addActionListener(new ActionListener() {
284
                                public void actionPerformed(ActionEvent e) {
285
                                        if (projectionDstSelector.isOkPressed()) {
286
                                                projDst = projectionDstSelector.getCurProj();
287
                                        }
288
                                }
289
                        });
290
                        projectionDstSelector.setBorder(BorderFactory.createTitledBorder(RasterToolsUtil.getText(this, "dest_proj")));
291
                }
292
                return projectionDstSelector;
293
        }
294

    
295
        /**
296
         * @return the projSrc
297
         */
298
        public IProjection getProjectionSrc() {
299
                return projSrc;
300
        }
301

    
302
        /**
303
         * @return the projDst
304
         */
305
        public IProjection getProjectionDst() {
306
                return projDst;
307
        }
308
}