Statistics
| Revision:

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

History | View | Annotate | Download (14.2 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
import java.util.ArrayList;
49
import java.util.Map;
50

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

    
60
import com.iver.andami.PluginServices;
61
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
62
import com.iver.cit.gvsig.fmap.layers.FBitSet;
63
import com.iver.cit.gvsig.fmap.layers.FLayers;
64
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
65
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
66
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
67
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
68
import com.iver.gvsig.geoprocessing.schemabuilder.XTypes;
69
import com.iver.utiles.GenericFileFilter;
70
/**
71
 * @author jmorell
72
 */
73
public class GeoProcessingSpatialjoinPanel extends GeoProcessingOperationPanel 
74
        implements SpatialJoinPanelIF{
75

    
76
        /**
77
     * 
78
     */
79
    private static final long serialVersionUID = 1L;
80
    private JTextField jTextField = null;  //  @jve:decl-index=0:visual-constraint="41,143"
81
        private JButton jButton = null;
82
        private JComboBox firstLayerCombo = null;
83
        private JCheckBox firstSelectionCheck = null;
84
        private JComboBox secondLayerCombo = null;
85
        private JCheckBox secondSelectionCheck = null;
86
        private JLabel jLabel = null;
87
        private JLabel jLabel1 = null;
88
        private JLabel jLabel2 = null;
89
        private JLabel jLabel3 = null;
90
        private JLabel jLabel4 = null;
91
        private JLabel jLabel5 = null;
92
        private JLabel jLabel6 = null;
93
        private JLabel jLabel7 = null;
94
    private File outputFile = null;
95
        private JCheckBox nearestCheckbox = null;
96
        private JLabel nearestLabel = null;
97
        private SpatialJoinNumericFieldSelection fieldDialog = null;
98
        private Map sumarizeFunctions;
99
        /**
100
         * This is the default constructor
101
         */
102
        /*public GeoProcessingSpatialjoinPanel() {
103
                super();
104
                initialize();
105
        }*/
106
        /**
107
         * This constructor initializes the set of layers
108
         */
109
        public GeoProcessingSpatialjoinPanel(FLayers layers) {
110
                super();
111
                this.layers = layers;
112
                initialize();
113
        }
114
        /**
115
         * This method initializes this
116
         * 
117
         * @return void
118
         */
119
        private  void initialize() {
120
                nearestLabel = new JLabel();
121
                nearestLabel.setBounds(new java.awt.Rectangle(288,153,148,16));
122
                nearestLabel.setText(PluginServices.getText(this,"Obtener_mas_proximo"));
123
                jLabel7 = new JLabel();
124
                jLabel6 = new JLabel();
125
                jLabel5 = new JLabel();
126
                jLabel4 = new JLabel();
127
                jLabel3 = new JLabel();
128
                jLabel2 = new JLabel();
129
                jLabel1 = new JLabel();
130
                jLabel = new JLabel();
131
                this.setLayout(null);
132
                this.setSize(517, 232);
133
                jLabel.setBounds(6, 6, 213, 21);
134
                jLabel.setText(PluginServices.getText(this,"Enlace_espacial._Introduccion_de_datos") + ":");
135
                jLabel1.setBounds(6, 40, 125, 21);
136
                jLabel1.setText(PluginServices.getText(this,"Cobertura_de_entrada") + ":");
137
                jLabel2.setBounds(6, 90, 195, 21);
138
                jLabel2.setText(PluginServices.getText(this,"Numero_de_elementos_seleccionados") + ":");
139
                jLabel3.setBounds(205, 90, 36, 21);
140
                jLabel3.setText("00");
141
                jLabel4.setBounds(6, 122, 124, 21);
142
                jLabel4.setText(PluginServices.getText(this,"Cobertura_de_datos") + ":");
143
                jLabel5.setBounds(6, 173, 192, 21);
144
                jLabel5.setText(PluginServices.getText(this,"Numero_de_elementos_seleccionados") + ":");
145
                jLabel6.setBounds(202, 173, 39, 21);
146
                jLabel6.setText("00");
147
                jLabel7.setBounds(6, 203, 127, 21);
148
                jLabel7.setText(PluginServices.getText(this,"Cobertura_de_salida") + ":");
149
                this.add(getFirstLayerCombo(), null);
150
                this.add(getFirstSelectionCheck(), null);
151
                this.add(getJButton(), null);
152
                this.add(getSecondLayerCombo(), null);
153
                this.add(getJTextField(), null);
154
                this.add(getSecondSelectionCheck(), null);
155
                this.add(jLabel, null);
156
                this.add(jLabel1, null);
157
                this.add(jLabel2, null);
158
                this.add(jLabel3, null);
159
                this.add(jLabel4, null);
160
                this.add(jLabel5, null);
161
                this.add(jLabel6, null);
162
                this.add(jLabel7, null);
163
                this.add(getNearestCheckbox(), null);
164
                this.add(nearestLabel, null);
165
        changeSelectedItemsJCheckBox();
166
        changeSelectedItemsJCheckBox1();
167
        changeSelectedItemsNumberJLabel();
168
        changeSelectedItemsNumberJLabel1();
169
        }
170
   
171
    private void changeSelectedItemsJCheckBox() {
172
            FLyrVect inputSelectable = (FLyrVect)(layers.getLayer((String)firstLayerCombo.getSelectedItem()));
173
        FBitSet fBitSet = inputSelectable.getRecordset().getSelection();
174
        if (fBitSet.cardinality()==0) {
175
            firstSelectionCheck.setEnabled(false);
176
            firstSelectionCheck.setSelected(false);
177
        } else {
178
            firstSelectionCheck.setEnabled(true);
179
            firstSelectionCheck.setSelected(true);
180
        }
181
    }
182
    private void changeSelectedItemsJCheckBox1() {
183
            FLyrVect inputSelectable = (FLyrVect)(layers.getLayer((String)secondLayerCombo.getSelectedItem()));
184
        FBitSet fBitSet = inputSelectable.getRecordset().getSelection();
185
        if (fBitSet.cardinality()==0) {
186
            secondSelectionCheck.setEnabled(false);
187
            secondSelectionCheck.setSelected(false);
188
        } else {
189
            secondSelectionCheck.setEnabled(true);
190
            secondSelectionCheck.setSelected(true);
191
        }
192
    }
193
    private void changeSelectedItemsNumberJLabel() {
194
        if (getFirstSelectionCheck().isSelected()) {
195
                FLyrVect inputSelectable = (FLyrVect)(layers.getLayer((String)firstLayerCombo.getSelectedItem()));
196
            FBitSet fBitSet = inputSelectable.getRecordset().getSelection();
197
            jLabel3.setText(new Integer(fBitSet.cardinality()).toString());
198
        } else {
199
            VectorialAdapter va = (VectorialAdapter)((SingleLayer)(layers.getLayer((String)firstLayerCombo.getSelectedItem()))).getSource();
200
            try {
201
                jLabel3.setText(new Integer(va.getShapeCount()).toString());
202
            } catch (DriverIOException e) {
203
                // TODO Auto-generated catch block
204
                e.printStackTrace();
205
            }
206
        }
207
    }
208
    private void changeSelectedItemsNumberJLabel1() {
209
        if (getSecondSelectionCheck().isSelected()) {
210
                FLyrVect inputSelectable = (FLyrVect)(layers.getLayer((String)secondLayerCombo.getSelectedItem()));
211
            FBitSet fBitSet = inputSelectable.getRecordset().getSelection();
212
            jLabel6.setText(new Integer(fBitSet.cardinality()).toString());
213
        } else {
214
            VectorialAdapter va = (VectorialAdapter)((SingleLayer)(layers.getLayer((String)secondLayerCombo.getSelectedItem()))).getSource();
215
            try {
216
                jLabel6.setText(new Integer(va.getShapeCount()).toString());
217
            } catch (DriverIOException e) {
218
                // TODO Auto-generated catch block
219
                e.printStackTrace();
220
            }
221
        }
222
    }
223
        /**
224
         * This method initializes jTextField        
225
         *         
226
         * @return javax.swing.JTextField        
227
         */    
228
        private JTextField getJTextField() {
229
                if (jTextField == null) {
230
                        jTextField = new JTextField();
231
                        jTextField.setBounds(139, 203, 194, 21);
232
                }
233
                return jTextField;
234
        }
235
        /**
236
         * This method initializes jButton        
237
         *         
238
         * @return javax.swing.JButton        
239
         */    
240
        private JButton getJButton() {
241
                if (jButton == null) {
242
                        jButton = new JButton();
243
                        jButton.setText(PluginServices.getText(this,"Abrir"));
244
                        jButton.addActionListener(new java.awt.event.ActionListener() { 
245
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
246
                    openResultFileDialog();
247
                                }
248
                        });
249
                        jButton.setBounds(337, 203, 76, 21);
250
                }
251
                return jButton;
252
        }
253
        /**
254
         * This method initializes firstLayerCombo        
255
         *         
256
         * @return javax.swing.JComboBox        
257
         */    
258
        private JComboBox getFirstLayerCombo() {
259
                if (firstLayerCombo == null) {
260
                        firstLayerCombo = new JComboBox();
261
            DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames());
262
            firstLayerCombo.setModel(defaultModel);
263
                        firstLayerCombo.setBounds(138, 40, 260, 21);
264
                        firstLayerCombo.addItemListener(new java.awt.event.ItemListener() { 
265
                                public void itemStateChanged(java.awt.event.ItemEvent e) {    
266
                    changeSelectedItemsJCheckBox();
267
                    changeSelectedItemsNumberJLabel();
268
                                }
269
                        });
270
                }
271
                return firstLayerCombo;
272
        }
273
        /**
274
         * This method initializes firstSelectionCheck        
275
         *         
276
         * @return javax.swing.JCheckBox        
277
         */    
278
        private JCheckBox getFirstSelectionCheck() {
279
                if (firstSelectionCheck == null) {
280
                        firstSelectionCheck = new JCheckBox();
281
                        firstSelectionCheck.setText(PluginServices.getText(this,"Usar_solamente_los_elementos_seleccionados"));
282
                        firstSelectionCheck.addItemListener(new java.awt.event.ItemListener() { 
283
                                public void itemStateChanged(java.awt.event.ItemEvent e) {    
284
                                        firstLayerSelectionChecked(firstSelectionCheck.isSelected());
285
                                }
286
                        });
287
                        firstSelectionCheck.setBounds(6, 66, 264, 21);
288
                }
289
                return firstSelectionCheck;
290
        }
291
        /**
292
         * This method initializes secondLayerCombo        
293
         *         
294
         * @return javax.swing.JComboBox        
295
         */    
296
        private JComboBox getSecondLayerCombo() {
297
                if (secondLayerCombo == null) {
298
                        secondLayerCombo = new JComboBox();
299
            DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames());
300
            secondLayerCombo.setModel(defaultModel);
301
                        secondLayerCombo.setBounds(136, 122, 262, 21);
302
                        secondLayerCombo.addItemListener(new java.awt.event.ItemListener() { 
303
                                public void itemStateChanged(java.awt.event.ItemEvent e) {    
304
                    changeSelectedItemsJCheckBox1();
305
                    changeSelectedItemsNumberJLabel1();
306
                                }
307
                        });
308
                }
309
                return secondLayerCombo;
310
        }
311
        /**
312
         * This method initializes secondSelectionCheck        
313
         *         
314
         * @return javax.swing.JCheckBox        
315
         */    
316
        private JCheckBox getSecondSelectionCheck() {
317
                if (secondSelectionCheck == null) {
318
                        secondSelectionCheck = new JCheckBox();
319
                        secondSelectionCheck.setText(PluginServices.getText(this,"Usar_solamente_los_elementos_seleccionados"));
320
                        secondSelectionCheck.addItemListener(new java.awt.event.ItemListener() { 
321
                                public void itemStateChanged(java.awt.event.ItemEvent e) {    
322
                    secondLayerSelectionChecked(secondSelectionCheck.isSelected());
323
                                }
324
                        });
325
                        secondSelectionCheck.setBounds(6, 149, 264, 21);
326
                }
327
                return secondSelectionCheck;
328
        }
329
    /**
330
     * @return Returns the outputFile.
331
     */
332
    public File getOutputFile() {
333
        return outputFile;
334
    }
335
        /**
336
         * This method initializes nearestCheckbox        
337
         *         
338
         * @return javax.swing.JCheckBox        
339
         */
340
        private JCheckBox getNearestCheckbox() {
341
                if (nearestCheckbox == null) {
342
                        nearestCheckbox = new JCheckBox();
343
                        nearestCheckbox.setBounds(new java.awt.Rectangle(266,149,21,21));
344
                }
345
                return nearestCheckbox;
346
        }
347
        
348
        public boolean isNearestSelected() {
349
                return nearestCheckbox.isSelected();
350
        }
351
        
352
        //FIXME FUNCION PARA CENTRAR DIALOGOS (SALEN DESCUADRADOS)
353
        public void openSumarizeFunction() {
354
                if(fieldDialog == null){
355
                        fieldDialog = new SpatialJoinNumericFieldSelection();
356
                        fieldDialog.pack();
357
                }
358
                String[] numericFields = getTargetLayerNumericFields();
359
                fieldDialog.setNumericFields(numericFields);
360
                fieldDialog.setSize(370, 236);
361
                fieldDialog.setVisible(true);
362
                this.sumarizeFunctions = fieldDialog.getSumarizationFunctions();
363
        }
364
        public FLyrVect getFirstLayer() {
365
                return (FLyrVect) layers.getLayer((String)firstLayerCombo.getSelectedItem());
366
        }
367
        public FLyrVect getSecondLayer() {
368
                return (FLyrVect) layers.getLayer((String)secondLayerCombo.getSelectedItem());
369
        }
370
        public boolean onlyFirstLayerSelected() {
371
                return firstSelectionCheck.isSelected();
372
        }
373
        public boolean onlySecondLayerSelected() {
374
                return secondSelectionCheck.isSelected();
375
        }
376
        public void openResultFileDialog() {
377
                JFileChooser jfc = new JFileChooser();
378
        jfc.addChoosableFileFilter(new GenericFileFilter("shp", "Ficheros SHP"));
379
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
380
            File file = jfc.getSelectedFile();
381
            if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){
382
                file = new File(file.getPath()+".shp");
383
            }
384
            outputFile = file;
385
        }
386
        if (jfc.getSelectedFile()!=null) getJTextField().setText(jfc.getSelectedFile().getAbsolutePath());
387
                
388
        }
389
        public void firstLayerSelectionChecked(boolean checked) {
390
                changeSelectedItemsNumberJLabel();
391
                
392
        }
393
        public void secondLayerSelectionChecked(boolean checked) {
394
                changeSelectedItemsNumberJLabel1();
395
        }
396
        public String[] getTargetLayerNumericFields() {
397
                String[] solution;
398
                FLyrVect layer = getSecondLayer();
399
                ArrayList list = new ArrayList();
400
                SelectableDataSource recordset = layer.getRecordset();
401
                try {
402
                        int numFields = recordset.getFieldCount();
403
                        for (int i = 0; i < numFields; i++) {
404
                                if (XTypes.isNumeric(recordset.getFieldType(i))) {
405
                                        list.add(recordset.getFieldName(i));
406
                                }
407
                        }// for
408
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
409
                        return null;
410
                }
411
                solution = new String[list.size()];
412
                list.toArray(solution);
413
                return solution;
414
        }
415
        public Map getSumarizeFunctions() {
416
                return sumarizeFunctions;
417
        }
418
}  //  @jve:decl-index=0:visual-constraint="10,10"