Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / reproject / ui / LayerReprojectPanel.java @ 24986

History | View | Annotate | Download (10.3 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.gui.util.StatusComponent;
37
import org.gvsig.raster.beans.createlayer.NewLayerPanel;
38
import org.gvsig.raster.util.RasterToolsUtil;
39

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

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

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

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

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

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

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

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

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

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

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

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

    
306
        /**
307
         * @return the projSrc
308
         */
309
        public IProjection getProjectionSrc() {
310
                return projSrc;
311
        }
312

    
313
        /**
314
         * @return the projDst
315
         */
316
        public IProjection getProjectionDst() {
317
                return projDst;
318
        }
319

    
320
        public Object getWindowProfile() {
321
                return WindowInfo.DIALOG_PROFILE;
322
        }
323
}