Statistics
| Revision:

gvsig-raster / org.gvsig.raster.reproject / branches / org.gvsig.raster.reproject_dataaccess_refactoring / org.gvsig.raster.reproject.algorithm / src / main / java / org / gvsig / raster / reproject / algorithm / swing / impl / RasterReprojectionPanelImpl.java @ 2367

History | View | Annotate | Download (11.1 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.reproject.algorithm.swing.impl;
23

    
24
import java.awt.BorderLayout;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.Insets;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.awt.event.KeyEvent;
31
import java.awt.event.KeyListener;
32
import java.util.List;
33

    
34
import javax.swing.BorderFactory;
35
import javax.swing.JComponent;
36
import javax.swing.JLabel;
37
import javax.swing.JPanel;
38

    
39
import org.gvsig.app.gui.panels.CRSSelectPanel;
40
import org.gvsig.app.gui.panels.CRSSelectPanelFactory;
41
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
42
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
43
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
44
import org.gvsig.i18n.Messages;
45
import org.gvsig.raster.reproject.algorithm.swing.api.RasterReprojectionPanel;
46
import org.gvsig.raster.reproject.algorithm.swing.api.ReprojectionPanelDataModel;
47
import org.gvsig.raster.swing.RasterSwingLocator;
48
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel;
49

    
50
/**
51
 * Panel para la reproyecci�n de capas cargadas.
52
 * 
53
 * @author Nacho Brodin (nachobrodin@gmail.com)
54
 */
55
public class RasterReprojectionPanelImpl extends DefaultButtonsPanel implements ActionListener, RasterReprojectionPanel, KeyListener {
56
        private static final long          serialVersionUID      = -1011688195806336071L;
57
        private CRSSelectPanel             projectionSrcSelector = null;
58
        private CRSSelectPanel             projectionDstSelector = null;
59
        private InterpolationPanel         interpolationPanel    = null;
60
        private OutputLayerOptionsPanel    layerOptions          = null;
61
        private CreateNewLayerPanel        newLayerPanel         = null;
62
        private ReprojectionPanelDataModel dataModel             = null;
63
        private JLabel                     layerName             = null;
64

    
65
        /**
66
         * Constructor
67
         * @throws RasterDriverException 
68
         */
69
        public RasterReprojectionPanelImpl(
70
                        ReprojectionPanelDataModel dataModel) {
71
                super(ButtonsPanel.BUTTONS_ACCEPTCANCEL);
72
                this.dataModel = dataModel;
73
                init();
74
                loadPanelFromDataModel();
75
                getInterpolationPanel().getComboInterpolationMethod().addActionListener(this);
76
                getInterpolationPanel().getRadioYes().addActionListener(this);
77
                getInterpolationPanel().getRadioNo().addActionListener(this);
78
        }
79
        
80
        private void loadPanelFromDataModel() {
81
                getLayerOptionsPanel().getTextFieldCellSize().setText(dataModel.getCellSize() + "");
82
                getLayerOptionsPanel().getTextFieldSizeX().setText(dataModel.getSize()[0] + "");
83
                getLayerOptionsPanel().getTextFieldSizeY().setText(dataModel.getSize()[1] + "");
84
                getLayerName().setText("<html><b>" + dataModel.getLayerName() + "</b></html>");
85
                List<String> list = dataModel.getInterpolationMethodList();
86
                for (int i = 0; i < list.size(); i++) {
87
                        getInterpolationPanel().getComboInterpolationMethod().addItem(list.get(i));        
88
                }
89
                
90
                if(dataModel.getInterpolationMethodSelected() < 0) {
91
                        getInterpolationPanel().getRadioYes().setSelected(false);
92
                        getInterpolationPanel().getRadioNo().setSelected(true);
93
                } else {
94
                        getInterpolationPanel().getRadioYes().setSelected(true);
95
                        getInterpolationPanel().getRadioNo().setSelected(false);
96
                        getInterpolationPanel().getComboInterpolationMethod().setEnabled(true);
97
                }
98
        }
99
        
100
        /**
101
         * Inicializaci�n de los componentes gr�ficos.
102
         * @throws RasterDriverException 
103
         */
104
        private void init() {
105
                GridBagConstraints gridBagConstraints;
106

    
107
                setLayout(new GridBagLayout());
108
                
109
                int posy = 0;
110
                
111
                gridBagConstraints = new GridBagConstraints();
112
                gridBagConstraints.fill = GridBagConstraints.BOTH;
113
                gridBagConstraints.gridx = 0;
114
                gridBagConstraints.gridy = posy;
115
                gridBagConstraints.weightx = 1.0;
116
                gridBagConstraints.insets = new Insets(2, 2, 2, 2);
117
                JPanel panelFile = new JPanel();
118
                panelFile.setLayout(new BorderLayout());
119
                panelFile.setBorder(BorderFactory.createTitledBorder(Messages.getText("origen")));
120
                panelFile.add(getLayerName(), BorderLayout.CENTER);
121
                add(panelFile, gridBagConstraints);
122
                
123
                posy++;
124
                gridBagConstraints = new GridBagConstraints();
125
                gridBagConstraints.fill = GridBagConstraints.BOTH;
126
                gridBagConstraints.gridx = 0;
127
                gridBagConstraints.gridy = posy;
128
                gridBagConstraints.weightx = 1.0;
129
                gridBagConstraints.insets = new Insets(2, 2, 2, 2);
130
                add(getProjectionSrcSelector(), gridBagConstraints);
131

    
132
                posy++;
133
                gridBagConstraints = new GridBagConstraints();
134
                gridBagConstraints.fill = GridBagConstraints.BOTH;
135
                gridBagConstraints.gridx = 0;
136
                gridBagConstraints.gridy = posy;
137
                gridBagConstraints.weightx = 1.0;
138
                gridBagConstraints.insets = new Insets(2, 2, 2, 2);
139
                add(getProjectionDstSelector(), 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, 2, 2, 2);
148
                add(getInterpolationPanel(), 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, 2, 2, 2);
157
                add(getLayerOptionsPanel(), gridBagConstraints);
158
                
159
                posy++;
160
                gridBagConstraints = new GridBagConstraints();
161
                gridBagConstraints.fill = GridBagConstraints.BOTH;
162
                gridBagConstraints.gridx = 0;
163
                gridBagConstraints.gridy = posy;
164
                gridBagConstraints.weightx = 1.0;
165
                gridBagConstraints.insets = new Insets(2, 2, 2, 2);
166
                add((JComponent)getCreateNewLayerPanel(), gridBagConstraints);
167

    
168
                // Insertamos un panel vacio
169
                posy++;
170
                gridBagConstraints = new GridBagConstraints();
171
                gridBagConstraints.gridx = 0;
172
                gridBagConstraints.gridy = posy;
173
                gridBagConstraints.weighty = 1.0;
174
                gridBagConstraints.insets = new Insets(0, 0, 0, 0);
175
                JPanel emptyPanel = new JPanel();
176
                add(emptyPanel, gridBagConstraints);
177
        }
178
        
179
        private JLabel getLayerName() {
180
                if(layerName == null)
181
                        layerName = new JLabel();
182
                return layerName;
183
        }
184
        
185
        public CreateNewLayerPanel getCreateNewLayerPanel() {
186
                if(newLayerPanel == null) {
187
                        newLayerPanel = RasterSwingLocator.getSwingManager().createNewLayerPanel();
188
                        //newLayerPanel = new CreateNewLayerPanelImpl(fileNameManagement);
189
                }
190
                return newLayerPanel;
191
        }
192
        
193
        public InterpolationPanel getInterpolationPanel() {
194
                if(interpolationPanel == null) {
195
                        interpolationPanel = new InterpolationPanel();
196
                }
197
                return interpolationPanel;
198
        }
199
        
200
        public OutputLayerOptionsPanel getLayerOptionsPanel() {
201
                if(layerOptions == null) {
202
                        layerOptions = new OutputLayerOptionsPanel();
203
                        layerOptions.getTextFieldCellSize().addKeyListener(this);
204
                }
205
                return layerOptions;
206
        }
207

    
208
        /**
209
         * Obtiene el bot�n que lanza el panel de selecci�n de proyecciones.
210
         * @return
211
         * @throws RasterDriverException 
212
         */
213
        private CRSSelectPanel getProjectionSrcSelector() {
214
                if (projectionSrcSelector == null) {
215
                        projectionSrcSelector = CRSSelectPanelFactory.getPanel(dataModel.getSrcProjection());
216
                        projectionSrcSelector.setTransPanelActive(true);
217
                        projectionSrcSelector.setPreferredSize(null);
218
                        projectionSrcSelector.addActionListener(new ActionListener() {
219
                                public void actionPerformed(ActionEvent e) {
220
                                        if (projectionSrcSelector.isOkPressed()) {
221
                                                dataModel.setSrcProjection(projectionSrcSelector.getCurProj());
222
                                                try {
223
                                                        updateSize();
224
                                                        getLayerOptionsPanel().getTextFieldCellSize().setText(dataModel.getCellSize() + "");
225
                                                } catch (Exception exc) {
226
                                                }
227
                                        }
228
                                }
229
                        });
230
                        projectionSrcSelector.setBorder(BorderFactory.createTitledBorder(Messages.getText("src_proj")));
231
                }
232
                return projectionSrcSelector;
233
        }
234
        
235
        /**
236
         * Obtiene el bot�n que lanza el panel de selecci�n de proyecciones.
237
         * @return
238
         */
239
        private CRSSelectPanel getProjectionDstSelector() {
240
                if (projectionDstSelector == null) {
241
                        projectionDstSelector = CRSSelectPanel.getPanel(dataModel.getDstProjection());
242
                        projectionDstSelector.setTransPanelActive(true);
243
                        projectionDstSelector.setPreferredSize(null);
244
                        projectionDstSelector.addActionListener(new ActionListener() {
245
                                public void actionPerformed(ActionEvent e) {
246
                                        if (projectionDstSelector.isOkPressed()) {
247
                                                dataModel.setDstProjection(projectionDstSelector.getCurProj());
248
                                                try {
249
                                                        updateSize();
250
                                                        getLayerOptionsPanel().getTextFieldCellSize().setText(dataModel.getCellSize() + "");
251
                                                } catch (Exception exc) {
252
                                                }
253
                                        }
254
                                }
255
                        });
256
                        projectionDstSelector.setBorder(BorderFactory.createTitledBorder(Messages.getText("dest_proj")));
257
                }
258
                return projectionDstSelector;
259
        }
260

    
261
        public void keyPressed(KeyEvent e) {
262
                
263
        }
264

    
265
        public void keyReleased(KeyEvent e) {
266
                try {
267
                        Double d = new Double(getLayerOptionsPanel().getTextFieldCellSize().getText());
268
                        dataModel.setCellSize(d.doubleValue());
269
                        updateSize();
270
                } catch (Exception exc) {
271
                }
272
        }
273

    
274
        private void updateSize() {
275
                getLayerOptionsPanel().getTextFieldSizeX().setText(dataModel.getSize()[0] + "");
276
                getLayerOptionsPanel().getTextFieldSizeY().setText(dataModel.getSize()[1] + "");
277
        }
278
        
279
        public void keyTyped(KeyEvent e) {
280
                
281
        }
282

    
283
        public void addButtonsListener(ActionListener listener) {
284
                getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).addActionListener(listener);
285
                getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL).addActionListener(listener);
286
        }
287
        
288
        public int getObjectSelected(Object obj) {
289
                if(obj == getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT))
290
                        return BUTTON_ACCEPT;
291
                if(obj == getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL))
292
                        return BUTTON_CANCEL;
293
                return -1;
294
        }
295
        
296
        public JComponent getComponent() {
297
                return this;
298
        }
299

    
300
        public String getFileSelected() {
301
                return getCreateNewLayerPanel().getFileSelected();
302
        }
303
        
304
        public String getDirectorySelected() {
305
                return getCreateNewLayerPanel().getDirectorySelected();
306
        }
307

    
308
        public void actionPerformed(ActionEvent e) {
309
                if(e.getSource() == getInterpolationPanel().getComboInterpolationMethod()) {
310
                        dataModel.setInterpolationMethodSelected(getInterpolationPanel().getComboInterpolationMethod().getSelectedIndex());
311
                }
312
                
313
                if(e.getSource() == getInterpolationPanel().getRadioYes()) {
314
                        dataModel.setInterpolationMethodSelected(getInterpolationPanel().getComboInterpolationMethod().getSelectedIndex());
315
                }
316
                
317
                if(e.getSource() == getInterpolationPanel().getRadioNo()) {
318
                        dataModel.setInterpolationMethodSelected(-1);
319
                }
320
        }
321
}