Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / gvsig / geoprocessing / gui / operationpanels / GeoProcessingOverlayPanel.java @ 4340

History | View | Annotate | Download (13 KB)

1
/*
2
 * Created on 04-jul-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
package com.iver.gvsig.geoprocessing.gui.operationpanels;
45

    
46
import java.awt.Component;
47
import java.io.File;
48

    
49
import javax.swing.DefaultComboBoxModel;
50
import javax.swing.JButton;
51
import javax.swing.JCheckBox;
52
import javax.swing.JComboBox;
53
import javax.swing.JFileChooser;
54
import javax.swing.JLabel;
55
import javax.swing.JPanel;
56
import javax.swing.JTextField;
57

    
58
import com.iver.andami.PluginServices;
59
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
60
import com.iver.cit.gvsig.fmap.layers.FBitSet;
61
import com.iver.cit.gvsig.fmap.layers.FLayers;
62
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
63
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
64
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
65
import com.iver.utiles.GenericFileFilter;
66
/**
67
 * Panel that allows user to enter clip geoprocess params
68
 * (input layers, etc).
69
 * 
70
 * @author jmorell, azabala
71
 */
72
public class GeoProcessingOverlayPanel extends GeoProcessingOperationPanel 
73
                                                        implements OverlayPanelIF {
74
    
75
        private static final long serialVersionUID = 1L;
76
    private JTextField filePathTextField = null;//@jve:decl-index=0:visual-constraint="41,143"
77
        private JButton openFileDialogButton = null;
78
        private JComboBox firstLayerComboBox = null;
79
        private JCheckBox selectedFirstLayerCheckBox = null;
80
        private JComboBox secondLayerComboBox = null;
81
        private JCheckBox secondLayerSelectedCheckBox = null;
82
        private JLabel jLabel = null;
83
        private JLabel jLabel1 = null;
84
        private JLabel jLabel2 = null;
85
        private JLabel jLabel3 = null;
86
        private JLabel jLabel4 = null;
87
        private JLabel jLabel5 = null;
88
        private JLabel jLabel6 = null;
89
        private JLabel jLabel7 = null;
90
  
91
    /**
92
     * Text that describes which type of overlay
93
     * operation will launch this panel
94
     */
95
        private String titleText;
96
        
97
        /**
98
         * This constructor initializes the set of layers
99
         */
100
        public GeoProcessingOverlayPanel(FLayers layers, String titleText) {
101
                super();
102
                this.layers = layers;
103
                this.titleText = titleText;
104
                initialize();
105
        }
106
        /**
107
         * This method initializes this
108
         * 
109
         * @return void
110
         */
111
        private  void initialize() {
112
                jLabel7 = new JLabel();
113
                jLabel6 = new JLabel();
114
                jLabel5 = new JLabel();
115
                jLabel4 = new JLabel();
116
                jLabel3 = new JLabel();
117
                jLabel2 = new JLabel();
118
                jLabel1 = new JLabel();
119
                jLabel = new JLabel();
120
                this.setLayout(null);
121
                this.setSize(405, 232);
122
                jLabel.setBounds(6, 6, 194, 21);
123
                jLabel.setText(titleText);
124
                jLabel1.setBounds(6, 40, 125, 21);
125
                jLabel1.setText(PluginServices.getText(this,"Cobertura_de_entrada") + ":");
126
                jLabel2.setBounds(6, 90, 195, 21);
127
                jLabel2.setText(PluginServices.getText(this,"Numero_de_elementos_seleccionados") + ":");
128
                jLabel3.setBounds(205, 90, 36, 21);
129
                jLabel3.setText("00");
130
                jLabel4.setBounds(6, 122, 124, 21);
131
                jLabel4.setText(PluginServices.getText(this,"Cobertura de recorte") + ":");
132
                jLabel5.setBounds(6, 173, 192, 21);
133
                jLabel5.setText(PluginServices.getText(this,"Numero_de_elementos_seleccionados") + ":");
134
                jLabel6.setBounds(202, 173, 39, 21);
135
                jLabel6.setText("00");
136
                jLabel7.setBounds(6, 203, 117, 21);
137
                jLabel7.setText(PluginServices.getText(this,"Cobertura_de_salida") + ":");
138
                this.add(getFirstLayerComboBox(), null);
139
                this.add(getOnlyFirstLayerSelectedCheckBox(), null);
140
                this.add(getOpenFileDialogButton(), null);
141
                this.add(getSecondLayerComboBox(), null);
142
                this.add(getFilePathTextField(), null);
143
                this.add(getOnlySecondLayerSelectedCheckBox(), null);
144
                this.add(jLabel, null);
145
                this.add(jLabel1, null);
146
                this.add(jLabel2, null);
147
                this.add(jLabel3, null);
148
                this.add(jLabel4, null);
149
                this.add(jLabel5, null);
150
                this.add(jLabel6, null);
151
                this.add(jLabel7, null);
152
        changeSelectedItemsJCheckBox();
153
        changeSelectedItemsJCheckBox1();
154
        changeSelectedItemsNumberJLabel();
155
        changeSelectedItemsNumberJLabel1();
156
        }
157
   
158
    private void changeSelectedItemsJCheckBox() {
159
        FLyrVect inputSelectable = (FLyrVect)(layers.getLayer((String)firstLayerComboBox.getSelectedItem()));
160
        FBitSet fBitSet = inputSelectable.getRecordset().getSelection();
161
        if (fBitSet.cardinality()==0) {
162
            selectedFirstLayerCheckBox.setEnabled(false);
163
            selectedFirstLayerCheckBox.setSelected(false);
164
        } else {
165
            selectedFirstLayerCheckBox.setEnabled(true);
166
            selectedFirstLayerCheckBox.setSelected(true);
167
        }
168
    }
169
    private void changeSelectedItemsJCheckBox1() {
170
        FLyrVect inputSelectable = (FLyrVect)(layers.getLayer((String)secondLayerComboBox.getSelectedItem()));
171
        FBitSet fBitSet = inputSelectable.getRecordset().getSelection();
172
        if (fBitSet.cardinality()==0) {
173
            secondLayerSelectedCheckBox.setEnabled(false);
174
            secondLayerSelectedCheckBox.setSelected(false);
175
        } else {
176
            secondLayerSelectedCheckBox.setEnabled(true);
177
            secondLayerSelectedCheckBox.setSelected(true);
178
        }
179
    }
180
    private void changeSelectedItemsNumberJLabel() {
181
        if (getOnlyFirstLayerSelectedCheckBox().isSelected()) {
182
            FLyrVect inputSelectable = (FLyrVect)(layers.getLayer((String)firstLayerComboBox.getSelectedItem()));
183
            FBitSet fBitSet = inputSelectable.getRecordset().getSelection();
184
            jLabel3.setText(new Integer(fBitSet.cardinality()).toString());
185
        } else {
186
            VectorialAdapter va = (VectorialAdapter)((SingleLayer)(layers.getLayer((String)firstLayerComboBox.getSelectedItem()))).getSource();
187
            try {
188
                jLabel3.setText(new Integer(va.getShapeCount()).toString());
189
            } catch (DriverIOException e) {
190
                // TODO Auto-generated catch block
191
                e.printStackTrace();
192
            }
193
        }
194
    }
195
    private void changeSelectedItemsNumberJLabel1() {
196
        if (getOnlySecondLayerSelectedCheckBox().isSelected()) {
197
            FLyrVect inputSelectable = (FLyrVect)(layers.getLayer((String)secondLayerComboBox.getSelectedItem()));
198
            FBitSet fBitSet = inputSelectable.getRecordset().getSelection();
199
            jLabel6.setText(new Integer(fBitSet.cardinality()).toString());
200
        } else {
201
            VectorialAdapter va = (VectorialAdapter)((SingleLayer)(layers.getLayer((String)secondLayerComboBox.getSelectedItem()))).getSource();
202
            try {
203
                jLabel6.setText(new Integer(va.getShapeCount()).toString());
204
            } catch (DriverIOException e) {
205
                // TODO Auto-generated catch block
206
                e.printStackTrace();
207
            }
208
        }
209
    }
210
        /**
211
         * This method initializes filePathTextField        
212
         *         
213
         * @return javax.swing.JTextField        
214
         */    
215
        private JTextField getFilePathTextField() {
216
                if (filePathTextField == null) {
217
                        filePathTextField = new JTextField();
218
                        filePathTextField.setBounds(129, 203, 204, 21);
219
                }
220
                return filePathTextField;
221
        }
222
        /**
223
         * 
224
         * TODO
225
         * El panel de seleccion de escritura esta metido a pelo en todas
226
         * las pantallas. Hacer que sea generico, y vinculado a los IWriters
227
         * cargados en el sistema.
228
         * 
229
         * 
230
         */    
231
        private JButton getOpenFileDialogButton() {
232
                if (openFileDialogButton == null) {
233
                        openFileDialogButton = new JButton();
234
                        openFileDialogButton.setText(PluginServices.getText(this,"Abrir"));
235
                        openFileDialogButton.addActionListener(new java.awt.event.ActionListener() { 
236
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
237
                    openResultFileDialog();
238
                                }
239
                        });
240
                        openFileDialogButton.setBounds(337, 203, 61, 21);
241
                }
242
                return openFileDialogButton;
243
        }
244
        /**
245
         * This method initializes firstLayerComboBox        
246
         *         
247
         * @return javax.swing.JComboBox        
248
         */    
249
        private JComboBox getFirstLayerComboBox() {
250
                if (firstLayerComboBox == null) {
251
                        firstLayerComboBox = new JComboBox();
252
            DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames());
253
            firstLayerComboBox.setModel(defaultModel);
254
                        firstLayerComboBox.setBounds(138, 40, 260, 21);
255
                        firstLayerComboBox.addItemListener(new java.awt.event.ItemListener() { 
256
                                public void itemStateChanged(java.awt.event.ItemEvent e) {    
257
                    changeSelectedItemsJCheckBox();
258
                    changeSelectedItemsNumberJLabel();
259
                                }
260
                        });
261
                }
262
                return firstLayerComboBox;
263
        }
264
        /**
265
         * This method initializes selectedFirstLayerCheckBox        
266
         *         
267
         * @return javax.swing.JCheckBox        
268
         */    
269
        private JCheckBox getOnlyFirstLayerSelectedCheckBox() {
270
                if (selectedFirstLayerCheckBox == null) {
271
                        selectedFirstLayerCheckBox = new JCheckBox();
272
                        selectedFirstLayerCheckBox.setText(PluginServices.getText(this,"Usar_solamente_los_elementos_seleccionados"));
273
                        selectedFirstLayerCheckBox.addItemListener(new java.awt.event.ItemListener() { 
274
                                public void itemStateChanged(java.awt.event.ItemEvent e) {    
275
                    changeSelectedItemsNumberJLabel();
276
                                }
277
                        });
278
                        selectedFirstLayerCheckBox.setBounds(6, 66, 263, 21);
279
                }
280
                return selectedFirstLayerCheckBox;
281
        }
282
        /**
283
         * This method initializes secondLayerComboBox        
284
         *         
285
         * @return javax.swing.JComboBox        
286
         */    
287
        private JComboBox getSecondLayerComboBox() {
288
                if (secondLayerComboBox == null) {
289
                        secondLayerComboBox = new JComboBox();
290
            DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames());
291
            secondLayerComboBox.setModel(defaultModel);
292
                        secondLayerComboBox.setBounds(136, 122, 262, 21);
293
                        secondLayerComboBox.addItemListener(new java.awt.event.ItemListener() { 
294
                                public void itemStateChanged(java.awt.event.ItemEvent e) {    
295
                    changeSelectedItemsJCheckBox1();
296
                    changeSelectedItemsNumberJLabel1();
297
                                }
298
                        });
299
                }
300
                return secondLayerComboBox;
301
        }
302
        /**
303
         * This method initializes secondLayerSelectedCheckBox        
304
         *         
305
         * @return javax.swing.JCheckBox        
306
         */    
307
        private JCheckBox getOnlySecondLayerSelectedCheckBox() {
308
                if (secondLayerSelectedCheckBox == null) {
309
                        secondLayerSelectedCheckBox = new JCheckBox();
310
                        secondLayerSelectedCheckBox.setText(PluginServices.getText(this,"Usar_solamente_los_elementos_seleccionados"));
311
                        secondLayerSelectedCheckBox.addItemListener(new java.awt.event.ItemListener() { 
312
                                public void itemStateChanged(java.awt.event.ItemEvent e) {    
313
                    changeSelectedItemsNumberJLabel1();
314
                                }
315
                        });
316
                        secondLayerSelectedCheckBox.setBounds(6, 149, 263, 21);
317
                }
318
                return secondLayerSelectedCheckBox;
319
        }
320
   
321
        
322
    public File getOutputFile() {
323
            return new File(getFilePathTextField().getText());
324
    }
325
    
326
        public FLyrVect getFirstLayer() {
327
                String layerToClipName = 
328
                        (String) firstLayerComboBox.getSelectedItem();
329
                return (FLyrVect) layers.getLayer(layerToClipName);
330
        }
331
        
332
        public FLyrVect getSecondLayer() {
333
                String clippingLayer = 
334
                        (String) secondLayerComboBox.getSelectedItem();
335
                return (FLyrVect) layers.getLayer(clippingLayer);
336
        }
337
        
338
        public boolean onlyFirstLayerSelected() {
339
                return selectedFirstLayerCheckBox.isSelected();
340
        }
341
        
342
        public boolean onlySecondLayerSelected() {
343
                return secondLayerSelectedCheckBox.isSelected();
344
        }
345
        
346
        
347
        //TODO Sustituir esto para que pueda trabajar
348
        //con los IWriter que est?n registrados en el sistema
349
        public void openResultFileDialog() {
350
                JFileChooser jfc = new JFileChooser();
351
        jfc.addChoosableFileFilter(
352
                        new GenericFileFilter("shp", "Ficheros SHP"));
353
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
354
            File file = jfc.getSelectedFile();
355
            if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){
356
                file = new File(file.getPath()+".shp");
357
            }
358
        }
359
        if (jfc.getSelectedFile()!=null) 
360
                getFilePathTextField().setText(jfc.getSelectedFile().getAbsolutePath());
361
        }
362
        
363
        //TODO Rehacer esto
364
        public void firstLayerSelectionChecked(boolean checked) {
365
                changeSelectedItemsJCheckBox();
366
        changeSelectedItemsNumberJLabel();
367
        }
368
        public void secondLayerSelectionChecked(boolean checked) {
369
                changeSelectedItemsJCheckBox1();
370
                changeSelectedItemsNumberJLabel1();
371
        }
372
}  //  @jve:decl-index=0:visual-constraint="10,10"