svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / gvsig / geoprocessing / gui / operationpanels / GeoProcessingSpatialjoinPanel.java @ 4340
History | View | Annotate | Download (14.2 KB)
1 | 2402 | jmorell | /*
|
---|---|---|---|
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 | 4270 | azabala | import java.util.ArrayList; |
49 | import java.util.Map; |
||
50 | 2402 | jmorell | |
51 | import javax.swing.DefaultComboBoxModel; |
||
52 | 4270 | azabala | import javax.swing.JButton; |
53 | import javax.swing.JCheckBox; |
||
54 | import javax.swing.JComboBox; |
||
55 | 2402 | jmorell | import javax.swing.JFileChooser; |
56 | import javax.swing.JLabel; |
||
57 | 4270 | azabala | import javax.swing.JPanel; |
58 | 2402 | jmorell | 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 | 4065 | azabala | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
65 | 4270 | azabala | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
66 | 2402 | jmorell | import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
67 | import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
||
68 | 4270 | azabala | import com.iver.gvsig.geoprocessing.schemabuilder.XTypes; |
69 | 2402 | jmorell | import com.iver.utiles.GenericFileFilter; |
70 | /**
|
||
71 | * @author jmorell
|
||
72 | */
|
||
73 | 4340 | azabala | public class GeoProcessingSpatialjoinPanel extends GeoProcessingOperationPanel |
74 | 4270 | azabala | implements SpatialJoinPanelIF{
|
75 | 2402 | jmorell | |
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 | 4270 | azabala | private JComboBox firstLayerCombo = null; |
83 | private JCheckBox firstSelectionCheck = null; |
||
84 | private JComboBox secondLayerCombo = null; |
||
85 | private JCheckBox secondSelectionCheck = null; |
||
86 | 2402 | jmorell | 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 | 4270 | azabala | private JCheckBox nearestCheckbox = null; |
96 | private JLabel nearestLabel = null; |
||
97 | private SpatialJoinNumericFieldSelection fieldDialog = null; |
||
98 | private Map sumarizeFunctions; |
||
99 | 2402 | jmorell | /**
|
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 | 4270 | azabala | nearestLabel = new JLabel(); |
121 | nearestLabel.setBounds(new java.awt.Rectangle(288,153,148,16)); |
||
122 | nearestLabel.setText(PluginServices.getText(this,"Obtener_mas_proximo")); |
||
123 | 2402 | jmorell | 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 | 4270 | azabala | this.setSize(517, 232); |
133 | 2676 | jmorell | jLabel.setBounds(6, 6, 213, 21); |
134 | 2689 | jmorell | jLabel.setText(PluginServices.getText(this,"Enlace_espacial._Introduccion_de_datos") + ":"); |
135 | 2402 | jmorell | jLabel1.setBounds(6, 40, 125, 21); |
136 | 2676 | jmorell | jLabel1.setText(PluginServices.getText(this,"Cobertura_de_entrada") + ":"); |
137 | 2402 | jmorell | jLabel2.setBounds(6, 90, 195, 21); |
138 | 2676 | jmorell | jLabel2.setText(PluginServices.getText(this,"Numero_de_elementos_seleccionados") + ":"); |
139 | 2402 | jmorell | jLabel3.setBounds(205, 90, 36, 21); |
140 | jLabel3.setText("00");
|
||
141 | jLabel4.setBounds(6, 122, 124, 21); |
||
142 | 2676 | jmorell | jLabel4.setText(PluginServices.getText(this,"Cobertura_de_datos") + ":"); |
143 | 2402 | jmorell | jLabel5.setBounds(6, 173, 192, 21); |
144 | 2689 | jmorell | jLabel5.setText(PluginServices.getText(this,"Numero_de_elementos_seleccionados") + ":"); |
145 | 2402 | jmorell | jLabel6.setBounds(202, 173, 39, 21); |
146 | jLabel6.setText("00");
|
||
147 | 2676 | jmorell | jLabel7.setBounds(6, 203, 127, 21); |
148 | jLabel7.setText(PluginServices.getText(this,"Cobertura_de_salida") + ":"); |
||
149 | 4270 | azabala | this.add(getFirstLayerCombo(), null); |
150 | this.add(getFirstSelectionCheck(), null); |
||
151 | 2402 | jmorell | this.add(getJButton(), null); |
152 | 4270 | azabala | this.add(getSecondLayerCombo(), null); |
153 | 2402 | jmorell | this.add(getJTextField(), null); |
154 | 4270 | azabala | this.add(getSecondSelectionCheck(), null); |
155 | 2402 | jmorell | 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 | 4270 | azabala | this.add(getNearestCheckbox(), null); |
164 | this.add(nearestLabel, null); |
||
165 | 2402 | jmorell | changeSelectedItemsJCheckBox(); |
166 | changeSelectedItemsJCheckBox1(); |
||
167 | changeSelectedItemsNumberJLabel(); |
||
168 | changeSelectedItemsNumberJLabel1(); |
||
169 | } |
||
170 | 4340 | azabala | |
171 | 2402 | jmorell | private void changeSelectedItemsJCheckBox() { |
172 | 4270 | azabala | FLyrVect inputSelectable = (FLyrVect)(layers.getLayer((String)firstLayerCombo.getSelectedItem()));
|
173 | 4065 | azabala | FBitSet fBitSet = inputSelectable.getRecordset().getSelection(); |
174 | 2402 | jmorell | if (fBitSet.cardinality()==0) { |
175 | 4270 | azabala | firstSelectionCheck.setEnabled(false);
|
176 | firstSelectionCheck.setSelected(false);
|
||
177 | 2402 | jmorell | } else {
|
178 | 4270 | azabala | firstSelectionCheck.setEnabled(true);
|
179 | firstSelectionCheck.setSelected(true);
|
||
180 | 2402 | jmorell | } |
181 | } |
||
182 | private void changeSelectedItemsJCheckBox1() { |
||
183 | 4270 | azabala | FLyrVect inputSelectable = (FLyrVect)(layers.getLayer((String)secondLayerCombo.getSelectedItem()));
|
184 | 4065 | azabala | FBitSet fBitSet = inputSelectable.getRecordset().getSelection(); |
185 | 2402 | jmorell | if (fBitSet.cardinality()==0) { |
186 | 4270 | azabala | secondSelectionCheck.setEnabled(false);
|
187 | secondSelectionCheck.setSelected(false);
|
||
188 | 2402 | jmorell | } else {
|
189 | 4270 | azabala | secondSelectionCheck.setEnabled(true);
|
190 | secondSelectionCheck.setSelected(true);
|
||
191 | 2402 | jmorell | } |
192 | } |
||
193 | private void changeSelectedItemsNumberJLabel() { |
||
194 | 4270 | azabala | if (getFirstSelectionCheck().isSelected()) {
|
195 | FLyrVect inputSelectable = (FLyrVect)(layers.getLayer((String)firstLayerCombo.getSelectedItem()));
|
||
196 | 4065 | azabala | FBitSet fBitSet = inputSelectable.getRecordset().getSelection(); |
197 | 2402 | jmorell | jLabel3.setText(new Integer(fBitSet.cardinality()).toString()); |
198 | } else {
|
||
199 | 4270 | azabala | VectorialAdapter va = (VectorialAdapter)((SingleLayer)(layers.getLayer((String)firstLayerCombo.getSelectedItem()))).getSource();
|
200 | 2402 | jmorell | 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 | 4270 | azabala | if (getSecondSelectionCheck().isSelected()) {
|
210 | FLyrVect inputSelectable = (FLyrVect)(layers.getLayer((String)secondLayerCombo.getSelectedItem()));
|
||
211 | 4065 | azabala | FBitSet fBitSet = inputSelectable.getRecordset().getSelection(); |
212 | 2402 | jmorell | jLabel6.setText(new Integer(fBitSet.cardinality()).toString()); |
213 | } else {
|
||
214 | 4270 | azabala | VectorialAdapter va = (VectorialAdapter)((SingleLayer)(layers.getLayer((String)secondLayerCombo.getSelectedItem()))).getSource();
|
215 | 2402 | jmorell | 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 | 2676 | jmorell | jTextField.setBounds(139, 203, 194, 21); |
232 | 2402 | jmorell | } |
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 | 2676 | jmorell | jButton.setText(PluginServices.getText(this,"Abrir")); |
244 | 2402 | jmorell | jButton.addActionListener(new java.awt.event.ActionListener() {
|
245 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
246 | 4270 | azabala | openResultFileDialog(); |
247 | 2402 | jmorell | } |
248 | }); |
||
249 | 4270 | azabala | jButton.setBounds(337, 203, 76, 21); |
250 | 2402 | jmorell | } |
251 | return jButton;
|
||
252 | } |
||
253 | /**
|
||
254 | 4270 | azabala | * This method initializes firstLayerCombo
|
255 | 2402 | jmorell | *
|
256 | * @return javax.swing.JComboBox
|
||
257 | */
|
||
258 | 4270 | azabala | private JComboBox getFirstLayerCombo() { |
259 | if (firstLayerCombo == null) { |
||
260 | firstLayerCombo = new JComboBox(); |
||
261 | 2402 | jmorell | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames()); |
262 | 4270 | azabala | firstLayerCombo.setModel(defaultModel); |
263 | firstLayerCombo.setBounds(138, 40, 260, 21); |
||
264 | firstLayerCombo.addItemListener(new java.awt.event.ItemListener() {
|
||
265 | 2402 | jmorell | public void itemStateChanged(java.awt.event.ItemEvent e) { |
266 | changeSelectedItemsJCheckBox(); |
||
267 | changeSelectedItemsNumberJLabel(); |
||
268 | } |
||
269 | }); |
||
270 | } |
||
271 | 4270 | azabala | return firstLayerCombo;
|
272 | 2402 | jmorell | } |
273 | /**
|
||
274 | 4270 | azabala | * This method initializes firstSelectionCheck
|
275 | 2402 | jmorell | *
|
276 | * @return javax.swing.JCheckBox
|
||
277 | */
|
||
278 | 4270 | azabala | 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 | 2402 | jmorell | public void itemStateChanged(java.awt.event.ItemEvent e) { |
284 | 4270 | azabala | firstLayerSelectionChecked(firstSelectionCheck.isSelected()); |
285 | 2402 | jmorell | } |
286 | }); |
||
287 | 4270 | azabala | firstSelectionCheck.setBounds(6, 66, 264, 21); |
288 | 2402 | jmorell | } |
289 | 4270 | azabala | return firstSelectionCheck;
|
290 | 2402 | jmorell | } |
291 | /**
|
||
292 | 4270 | azabala | * This method initializes secondLayerCombo
|
293 | 2402 | jmorell | *
|
294 | * @return javax.swing.JComboBox
|
||
295 | */
|
||
296 | 4270 | azabala | private JComboBox getSecondLayerCombo() { |
297 | if (secondLayerCombo == null) { |
||
298 | secondLayerCombo = new JComboBox(); |
||
299 | 2402 | jmorell | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames()); |
300 | 4270 | azabala | secondLayerCombo.setModel(defaultModel); |
301 | secondLayerCombo.setBounds(136, 122, 262, 21); |
||
302 | secondLayerCombo.addItemListener(new java.awt.event.ItemListener() {
|
||
303 | 2402 | jmorell | public void itemStateChanged(java.awt.event.ItemEvent e) { |
304 | changeSelectedItemsJCheckBox1(); |
||
305 | changeSelectedItemsNumberJLabel1(); |
||
306 | } |
||
307 | }); |
||
308 | } |
||
309 | 4270 | azabala | return secondLayerCombo;
|
310 | 2402 | jmorell | } |
311 | /**
|
||
312 | 4270 | azabala | * This method initializes secondSelectionCheck
|
313 | 2402 | jmorell | *
|
314 | * @return javax.swing.JCheckBox
|
||
315 | */
|
||
316 | 4270 | azabala | 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 | 2402 | jmorell | public void itemStateChanged(java.awt.event.ItemEvent e) { |
322 | 4270 | azabala | secondLayerSelectionChecked(secondSelectionCheck.isSelected()); |
323 | 2402 | jmorell | } |
324 | }); |
||
325 | 4270 | azabala | secondSelectionCheck.setBounds(6, 149, 264, 21); |
326 | 2402 | jmorell | } |
327 | 4270 | azabala | return secondSelectionCheck;
|
328 | 2402 | jmorell | } |
329 | /**
|
||
330 | * @return Returns the outputFile.
|
||
331 | */
|
||
332 | public File getOutputFile() { |
||
333 | return outputFile;
|
||
334 | } |
||
335 | 4270 | azabala | /**
|
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 | 2402 | jmorell | } // @jve:decl-index=0:visual-constraint="10,10" |