Statistics
| Revision:

gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.reproject / src / main / java / org / gvsig / geoprocess / algorithm / reproject / ReprojectParametersPanel.java @ 639

History | View | Annotate | Download (11.9 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.geoprocess.algorithm.reproject;
25

    
26
import java.awt.Dimension;
27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
29
import java.awt.Insets;
30
import java.awt.event.ActionEvent;
31
import java.awt.event.ActionListener;
32

    
33
import javax.swing.ComboBoxModel;
34
import javax.swing.DefaultComboBoxModel;
35
import javax.swing.JCheckBox;
36
import javax.swing.JComboBox;
37
import javax.swing.JLabel;
38
import javax.swing.JPanel;
39

    
40
import org.cresques.cts.IProjection;
41
import org.gvsig.app.gui.panels.CRSSelectPanel;
42
import org.gvsig.fmap.crs.CRSFactory;
43
import org.gvsig.geoprocess.lib.api.GeoProcessLocator;
44
import org.gvsig.geoprocess.sextante.gui.algorithm.AlgorithmOutputPanel;
45

    
46
import es.unex.sextante.core.GeoAlgorithm;
47
import es.unex.sextante.core.ObjectAndDescription;
48
import es.unex.sextante.core.OutputObjectsSet;
49
import es.unex.sextante.core.ParametersSet;
50
import es.unex.sextante.core.Sextante;
51
import es.unex.sextante.dataObjects.IVectorLayer;
52
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel;
53
import es.unex.sextante.gui.algorithm.OutputChannelSelectionPanel;
54
import es.unex.sextante.gui.core.SextanteGUI;
55
import es.unex.sextante.outputs.Output;
56

    
57
/**
58
 * Panel for reproject algorithm
59
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
60
 */
61
public class ReprojectParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener {
62
        private static final long                serialVersionUID       = 1L;
63
        private GeoAlgorithm                     m_Algorithm            = null;
64
        private JComboBox                        layersCombo            = null;
65
        private JCheckBox                        selectionOnly          = null;
66
        //private AlgorithmOutputPanel             output                 = null;
67
        private JLabel                           projLabel              = null;
68
        private CRSSelectPanel                   projectionSrcSelector  = null;
69
        private IProjection                      targetLayerProjection  = null;
70
        private AlgorithmOutputPanel             algorithmOutputPanel   = null;
71
        private OutputChannelSelectionPanel      outputChannelSelectionPanelPol;
72
        private OutputChannelSelectionPanel      outputChannelSelectionPanelLine;
73
        private OutputChannelSelectionPanel      outputChannelSelectionPanelPoint;
74
        private JPanel                           outputPanel;
75
        
76
        public ReprojectParametersPanel() {
77
                super();
78
        }
79

    
80
    public void init(GeoAlgorithm algorithm) {
81
            m_Algorithm = algorithm;
82
            initGUI();
83
            init();
84
    }
85

    
86
        private void initGUI() {
87
                GridBagLayout gbl = new GridBagLayout();
88
                this.setLayout(gbl);
89
                
90
                GridBagConstraints gbc = new GridBagConstraints();
91
                gbc.fill = GridBagConstraints.HORIZONTAL;
92
                gbc.weightx = 1.0;
93
                gbc.gridx = 0;
94
                gbc.gridy = 0;
95
                gbc.insets = new Insets(15, 5, 15, 0);
96
                this.add(getComboPanel(GeoProcessLocator.getGeoProcessManager().getTranslation("Input_layer"), getLayersCombo()), gbc);
97
                
98
                gbc.gridy = 1;
99
                gbc.insets = new Insets(0, 5, 15, 0);
100
                this.add(getSelectionCheck(), gbc);
101
                
102
                gbc.gridy = 2;
103
                this.add(getCurrentProjLabel(), gbc);
104
                
105
                gbc.gridy = 3;
106
                this.add(getProjectionSelector(), gbc);
107
                
108
                gbc.gridy = 4;
109
                gbc.fill = GridBagConstraints.BOTH;
110
                gbc.weighty = 1.0;
111
                gbc.weightx = 1.0;
112
                this.add(new JPanel(), gbc);
113
                
114
                gbc.gridy = 5;
115
                gbc.fill = GridBagConstraints.HORIZONTAL;
116
                gbc.weighty = 0.0;
117
                this.add(getOutputChannelSelectionPanel(), gbc);
118
        }
119
        
120
        /**
121
         * Gets the output panel (SEXTANTE)
122
         * @return
123
         */
124
        private JPanel getOutputChannelSelectionPanel() {
125
                if(outputPanel == null) {
126
                        try {
127
                                outputPanel = new JPanel();
128
                                outputPanel.setLayout(new GridBagLayout());
129
                                
130
                                final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
131
                                final Output out_pol = ooSet.getOutput(ReprojectAlgorithm.RESULT_POL);
132
                                final Output out_line = ooSet.getOutput(ReprojectAlgorithm.RESULT_LINE);
133
                                final Output out_point = ooSet.getOutput(ReprojectAlgorithm.RESULT_POINT);
134
                                
135
                                outputChannelSelectionPanelPol = new OutputChannelSelectionPanel(out_pol, m_Algorithm.getParameters());
136
                                outputChannelSelectionPanelLine = new OutputChannelSelectionPanel(out_line, m_Algorithm.getParameters());
137
                                outputChannelSelectionPanelPoint = new OutputChannelSelectionPanel(out_point, m_Algorithm.getParameters());
138
                                
139
                                String label = GeoProcessLocator.getGeoProcessManager().getTranslation("Reproject");
140
                                
141
                                GridBagConstraints gbc = new GridBagConstraints();
142
                                gbc.fill = GridBagConstraints.HORIZONTAL;
143
                                gbc.insets = new Insets(0, 0, 4, 0);
144
                                gbc.weightx = 1;
145
                                gbc.gridx = 0;
146
                                gbc.gridy = 0;
147
                                outputPanel.add(new JLabel(" " + label + " [" +
148
                                                GeoProcessLocator.getGeoProcessManager().getTranslation("Polygon") + "]               "), gbc);
149
                                
150
                                gbc.gridx = 0;
151
                                gbc.gridy = 1;
152
                                outputPanel.add(new JLabel(" " + label + " [" +
153
                                                GeoProcessLocator.getGeoProcessManager().getTranslation("Line") + "]               "), gbc);
154
                                
155
                                gbc.gridx = 0;
156
                                gbc.gridy = 2;
157
                                outputPanel.add(new JLabel(" " + label + " [" +
158
                                                GeoProcessLocator.getGeoProcessManager().getTranslation("Point") + "]               "), gbc);
159
                                
160
                                gbc.fill = GridBagConstraints.HORIZONTAL;
161
                                gbc.weightx = 1;
162
                                gbc.gridx = 1;
163
                                gbc.gridy = 0;
164
                                outputPanel.add(outputChannelSelectionPanelPol, gbc);
165
                                
166
                                gbc.gridx = 1;
167
                                gbc.gridy = 1;
168
                                outputPanel.add(outputChannelSelectionPanelLine, gbc);
169
                                
170
                                gbc.gridx = 1;
171
                                gbc.gridy = 2;
172
                                outputPanel.add(outputChannelSelectionPanelPoint, gbc);
173
                        } catch (final Exception e) {
174
                                Sextante.addErrorToLog(e);
175
                        }
176
                }
177
                return outputPanel;
178
        }
179
        
180
        /**
181
         * Gets the output panel (DAL)
182
         * @return
183
         */
184
        @SuppressWarnings("unused")
185
        private AlgorithmOutputPanel getAlgorithmOutputPanel() {
186
                if(algorithmOutputPanel == null)
187
                    algorithmOutputPanel = new AlgorithmOutputPanel();
188
                return algorithmOutputPanel;
189
        }
190
        
191
        /**
192
         * Gets a new JPanel with the text and JComboBox 
193
         * @param text
194
         * @param combo
195
         * @return
196
         */
197
        public JPanel getComboPanel(String text, JComboBox combo) {
198
                JPanel panel = new JPanel();
199
                GridBagLayout gbl = new GridBagLayout();
200
                panel.setLayout(gbl);
201

    
202
                GridBagConstraints gbc = new GridBagConstraints();
203
                gbc.fill = GridBagConstraints.NONE;
204
                gbc.weightx = 0;
205
                gbc.gridx = 0;
206
                gbc.insets = new Insets(0, 2, 0, 50);
207
                JLabel label = new JLabel(text);
208
                label.setPreferredSize(new Dimension(180, 18));
209
                panel.add(label, gbc);
210

    
211
                gbc.fill = GridBagConstraints.HORIZONTAL;
212
                gbc.weightx = 1.0;
213
                gbc.gridx = 1;
214
                gbc.anchor = GridBagConstraints.EAST;
215
                gbc.insets = new Insets(0, 2, 0, 0);
216
                panel.add(combo, gbc);
217
                return panel;
218
        }
219
        
220
        /**
221
         * Gets a ComboBox
222
         * @return
223
         */
224
        public JComboBox getLayersCombo() {
225
                if(layersCombo == null) {
226
                        layersCombo = new JComboBox();
227
                        layersCombo.setPreferredSize(new Dimension(0, 18));
228
                        ComboBoxModel comboModel = new DefaultComboBoxModel(getLayerList());
229
                        layersCombo.setModel(comboModel);
230
                        layersCombo.addActionListener(this);
231
                }
232
                return layersCombo;
233
        }
234
        
235
        
236
        /**
237
         * Gets a CheckBox
238
         * @return
239
         */
240
        public JCheckBox getSelectionCheck() {
241
                if(selectionOnly == null) {
242
                        selectionOnly = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("Selected_geometries"));
243
                }
244
                return selectionOnly;
245
        }
246
        
247
        /**
248
         * Panel with the projection selector
249
         * @return
250
         */
251
        private CRSSelectPanel getProjectionSelector() {
252
                if (projectionSrcSelector == null) {
253
                        targetLayerProjection = CRSFactory.getCRS("EPSG:23030");
254
                        projectionSrcSelector = CRSSelectPanel.getPanel(targetLayerProjection);
255
                        projectionSrcSelector.getJLabel().setText(GeoProcessLocator.getGeoProcessManager().getTranslation("Proyeccion_Destino"));
256
                        projectionSrcSelector.setPreferredSize(new java.awt.Dimension(330,35));
257
                        projectionSrcSelector.addActionListener(new java.awt.event.ActionListener() {
258
                                public void actionPerformed(java.awt.event.ActionEvent e) {
259
                                        if (projectionSrcSelector.isOkPressed()) {
260
                                                targetLayerProjection = projectionSrcSelector.getCurProj();
261
                                        }
262
                                }
263
                        });
264
                }
265
                projectionSrcSelector.setTransPanelActive(true);
266
                return projectionSrcSelector;
267
        }
268
        
269
        /**
270
         * Gets the label with the current projection
271
         * @return
272
         */
273
        public JLabel getCurrentProjLabel() {
274
                if(projLabel == null)
275
                        projLabel = new JLabel();
276
                return projLabel;
277
        }
278
        
279
        //------------------------------------------------------------
280
        
281
        /**
282
         * Initialize actions
283
         */
284
        private void init() {
285
                IVectorLayer layer = getSelectedVectorLayer();
286
                IProjection currentProj = (IProjection)layer.getCRS();
287
                getCurrentProjLabel().setText(GeoProcessLocator.getGeoProcessManager().getTranslation("current_proj") + ": " + currentProj.getAbrev());
288
        }
289
        
290
        /*
291
         * (non-Javadoc)
292
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
293
         */
294
        public void actionPerformed(ActionEvent e) {
295
                if(e.getSource() ==  getLayersCombo()) {
296
                        init();
297
                }
298
        }
299
        
300
        @Override
301
    public void assignParameters() {
302
                try {
303
                        ParametersSet params = m_Algorithm.getParameters();
304
                        params.getParameter(ReprojectAlgorithm.LAYER).setParameterValue(getSelectedVectorLayer());
305
                        params.getParameter(ReprojectAlgorithm.SELECTED_GEOM).setParameterValue(getSelectionCheck().isSelected());
306
                        String proj = getProjectionSelector().getCurProj().getFullCode();
307
                        params.getParameter(ReprojectAlgorithm.DST_PROJECTION).setParameterValue(proj);
308
                        
309
                        OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
310
                        Output outPol = ooSet.getOutput(ReprojectAlgorithm.RESULT_POL);
311
                        Output outLine = ooSet.getOutput(ReprojectAlgorithm.RESULT_LINE);
312
                        Output outPoint = ooSet.getOutput(ReprojectAlgorithm.RESULT_POINT);
313
                        
314
                        //Reponer estas l?neas para cambiar el panel de salida y comentar la siguiente
315
                        //out.setOutputChannel(new CompositeSourceOutputChannel(getAlgorithmOutputPanel().getOutputParameters()));
316
                        outPol.setOutputChannel(outputChannelSelectionPanelPol.getOutputChannel());
317
                        outLine.setOutputChannel(outputChannelSelectionPanelLine.getOutputChannel());
318
                        outPoint.setOutputChannel(outputChannelSelectionPanelPoint.getOutputChannel());
319
                } catch (Exception e) {
320
                        Sextante.addErrorToLog(e);
321
                }
322
        }
323

    
324
        @Override
325
        public void setOutputValue(String arg0, String arg1) {
326
                
327
        }
328

    
329
        @Override
330
        public void setParameterValue(String arg0, String arg1) {
331
                
332
        }
333
        
334
        /**
335
         * Gets the input layer list
336
         * @return
337
         */
338
        private ObjectAndDescription[] getLayerList() {
339
                IVectorLayer[] layers = SextanteGUI.getInputFactory()
340
                                        .getVectorLayers(IVectorLayer.SHAPE_TYPE_WRONG);
341
                ObjectAndDescription[] oad = new ObjectAndDescription[layers.length];
342
                for (int i = 0; i < layers.length; i++)
343
                        oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
344
                return oad;
345
        }
346
        
347
        /**
348
         * Gets the selected vector layer in the JComboBox
349
         * @return
350
         */
351
        private IVectorLayer getSelectedVectorLayer() {
352
                if(layersCombo.getSelectedItem() != null)
353
                        return (IVectorLayer)((ObjectAndDescription)layersCombo.getSelectedItem()).getObject();
354
                return null;
355
        }
356
        
357
        /**
358
         * Gets the field list of the selected layer
359
         * @return
360
         */
361
        public String[] getFieldList() {
362
                IVectorLayer layer = getSelectedVectorLayer();
363
                String[] data = new String[layer.getFieldCount()];
364
                for (int i = 0; i < layer.getFieldCount(); i++) 
365
                        data[i] = layer.getFieldName(i);
366
                return data;
367
        }
368
}