Statistics
| Revision:

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

History | View | Annotate | Download (10.4 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.BaseView;
46
import com.iver.cit.gvsig.project.documents.view.gui.View;
47
/**
48
 * Panel para la reproyecci?n de capas cargadas.
49
 * 
50
 * 28/04/2008
51
 * @author Nacho Brodin nachobrodin@gmail.com
52
 */
53
public class LayerReprojectPanel extends DefaultButtonsPanel implements IWindow {
54
        private static final long serialVersionUID = -1011688195806336071L;
55
        private NewLayerPanel          newLayerPanel         = null;
56
        private JPanel                 nameFile              = null;
57
        private CRSSelectPanel         projectionSrcSelector = null;
58
        private CRSSelectPanel         projectionDstSelector = null;
59
        private IProjection            projSrc               = null;
60
        private IProjection            projDst               = null;
61
        private JPanel                 filePanel             = null;
62
        private LayerReprojectListener reprojectListener     = null;
63
        private FLyrRasterSE           lyr                   = null;
64
        private String                 viewName              = null;
65
        private Boolean                isInTOC               = Boolean.TRUE;
66

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

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

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

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

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

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

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

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

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

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

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

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

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

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