Statistics
| Revision:

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

History | View | Annotate | Download (8.18 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.GridBagConstraints;
22
import java.awt.GridBagLayout;
23
import java.awt.Insets;
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
26

    
27
import javax.swing.BorderFactory;
28
import javax.swing.JPanel;
29

    
30
import org.cresques.cts.IProjection;
31
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
32
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
33
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
34
import org.gvsig.raster.beans.createlayer.NewLayerPanel;
35

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

    
61
        /**
62
         * Constructor
63
         */
64
        public LayerReprojectPanel(FLyrRasterSE lyr) {
65
                super(ButtonsPanel.BUTTONS_ACCEPTCANCEL);
66
                setLayer(lyr);
67
                init();
68
        }
69
        
70
        /*
71
         * (non-Javadoc)
72
         * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
73
         */
74
        public WindowInfo getWindowInfo() {
75
                WindowInfo windowInfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
76
                windowInfo.setTitle(PluginServices.getText(this, "capa_a_reproyectar"));
77
                windowInfo.setWidth(320);
78
                windowInfo.setHeight(280);
79
                return windowInfo;
80
        }
81
        
82
        private void setLayer(FLyrRasterSE lyr) {
83
                this.lyr = lyr;
84

    
85
                if (this.lyr == null)
86
                        return;
87

    
88
                
89
                View view = (View) PluginServices.getMDIManager().getActiveWindow();
90
                viewName = PluginServices.getMDIManager().getWindowInfo(view).getTitle();
91
                
92
                projSrc = this.lyr.readProjection();
93
                if (projSrc == null)
94
                        projSrc = CRSFactory.getCRS("EPSG:23030");
95

    
96
                projDst = CRSFactory.getCRS("EPSG:23030");
97

    
98
                getLayerReprojectListener().setLayer(this.lyr);
99
        }
100
        
101
        private LayerReprojectListener getLayerReprojectListener() {
102
                if (reprojectListener == null) {
103
                        reprojectListener = new LayerReprojectListener(this);
104
                        addButtonPressedListener(reprojectListener);
105
                }
106
                return reprojectListener;
107
        }
108
        
109
        /**
110
         * Inicializaci?n de los componentes gr?ficos.
111
         */
112
        private void init() {
113
                GridBagConstraints gridBagConstraints;
114

    
115
                setLayout(new GridBagLayout());
116
                
117
                int posy = 0;
118
                gridBagConstraints = new GridBagConstraints();
119
                gridBagConstraints.fill = GridBagConstraints.BOTH;
120
                gridBagConstraints.gridx = 0;
121
                gridBagConstraints.gridy = posy;
122
                gridBagConstraints.weightx = 1.0;
123
                gridBagConstraints.insets = new Insets(5, 5, 2, 5);
124
                add(getProjectionSrcSelector(), gridBagConstraints);
125

    
126
                posy++;
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(2, 5, 2, 5);
133
                add(getProjectionDstSelector(), gridBagConstraints);
134
                
135
                posy++;
136
                gridBagConstraints = new GridBagConstraints();
137
                gridBagConstraints.gridx = 0;
138
                gridBagConstraints.gridy = posy;
139
                gridBagConstraints.fill = GridBagConstraints.BOTH;
140
                gridBagConstraints.insets = new Insets(2, 5, 2, 5);
141
                add(getNewLayerPanel().getJPanel(), gridBagConstraints);
142
                
143
                posy++;
144
                gridBagConstraints = new GridBagConstraints();
145
                gridBagConstraints.gridx = 0;
146
                gridBagConstraints.gridy = posy;
147
                gridBagConstraints.fill = GridBagConstraints.BOTH;
148
                gridBagConstraints.insets = new Insets(2, 5, 0, 5);
149
                add(getFilePanel(), gridBagConstraints);
150

    
151
                // Insertamos un panel vacio
152
                posy++;
153
                gridBagConstraints = new GridBagConstraints();
154
                gridBagConstraints.gridx = 0;
155
                gridBagConstraints.gridy = posy;
156
                gridBagConstraints.weighty = 1.0;
157
                gridBagConstraints.insets = new Insets(0, 0, 0, 0);
158
                JPanel emptyPanel = new JPanel();
159
                add(emptyPanel, gridBagConstraints);
160
        }
161
        
162
        /**
163
         * Obtiene el panel de destino de fichero y nombre de capa
164
         * @return JPanel
165
         */
166
        private JPanel getFilePanel() {
167
                if (filePanel == null) {
168
                        filePanel = new JPanel();
169
                        filePanel.setBorder(BorderFactory.createTitledBorder("dest_file"));
170
                        filePanel.setLayout(new GridBagLayout());
171

    
172
                        GridBagConstraints gbc = new GridBagConstraints();
173
                        gbc.gridx = 0;
174
                        gbc.gridy = 0;
175
                        gbc.weightx = 1D;
176
                        gbc.fill = GridBagConstraints.HORIZONTAL;
177
                        gbc.anchor = GridBagConstraints.WEST;
178
                        gbc.insets = new Insets(0, 0, 0, 5);
179
                        filePanel.add(getNameFilePanel(), gbc);
180
                }
181
                return filePanel;
182
        }
183

    
184
        /**
185
         * Obtiene el desplegable con la lista de capas
186
         * @return JComboBox
187
         */
188
        protected NewLayerPanel getNewLayerPanel() {
189
                if (newLayerPanel == null) {
190
                        newLayerPanel = new NewLayerPanel();
191
                        newLayerPanel.getJPanel().setBorder(BorderFactory.createTitledBorder("layer"));
192
                }
193
                return newLayerPanel;
194
        }
195
        
196
        /**
197
         * Obtiene el nombre de la vista
198
         * @return
199
         */
200
        public String getViewName() {
201
                return viewName;
202
        }
203
        
204
        /**
205
         * Obtiene el desplegable con la lista de capas
206
         * @return JComboBox
207
         */
208
        private JPanel getNameFilePanel() {
209
                if(nameFile == null) {
210
                        nameFile = getNewLayerPanel().getFileNamePanel();
211
                }
212
                return nameFile;
213
        }
214

    
215
        /**
216
         * Obtiene el bot?n que lanza el panel de selecci?n de proyecciones.
217
         * @return
218
         */
219
        private CRSSelectPanel getProjectionSrcSelector() {
220
                if (projectionSrcSelector == null) {
221
                        projectionSrcSelector = CRSSelectPanel.getPanel(projSrc);
222
                        projectionSrcSelector.setTransPanelActive(true);
223
                        projectionSrcSelector.setPreferredSize(null);
224
                        projectionSrcSelector.addActionListener(new ActionListener() {
225
                                public void actionPerformed(ActionEvent e) {
226
                                        if (projectionSrcSelector.isOkPressed()) {
227
                                                projSrc = projectionSrcSelector.getCurProj();
228
                                        }
229
                                }
230
                        });
231
                        projectionSrcSelector.setBorder(BorderFactory.createTitledBorder("src_proj"));
232
                }
233
                return projectionSrcSelector;
234
        }
235
        
236
        /**
237
         * Obtiene el bot?n que lanza el panel de selecci?n de proyecciones.
238
         * @return
239
         */
240
        private CRSSelectPanel getProjectionDstSelector() {
241
                if (projectionDstSelector == null) {
242
                        projectionDstSelector = CRSSelectPanel.getPanel(projDst);
243
                        projectionDstSelector.setTransPanelActive(true);
244
                        projectionDstSelector.setPreferredSize(null);
245
                        projectionDstSelector.addActionListener(new ActionListener() {
246
                                public void actionPerformed(ActionEvent e) {
247
                                        if (projectionDstSelector.isOkPressed()) {
248
                                                projDst = projectionDstSelector.getCurProj();
249
                                        }
250
                                }
251
                        });
252
                        projectionDstSelector.setBorder(BorderFactory.createTitledBorder("dest_proj"));
253
                }
254
                return projectionDstSelector;
255
        }
256

    
257
        /**
258
         * @return the projSrc
259
         */
260
        public IProjection getProjectionSrc() {
261
                return projSrc;
262
        }
263

    
264
        /**
265
         * @return the projDst
266
         */
267
        public IProjection getProjectionDst() {
268
                return projDst;
269
        }
270
}