root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / merge / gui / GeoProcessingMergePanel.java @ 6877
History | View | Annotate | Download (23.9 KB)
1 | 5918 | azabala | /*
|
---|---|---|---|
2 | * Created on 14-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.cit.gvsig.geoprocess.impl.merge.gui; |
||
45 | |||
46 | import java.awt.Component; |
||
47 | import java.awt.event.ActionEvent; |
||
48 | import java.awt.event.ActionListener; |
||
49 | import java.io.File; |
||
50 | import java.io.FilenameFilter; |
||
51 | import java.io.IOException; |
||
52 | import java.util.ArrayList; |
||
53 | |||
54 | import javax.swing.AbstractListModel; |
||
55 | import javax.swing.DefaultComboBoxModel; |
||
56 | 6749 | azabala | import org.gvsig.gui.beans.swing.JButton; |
57 | 5918 | azabala | import javax.swing.JComboBox; |
58 | import javax.swing.JFileChooser; |
||
59 | import javax.swing.JLabel; |
||
60 | import javax.swing.JList; |
||
61 | 6489 | azabala | import javax.swing.JPanel; |
62 | 5918 | azabala | import javax.swing.JScrollPane; |
63 | import javax.swing.JTextField; |
||
64 | import javax.swing.event.ListSelectionListener; |
||
65 | |||
66 | import org.cresques.cts.IProjection; |
||
67 | |||
68 | import com.iver.andami.PluginServices; |
||
69 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
70 | 5918 | azabala | import com.iver.andami.ui.mdiManager.ViewInfo; |
71 | import com.iver.cit.gvsig.fmap.DriverException; |
||
72 | import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
||
73 | import com.iver.cit.gvsig.fmap.drivers.dgn.DgnMemoryDriver; |
||
74 | import com.iver.cit.gvsig.fmap.drivers.dxf.DXFMemoryDriver; |
||
75 | import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver; |
||
76 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
77 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
78 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
||
79 | import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
||
80 | import com.iver.cit.gvsig.geoprocess.core.gui.AbstractGeoprocessPanel; |
||
81 | import com.iver.utiles.GenericFileFilter; |
||
82 | 6749 | azabala | import java.awt.GridBagLayout; |
83 | import java.awt.GridBagConstraints; |
||
84 | 5918 | azabala | /**
|
85 | * GUI component to that allows user entrys to launch
|
||
86 | * a Merge geoprocess.
|
||
87 | *
|
||
88 | * @author azabala
|
||
89 | *
|
||
90 | */
|
||
91 | public class GeoProcessingMergePanel |
||
92 | extends AbstractGeoprocessPanel implements MergePanelIF, |
||
93 | 6877 | cesar | IWindow{ |
94 | 5918 | azabala | |
95 | private static final long serialVersionUID = 1L; |
||
96 | private JLabel titleJLabel = null; |
||
97 | private JScrollPane inputJScrollPane = null; |
||
98 | /**
|
||
99 | * It has a list with all FLyrVect of TOC
|
||
100 | */
|
||
101 | private JList inputJList = null; |
||
102 | /**
|
||
103 | * Combo box to select which layer of the user selection
|
||
104 | * will preserve its schema
|
||
105 | */
|
||
106 | private JComboBox fieldsJComboBox = null; |
||
107 | private JButton outputJButton = null; |
||
108 | private JButton directoryButton = null; |
||
109 | |||
110 | //layers selected to merge
|
||
111 | private FLyrVect[] layersSelected = null; |
||
112 | private File outputFile = null; |
||
113 | |||
114 | //user could specify a directory where look for new layers
|
||
115 | //files to add
|
||
116 | private FLyrVect[] aditionalLayers; |
||
117 | private String[] inputLayersToAdd; |
||
118 | private JScrollPane directoryLayerScrollPane = null; |
||
119 | /**
|
||
120 | * It has a list with all the FLyrVect in the directory
|
||
121 | * selected by the user
|
||
122 | */
|
||
123 | private JList directoryLayerList = null; |
||
124 | |||
125 | private FLyrVect[] aditionalLayersSelection = null; |
||
126 | |||
127 | private ViewInfo viewInfo;
|
||
128 | private JPanel resultLayerPanel = null; |
||
129 | private JLabel jLabel = null; |
||
130 | private JPanel resultSchemaPanel = null; |
||
131 | private JLabel jLabel1 = null; |
||
132 | private JPanel directoryPanel = null; |
||
133 | private JLabel directoryLabel = null; |
||
134 | private JPanel inputLyrPanel = null; |
||
135 | private JLabel jLabel2 = null; |
||
136 | /**
|
||
137 | * This constructor initializes the set of layers
|
||
138 | */
|
||
139 | public GeoProcessingMergePanel(FLayers layers) {
|
||
140 | super();
|
||
141 | this.layers = layers;
|
||
142 | initialize(); |
||
143 | } |
||
144 | |||
145 | /**
|
||
146 | * This method initializes this
|
||
147 | *
|
||
148 | * @return void
|
||
149 | */
|
||
150 | private void initialize() { |
||
151 | 6749 | azabala | GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); |
152 | gridBagConstraints4.insets = new java.awt.Insets(4,7,0,33); |
||
153 | gridBagConstraints4.gridy = 1;
|
||
154 | gridBagConstraints4.ipadx = 445;
|
||
155 | gridBagConstraints4.ipady = 91;
|
||
156 | gridBagConstraints4.gridx = 0;
|
||
157 | GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
||
158 | gridBagConstraints3.insets = new java.awt.Insets(1,7,3,33); |
||
159 | gridBagConstraints3.gridy = 2;
|
||
160 | gridBagConstraints3.ipadx = 445;
|
||
161 | gridBagConstraints3.ipady = 122;
|
||
162 | gridBagConstraints3.gridx = 0;
|
||
163 | GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
||
164 | gridBagConstraints2.insets = new java.awt.Insets(3,9,1,31); |
||
165 | gridBagConstraints2.gridy = 3;
|
||
166 | gridBagConstraints2.ipadx = 445;
|
||
167 | gridBagConstraints2.ipady = 35;
|
||
168 | gridBagConstraints2.gridx = 0;
|
||
169 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
||
170 | gridBagConstraints1.insets = new java.awt.Insets(1,9,42,31); |
||
171 | gridBagConstraints1.gridy = 4;
|
||
172 | gridBagConstraints1.ipadx = 445;
|
||
173 | gridBagConstraints1.ipady = 35;
|
||
174 | gridBagConstraints1.gridx = 0;
|
||
175 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
||
176 | gridBagConstraints.insets = new java.awt.Insets(10,8,3,31); |
||
177 | gridBagConstraints.gridy = 0;
|
||
178 | gridBagConstraints.ipadx = 266;
|
||
179 | gridBagConstraints.ipady = 6;
|
||
180 | gridBagConstraints.gridx = 0;
|
||
181 | 5918 | azabala | titleJLabel = new JLabel(); |
182 | titleJLabel.setText(PluginServices.getText(this,"Juntar._Introduccion_de_datos") + ":"); |
||
183 | 6749 | azabala | this.setLayout(new GridBagLayout()); |
184 | this.setSize(486,377); |
||
185 | // this.setBounds(new java.awt.Rectangle(0,0,486,377));
|
||
186 | this.add(titleJLabel, gridBagConstraints);
|
||
187 | this.add(getResultLayerPanel(), gridBagConstraints1);
|
||
188 | this.add(getResultSchemaPanel(), gridBagConstraints2);
|
||
189 | this.add(getDirectoryPanel(), gridBagConstraints3);
|
||
190 | this.add(getInputLyrPanel(), gridBagConstraints4);
|
||
191 | 5918 | azabala | } |
192 | |||
193 | private void setDirectoryLabelText(String text){ |
||
194 | directoryLabel.setText(text); |
||
195 | } |
||
196 | |||
197 | /**
|
||
198 | * Returns an array with names of all vectorial layers in TOC
|
||
199 | */
|
||
200 | protected String[] getLayerNames() { |
||
201 | String[] solution = null; |
||
202 | ArrayList layerNames = new ArrayList(); |
||
203 | for (int i=0;i<layers.getLayersCount();i++) { |
||
204 | FLayer layer = layers.getLayer(i); |
||
205 | if(! (layer instanceof FLyrVect)) |
||
206 | continue;
|
||
207 | layerNames.add(layer.getName()); |
||
208 | } |
||
209 | solution = new String[layerNames.size()]; |
||
210 | layerNames.toArray(solution); |
||
211 | return solution;
|
||
212 | } |
||
213 | |||
214 | |||
215 | protected String[] getDirectoryLayerNames(){ |
||
216 | String[] solution = null; |
||
217 | ArrayList layerNames = new ArrayList(); |
||
218 | if(aditionalLayers != null){ |
||
219 | for(int i = 0; i < aditionalLayers.length; i++){ |
||
220 | layerNames.add(aditionalLayers[i].getName()); |
||
221 | }//for
|
||
222 | } |
||
223 | solution = new String[layerNames.size()]; |
||
224 | layerNames.toArray(solution); |
||
225 | return solution;
|
||
226 | } |
||
227 | |||
228 | private String[] getLayersSelectedNames() { |
||
229 | if(layersSelected == null && aditionalLayersSelection == null) |
||
230 | return null; |
||
231 | ArrayList solution = new ArrayList(); |
||
232 | if(layersSelected != null){ |
||
233 | for(int i = 0; i < layersSelected.length; i++){ |
||
234 | solution.add(layersSelected[i].getName()); |
||
235 | } |
||
236 | } |
||
237 | if(aditionalLayersSelection != null){ |
||
238 | for(int i = 0; i < aditionalLayersSelection.length; i++){ |
||
239 | solution.add(aditionalLayersSelection[i].getName()); |
||
240 | } |
||
241 | } |
||
242 | String[] layersSelectedNames = new String[solution.size()]; |
||
243 | solution.toArray(layersSelectedNames); |
||
244 | return layersSelectedNames;
|
||
245 | } |
||
246 | |||
247 | /**
|
||
248 | * This method initializes inputJScrollPane
|
||
249 | *
|
||
250 | * @return javax.swing.JScrollPane
|
||
251 | */
|
||
252 | private JScrollPane getInputJScrollPane() { |
||
253 | if (inputJScrollPane == null) { |
||
254 | inputJScrollPane = new JScrollPane(); |
||
255 | inputJScrollPane.setBounds(new java.awt.Rectangle(10,27,427,50)); |
||
256 | inputJScrollPane.setViewportView(getInputJList()); |
||
257 | } |
||
258 | return inputJScrollPane;
|
||
259 | } |
||
260 | |||
261 | /**
|
||
262 | * This method initializes inputJList
|
||
263 | *
|
||
264 | * @return javax.swing.JList
|
||
265 | */
|
||
266 | private JList getInputJList() { |
||
267 | if (inputJList == null) { |
||
268 | inputJList = new JList(getLayerNames()); |
||
269 | LayerSelectorListener layerSelectorListener = new LayerSelectorListener(layers);
|
||
270 | inputJList.addListSelectionListener(layerSelectorListener); |
||
271 | } |
||
272 | return inputJList;
|
||
273 | } |
||
274 | |||
275 | class AditionalLayersListModel extends AbstractListModel{ |
||
276 | private static final long serialVersionUID = 6123487908892908100L; |
||
277 | private FLyrVect[] layers; |
||
278 | |||
279 | AditionalLayersListModel(FLyrVect[] layers){
|
||
280 | this.layers = layers;
|
||
281 | } |
||
282 | public int getSize() { |
||
283 | if(layers != null){ |
||
284 | return layers.length;
|
||
285 | } |
||
286 | return 0; |
||
287 | } |
||
288 | |||
289 | public Object getElementAt(int position) { |
||
290 | if(layers != null){ |
||
291 | return layers[position].getName();
|
||
292 | } |
||
293 | return null; |
||
294 | } |
||
295 | } |
||
296 | /**
|
||
297 | * ListModel for input layer list (which has layers of the TOC)
|
||
298 | * @author azabala
|
||
299 | *
|
||
300 | */
|
||
301 | class LayersListModel extends AbstractListModel{ |
||
302 | private static final long serialVersionUID = 1L; |
||
303 | private FLayers layers;
|
||
304 | LayersListModel(FLayers layers){ |
||
305 | this.layers = layers;
|
||
306 | } |
||
307 | |||
308 | public int getSize() { |
||
309 | return layers.getLayersCount();
|
||
310 | } |
||
311 | |||
312 | public Object getElementAt(int arg0) { |
||
313 | if(arg0 < layers.getLayersCount())
|
||
314 | return layers.getLayer(arg0).getName();
|
||
315 | else{
|
||
316 | if(aditionalLayers == null) |
||
317 | return null; |
||
318 | else{
|
||
319 | FLyrVect layer = aditionalLayers[arg0 - layers.getLayersCount()]; |
||
320 | if(layer == null) |
||
321 | return ""; |
||
322 | else
|
||
323 | return layer.getName();
|
||
324 | }//else
|
||
325 | }//else
|
||
326 | }//getElementAt
|
||
327 | |||
328 | } |
||
329 | |||
330 | /**
|
||
331 | * Listens selection of layers in input layers list, and
|
||
332 | * refresh selected layers list
|
||
333 | * @author azabala
|
||
334 | *
|
||
335 | */
|
||
336 | private class LayerSelectorListener implements ListSelectionListener { |
||
337 | private FLayers layers;
|
||
338 | public LayerSelectorListener(FLayers layers) {
|
||
339 | this.layers = layers;
|
||
340 | } |
||
341 | public void valueChanged(javax.swing.event.ListSelectionEvent e) { |
||
342 | Object[] layersSelectedNames = inputJList.getSelectedValues(); |
||
343 | if(layersSelectedNames == null) |
||
344 | return;
|
||
345 | layersSelected = new FLyrVect[layersSelectedNames.length];
|
||
346 | for (int i=0;i<layersSelectedNames.length;i++) { |
||
347 | String layerString = (String) layersSelectedNames[i]; |
||
348 | FLyrVect lyr = (FLyrVect) layers.getLayer(layerString); |
||
349 | if(lyr != null) |
||
350 | layersSelected[i] = lyr; |
||
351 | } |
||
352 | //refresh combo box of schema preserve of layers
|
||
353 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayersSelectedNames()); |
||
354 | fieldsJComboBox.setModel(defaultModel); |
||
355 | }//valueChanged
|
||
356 | } |
||
357 | |||
358 | |||
359 | private class AditionalLayerSelectorListener implements ListSelectionListener { |
||
360 | private FLyrVect[] aditionalLayers; |
||
361 | public AditionalLayerSelectorListener(FLyrVect[] aditionalLayers) { |
||
362 | this.aditionalLayers = aditionalLayers;
|
||
363 | } |
||
364 | public void valueChanged(javax.swing.event.ListSelectionEvent e) { |
||
365 | Object[] layersSelectedNames = directoryLayerList.getSelectedValues(); |
||
366 | if(layersSelectedNames == null) |
||
367 | return;
|
||
368 | if(this.aditionalLayers == null) |
||
369 | return;
|
||
370 | aditionalLayersSelection = new FLyrVect[layersSelectedNames.length];
|
||
371 | for (int i=0;i<layersSelectedNames.length;i++) { |
||
372 | String selection = (String) layersSelectedNames[i]; |
||
373 | for(int j = 0; j < this.aditionalLayers.length; j++){ |
||
374 | if(this.aditionalLayers[j].getName().equals(selection)){ |
||
375 | aditionalLayersSelection[i] = this.aditionalLayers[j];
|
||
376 | break;
|
||
377 | }//if
|
||
378 | }//for
|
||
379 | }//for
|
||
380 | //Any time user add a layer to aditional layers list,
|
||
381 | //we create a new comboboxmodel, to add this layers to the
|
||
382 | //schema presevation combo box
|
||
383 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayersSelectedNames()); |
||
384 | fieldsJComboBox.setModel(defaultModel); |
||
385 | }//valueChanged
|
||
386 | } |
||
387 | |||
388 | /**
|
||
389 | * This method initializes fieldsJComboBox
|
||
390 | *
|
||
391 | * @return javax.swing.JComboBox
|
||
392 | */
|
||
393 | private JComboBox getFieldsJComboBox() { |
||
394 | if (fieldsJComboBox == null) { |
||
395 | fieldsJComboBox = new JComboBox(); |
||
396 | fieldsJComboBox.setBounds(new java.awt.Rectangle(225,6,191,23)); |
||
397 | } |
||
398 | return fieldsJComboBox;
|
||
399 | } |
||
400 | |||
401 | /**
|
||
402 | 6489 | azabala | * This method initializes fileNameResultTextField
|
403 | 5918 | azabala | *
|
404 | * @return javax.swing.JTextField
|
||
405 | */
|
||
406 | 6110 | azabala | public JTextField getFileNameResultTextField() { |
407 | 6489 | azabala | if (fileNameResultTextField == null) { |
408 | super.getFileNameResultTextField().
|
||
409 | setBounds(new java.awt.Rectangle(134,7, |
||
410 | 194,22)); |
||
411 | 5918 | azabala | } |
412 | 6489 | azabala | return fileNameResultTextField;
|
413 | 5918 | azabala | } |
414 | |||
415 | /**
|
||
416 | * This method initializes outputJButton
|
||
417 | *
|
||
418 | * @return javax.swing.JButton
|
||
419 | */
|
||
420 | private JButton getOutputJButton() { |
||
421 | if (outputJButton == null) { |
||
422 | outputJButton = new JButton(); |
||
423 | outputJButton.setText(PluginServices.getText(this,"Abrir")); |
||
424 | outputJButton.setBounds(new java.awt.Rectangle(334,5,104,26)); |
||
425 | outputJButton.addActionListener(new java.awt.event.ActionListener() {
|
||
426 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
427 | openResultFileDialog(); |
||
428 | } |
||
429 | }); |
||
430 | } |
||
431 | return outputJButton;
|
||
432 | } |
||
433 | 6489 | azabala | |
434 | 5918 | azabala | /**
|
435 | * This method initializes directoryButton
|
||
436 | *
|
||
437 | * @return javax.swing.JButton
|
||
438 | */
|
||
439 | private JButton getDirectoryButton() { |
||
440 | if (directoryButton == null) { |
||
441 | directoryButton = new JButton(); |
||
442 | directoryButton.setText(PluginServices.getText(this,"Seleccionar_Directorio")); |
||
443 | directoryButton.setBounds(new java.awt.Rectangle(136,91,183,26)); |
||
444 | directoryButton.addActionListener(new ActionListener(){ |
||
445 | public void actionPerformed(ActionEvent arg0) { |
||
446 | openDirectoryLayersDialog(); |
||
447 | }}); |
||
448 | } |
||
449 | return directoryButton;
|
||
450 | } |
||
451 | |||
452 | public FLyrVect[] getSelectedLayers() { |
||
453 | FLyrVect[] solution = null; |
||
454 | String[] selectedNames = this.getLayersSelectedNames(); |
||
455 | 6492 | azabala | if(selectedNames == null){ |
456 | return null; |
||
457 | } |
||
458 | 5918 | azabala | ArrayList loadedSelectedLayers = new ArrayList(); |
459 | for(int i = 0; i < selectedNames.length; i++){ |
||
460 | String name = selectedNames[i];
|
||
461 | FLyrVect layer = (FLyrVect) layers.getLayer(name); |
||
462 | if(layer == null){ |
||
463 | //it is a directory layer
|
||
464 | for(int j = 0; j < aditionalLayers.length; j++){ |
||
465 | FLyrVect aditional = aditionalLayers[j]; |
||
466 | if(name.equals(aditional.getName())){
|
||
467 | layer = aditional; |
||
468 | }//
|
||
469 | }//fir
|
||
470 | }//if
|
||
471 | if(layer != null) |
||
472 | loadedSelectedLayers.add(layer); |
||
473 | }//for
|
||
474 | solution = new FLyrVect[loadedSelectedLayers.size()];
|
||
475 | loadedSelectedLayers.toArray(solution); |
||
476 | return solution;
|
||
477 | } |
||
478 | |||
479 | |||
480 | public void addLayersToMergeList(FLyrVect[] layers) { |
||
481 | // TODO Auto-generated method stub
|
||
482 | |||
483 | } |
||
484 | |||
485 | public FLyrVect getSelectedSchema() {
|
||
486 | FLyrVect solution = null;
|
||
487 | String layerName = (String) fieldsJComboBox.getSelectedItem(); |
||
488 | 6525 | azabala | if(layerName == null) |
489 | return null; |
||
490 | 5918 | azabala | solution = (FLyrVect) layers.getLayer(layerName); |
491 | if (solution == null){ |
||
492 | //see if it is an aditionallayer
|
||
493 | for(int i = 0; i < aditionalLayers.length; i++){ |
||
494 | FLyrVect layer = aditionalLayers[i]; |
||
495 | if(layer.getName() == layerName)
|
||
496 | solution = layer; |
||
497 | } |
||
498 | } |
||
499 | return solution;
|
||
500 | } |
||
501 | /**
|
||
502 | * This method is called every time user add new layers to directory layers
|
||
503 | * list
|
||
504 | */
|
||
505 | |||
506 | public void layersSelected() { |
||
507 | LayerSelectorListener layerSelectorListener = new LayerSelectorListener(layers);
|
||
508 | inputJList.addListSelectionListener(layerSelectorListener); |
||
509 | LayersListModel model = new LayersListModel(layers);
|
||
510 | inputJList.setModel(model); |
||
511 | AditionalLayerSelectorListener aditionalListener = new
|
||
512 | AditionalLayerSelectorListener(aditionalLayers); |
||
513 | directoryLayerList.addListSelectionListener(aditionalListener); |
||
514 | AditionalLayersListModel aditionalListModel = |
||
515 | new AditionalLayersListModel(aditionalLayers);
|
||
516 | directoryLayerList.setModel(aditionalListModel); |
||
517 | } |
||
518 | |||
519 | public void openResultFileDialog() { |
||
520 | JFileChooser jfc = new JFileChooser(); |
||
521 | jfc.addChoosableFileFilter( |
||
522 | new GenericFileFilter("shp", |
||
523 | PluginServices.getText(this,
|
||
524 | "Ficheros_SHP")));
|
||
525 | if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
||
526 | File file = jfc.getSelectedFile();
|
||
527 | if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){ |
||
528 | file = new File(file.getPath()+".shp"); |
||
529 | } |
||
530 | outputFile = file; |
||
531 | } |
||
532 | 6110 | azabala | if (jfc.getSelectedFile()!=null) getFileNameResultTextField().setText(jfc.getSelectedFile().getAbsolutePath()); |
533 | 5918 | azabala | } |
534 | |||
535 | public void openDirectoryLayersDialog() { |
||
536 | JFileChooser jfc = new JFileChooser(); |
||
537 | jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
||
538 | final String[] extensions = {"shp", "dxf", "dwg"}; |
||
539 | jfc.addChoosableFileFilter( |
||
540 | new GenericFileFilter(extensions,
|
||
541 | PluginServices.getText(this, "Ficheros_de_cartografia"))); |
||
542 | if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
||
543 | File file = jfc.getSelectedFile();
|
||
544 | FLyrVect[] newlayers = loadLayersInDirectory(file, extensions);
|
||
545 | setDirectoryLabelText("Capas del directorio: " + file.getName());
|
||
546 | this.aditionalLayers = newlayers;
|
||
547 | } |
||
548 | layersSelected(); |
||
549 | } |
||
550 | |||
551 | public FLyrVect[] loadLayersInDirectory(File file, final String[] extensions) { |
||
552 | if(file.isDirectory()){
|
||
553 | inputLayersToAdd = file.list( |
||
554 | new FilenameFilter() { |
||
555 | public boolean accept(File dir, String name) { |
||
556 | for(int i = 0; i < extensions.length; i++){ |
||
557 | if(name.endsWith(extensions[i]))
|
||
558 | return true; |
||
559 | }//for
|
||
560 | return false; |
||
561 | }//acept
|
||
562 | }); |
||
563 | }else{
|
||
564 | inputLayersToAdd = new String[]{file.getAbsolutePath()}; |
||
565 | } |
||
566 | |||
567 | FLyrVect[] solution = null; |
||
568 | if(inputLayersToAdd == null) |
||
569 | return solution;
|
||
570 | else
|
||
571 | solution = new FLyrVect[inputLayersToAdd.length];
|
||
572 | //sin florituras. cogemos la primera que haya
|
||
573 | IProjection projection = layers.getLayer(0).getProjection();
|
||
574 | DgnMemoryDriver dgnDriver = null;
|
||
575 | IndexedShpDriver shpDriver = null;
|
||
576 | DXFMemoryDriver dxfDriver = null;
|
||
577 | VectorialFileDriver driver = null;
|
||
578 | try {
|
||
579 | for(int i = 0; i < inputLayersToAdd.length; i++){ |
||
580 | String fileName = inputLayersToAdd[i];
|
||
581 | String fullPath = file.getAbsolutePath() + "/" + fileName; |
||
582 | File afile = new File(fullPath); |
||
583 | if(fileName.endsWith("dxf") || fileName.endsWith("DXF")){ |
||
584 | dxfDriver = new DXFMemoryDriver();
|
||
585 | dxfDriver.open(afile); |
||
586 | dxfDriver.initialize(); |
||
587 | driver = dxfDriver; |
||
588 | }else if (fileName.endsWith("shp") || fileName.endsWith("SHP")){ |
||
589 | shpDriver = new IndexedShpDriver();
|
||
590 | shpDriver.open(afile); |
||
591 | shpDriver.initialize(); |
||
592 | driver = shpDriver; |
||
593 | }else if (fileName.endsWith("dgn") || fileName.endsWith("DGN")){ |
||
594 | dgnDriver = new DgnMemoryDriver();
|
||
595 | dgnDriver.open(afile); |
||
596 | dgnDriver.initialize(); |
||
597 | driver = dxfDriver; |
||
598 | } |
||
599 | solution[i] = (FLyrVect) LayerFactory.createLayer(fileName, |
||
600 | driver, |
||
601 | afile, |
||
602 | projection); |
||
603 | |||
604 | } |
||
605 | } catch (IOException e) { |
||
606 | // TODO Auto-generated catch block
|
||
607 | e.printStackTrace(); |
||
608 | } catch (DriverException e) {
|
||
609 | // TODO Auto-generated catch block
|
||
610 | e.printStackTrace(); |
||
611 | } |
||
612 | return solution;
|
||
613 | } |
||
614 | |||
615 | /**
|
||
616 | * This method initializes directoryLayerScrollPane
|
||
617 | *
|
||
618 | * @return javax.swing.JScrollPane
|
||
619 | */
|
||
620 | private JScrollPane getDirectoryLayerScrollPane() { |
||
621 | if (directoryLayerScrollPane == null) { |
||
622 | directoryLayerScrollPane = new JScrollPane(); |
||
623 | directoryLayerScrollPane.setBounds(new java.awt.Rectangle(10,29,428,59)); |
||
624 | directoryLayerScrollPane.setViewportView(getDirectoryLayerList()); |
||
625 | } |
||
626 | return directoryLayerScrollPane;
|
||
627 | } |
||
628 | |||
629 | /**
|
||
630 | * This method initializes directoryLayerList
|
||
631 | *
|
||
632 | * @return javax.swing.JList
|
||
633 | */
|
||
634 | private JList getDirectoryLayerList() { |
||
635 | if (directoryLayerList == null) { |
||
636 | directoryLayerList = new JList(getDirectoryLayerNames()); |
||
637 | AditionalLayerSelectorListener listener = |
||
638 | new AditionalLayerSelectorListener(aditionalLayers);
|
||
639 | directoryLayerList.addListSelectionListener(listener); |
||
640 | } |
||
641 | return directoryLayerList;
|
||
642 | } |
||
643 | |||
644 | public ViewInfo getViewInfo() {
|
||
645 | if (viewInfo == null) { |
||
646 | viewInfo = new ViewInfo(ViewInfo.MODALDIALOG);
|
||
647 | viewInfo.setTitle(PluginServices.getText(this,
|
||
648 | "Juntar"));
|
||
649 | } |
||
650 | return viewInfo;
|
||
651 | } |
||
652 | |||
653 | /**
|
||
654 | * This method initializes resultLayerPanel
|
||
655 | *
|
||
656 | * @return javax.swing.JPanel
|
||
657 | */
|
||
658 | private JPanel getResultLayerPanel() { |
||
659 | if (resultLayerPanel == null) { |
||
660 | jLabel = new JLabel(); |
||
661 | jLabel.setText(PluginServices.getText(this, "Cobertura_de_salida") + ":"); |
||
662 | jLabel.setBounds(new java.awt.Rectangle(2,5,128,26)); |
||
663 | resultLayerPanel = new JPanel(); |
||
664 | resultLayerPanel.setLayout(null);
|
||
665 | resultLayerPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED)); |
||
666 | resultLayerPanel.add(getOutputJButton(), null);
|
||
667 | 6110 | azabala | resultLayerPanel.add(getFileNameResultTextField(), null);
|
668 | 5918 | azabala | resultLayerPanel.add(jLabel, null);
|
669 | } |
||
670 | return resultLayerPanel;
|
||
671 | } |
||
672 | |||
673 | /**
|
||
674 | * This method initializes resultSchemaPanel
|
||
675 | *
|
||
676 | * @return javax.swing.JPanel
|
||
677 | */
|
||
678 | private JPanel getResultSchemaPanel() { |
||
679 | if (resultSchemaPanel == null) { |
||
680 | jLabel1 = new JLabel(); |
||
681 | jLabel1.setText(PluginServices.getText(this, "Usar_los_campos_de_la_capa") + ":"); |
||
682 | jLabel1.setBounds(new java.awt.Rectangle(11,5,203,25)); |
||
683 | resultSchemaPanel = new JPanel(); |
||
684 | resultSchemaPanel.setLayout(null);
|
||
685 | resultSchemaPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED)); |
||
686 | resultSchemaPanel.add(getFieldsJComboBox(), null);
|
||
687 | resultSchemaPanel.add(jLabel1, null);
|
||
688 | } |
||
689 | return resultSchemaPanel;
|
||
690 | } |
||
691 | |||
692 | /**
|
||
693 | * This method initializes directoryPanel
|
||
694 | *
|
||
695 | * @return javax.swing.JPanel
|
||
696 | */
|
||
697 | private JPanel getDirectoryPanel() { |
||
698 | if (directoryPanel == null) { |
||
699 | directoryLabel = new JLabel(); |
||
700 | directoryLabel.setText(PluginServices.getText(this, "Capas_del_directorio") + ":"); |
||
701 | directoryLabel.setBounds(new java.awt.Rectangle(9,5,429,19)); |
||
702 | directoryPanel = new JPanel(); |
||
703 | directoryPanel.setLayout(null);
|
||
704 | directoryPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED)); |
||
705 | directoryPanel.add(getDirectoryButton(), null);
|
||
706 | directoryPanel.add(getDirectoryLayerScrollPane(), null);
|
||
707 | directoryPanel.add(directoryLabel, null);
|
||
708 | } |
||
709 | return directoryPanel;
|
||
710 | } |
||
711 | |||
712 | /**
|
||
713 | * This method initializes inputLyrPanel
|
||
714 | *
|
||
715 | * @return javax.swing.JPanel
|
||
716 | */
|
||
717 | private JPanel getInputLyrPanel() { |
||
718 | if (inputLyrPanel == null) { |
||
719 | jLabel2 = new JLabel(); |
||
720 | jLabel2.setBounds(new java.awt.Rectangle(13,4,422,16)); |
||
721 | jLabel2.setText(PluginServices.getText(this, "Coberturas_de_entrada") + ":"); |
||
722 | inputLyrPanel = new JPanel(); |
||
723 | inputLyrPanel.setLayout(null);
|
||
724 | inputLyrPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED)); |
||
725 | inputLyrPanel.add(getInputJScrollPane(), null);
|
||
726 | inputLyrPanel.add(jLabel2, null);
|
||
727 | } |
||
728 | return inputLyrPanel;
|
||
729 | } |
||
730 | |||
731 | } // @jve:decl-index=0:visual-constraint="18,18" |