svn-gvsig-desktop / branches / v10 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / merge / gui / GeoProcessingMergePanel2.java @ 7577
History | View | Annotate | Download (22 KB)
1 |
/*
|
---|---|
2 |
* Created on 08-ago-2006
|
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 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: GeoProcessingMergePanel2.java 7577 2006-09-25 17:57:31Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.1.2.1 2006-09-25 17:57:31 azabala
|
49 |
* when "merge layers in directory" finds a corrupt data file, it ignores it and continues looking for cartographic data files.
|
50 |
*
|
51 |
* Revision 1.1 2006/08/11 16:30:38 azabala
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
*
|
55 |
*/
|
56 |
package com.iver.cit.gvsig.geoprocess.impl.merge.gui; |
57 |
|
58 |
import java.awt.BorderLayout; |
59 |
import java.awt.Component; |
60 |
import java.awt.Dimension; |
61 |
import java.awt.GridBagConstraints; |
62 |
import java.awt.Insets; |
63 |
import java.awt.event.ActionEvent; |
64 |
import java.awt.event.ActionListener; |
65 |
import java.io.File; |
66 |
import java.io.FileNotFoundException; |
67 |
import java.io.FilenameFilter; |
68 |
import java.io.IOException; |
69 |
import java.util.ArrayList; |
70 |
import java.util.Arrays; |
71 |
|
72 |
import javax.swing.AbstractListModel; |
73 |
import javax.swing.BorderFactory; |
74 |
import javax.swing.DefaultComboBoxModel; |
75 |
import javax.swing.JComboBox; |
76 |
import javax.swing.JFileChooser; |
77 |
import javax.swing.JLabel; |
78 |
import javax.swing.JList; |
79 |
import javax.swing.JOptionPane; |
80 |
import javax.swing.JPanel; |
81 |
import javax.swing.JScrollPane; |
82 |
import javax.swing.JTextField; |
83 |
import javax.swing.border.EtchedBorder; |
84 |
import javax.swing.event.ListSelectionListener; |
85 |
|
86 |
import org.cresques.cts.IProjection; |
87 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
88 |
import org.gvsig.gui.beans.swing.JButton; |
89 |
|
90 |
import com.iver.andami.PluginServices; |
91 |
import com.iver.cit.gvsig.fmap.DriverException; |
92 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
93 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
94 |
import com.iver.cit.gvsig.fmap.drivers.dgn.DgnMemoryDriver; |
95 |
import com.iver.cit.gvsig.fmap.drivers.dxf.DXFMemoryDriver; |
96 |
import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver; |
97 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
98 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
99 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
100 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
101 |
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel; |
102 |
import com.iver.cit.gvsig.gui.thememanager.CreateSpatialIndexMonitorableTask; |
103 |
import com.iver.utiles.GenericFileFilter; |
104 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
105 |
|
106 |
public class GeoProcessingMergePanel2 extends GridBagLayoutPanel implements |
107 |
MergePanelIF , IGeoprocessPanel{ |
108 |
|
109 |
// input layers of the active view's TOC
|
110 |
private FLayers layers;
|
111 |
|
112 |
// layers selected to merge
|
113 |
private FLyrVect[] layersSelected; |
114 |
|
115 |
// layers not in the TOC but in the directory selected by user
|
116 |
private FLyrVect[] aditionalLayers; |
117 |
|
118 |
private String[] inputLayersToAdd; |
119 |
|
120 |
// Additional selected layers in second list
|
121 |
private FLyrVect[] aditionalLayersSelection; |
122 |
|
123 |
/*
|
124 |
* GUI CONTROLS
|
125 |
*/
|
126 |
private JList inputLayersList; |
127 |
|
128 |
private JComboBox fieldsJComboBox; |
129 |
|
130 |
private JLabel directoryLyrsLabel; |
131 |
|
132 |
private JList directoryLayerList; |
133 |
|
134 |
protected JTextField resultTf; |
135 |
|
136 |
|
137 |
/**
|
138 |
* Constructor
|
139 |
* @param layers
|
140 |
*/
|
141 |
public GeoProcessingMergePanel2(FLayers layers) {
|
142 |
super();
|
143 |
setFLayers(layers); |
144 |
initialize(); |
145 |
} |
146 |
|
147 |
private void initialize() { |
148 |
Insets insets = new Insets(5, 5, 5, 5); |
149 |
String titleText = PluginServices.getText(this, |
150 |
"Juntar._Introduccion_de_datos")
|
151 |
+ ":";
|
152 |
addComponent(new JLabel(titleText), insets); |
153 |
|
154 |
String inputLayerText = PluginServices.getText(this, |
155 |
"Cobertura_de_entrada")
|
156 |
+ ":";
|
157 |
addComponent(new JLabel(inputLayerText), insets); |
158 |
|
159 |
JScrollPane inputLayersScrollPane = new JScrollPane(); |
160 |
inputLayersList = new JList(getLayerNames()); |
161 |
LayerSelectorListener layerSelectorListener = new LayerSelectorListener(
|
162 |
layers); |
163 |
inputLayersList.addListSelectionListener(layerSelectorListener); |
164 |
inputLayersScrollPane.setViewportView(inputLayersList); |
165 |
inputLayersScrollPane.setBorder(BorderFactory
|
166 |
.createEtchedBorder(EtchedBorder.RAISED));
|
167 |
// If we dont do this, GridBagLayout wont resize well the scrollpane
|
168 |
inputLayersScrollPane.setPreferredSize(new Dimension(520, 110)); |
169 |
inputLayersScrollPane.setMinimumSize(new Dimension(520, 90)); |
170 |
int numRows = 2; |
171 |
addComponent(inputLayersScrollPane, |
172 |
insets, |
173 |
numRows); |
174 |
|
175 |
String directoryLayersText = PluginServices.getText(this, |
176 |
"Capas_del_directorio")
|
177 |
+ ":";
|
178 |
directoryLyrsLabel = new JLabel(directoryLayersText); |
179 |
addComponent(directoryLyrsLabel, insets); |
180 |
|
181 |
JButton directoryButton = new JButton(PluginServices.getText(this, |
182 |
"Seleccionar_Directorio"));
|
183 |
directoryButton.addActionListener(new ActionListener() { |
184 |
public void actionPerformed(ActionEvent arg0) { |
185 |
openDirectoryLayersDialog(); |
186 |
} |
187 |
}); |
188 |
addComponent(directoryButton, insets); |
189 |
|
190 |
JScrollPane directoryLayerScrollPane = new JScrollPane(); |
191 |
directoryLayerList = new JList(getDirectoryLayerNames()); |
192 |
AditionalLayerSelectorListener listener = new AditionalLayerSelectorListener(
|
193 |
aditionalLayers); |
194 |
directoryLayerList.addListSelectionListener(listener); |
195 |
directoryLayerScrollPane.setViewportView(directoryLayerList); |
196 |
directoryLayerScrollPane.setBorder(BorderFactory
|
197 |
.createEtchedBorder(EtchedBorder.RAISED));
|
198 |
|
199 |
//If we dont do this, GridBagLayout wont resize well the scrollpane
|
200 |
directoryLayerScrollPane.setPreferredSize(new Dimension(520, 110)); |
201 |
directoryLayerScrollPane.setMinimumSize(new Dimension(520, 90)); |
202 |
|
203 |
|
204 |
addComponent(directoryLayerScrollPane, insets, |
205 |
numRows ); |
206 |
|
207 |
|
208 |
JLabel resultSchemaLabel = new JLabel(PluginServices. |
209 |
getText(this, "Usar_los_campos_de_la_capa") + ":"); |
210 |
|
211 |
fieldsJComboBox = new JComboBox(); |
212 |
addComponent(resultSchemaLabel, |
213 |
fieldsJComboBox, |
214 |
GridBagConstraints.HORIZONTAL,
|
215 |
insets); |
216 |
|
217 |
|
218 |
//FIXME Create an open result layer control
|
219 |
JPanel aux = new JPanel(new BorderLayout()); |
220 |
String resultLayerText = PluginServices.
|
221 |
getText(this, "Cobertura_de_salida") + ":"; |
222 |
resultTf = new JTextField(30); |
223 |
JButton openResultButton = new JButton(); |
224 |
openResultButton.setText(PluginServices.getText(this, "Abrir")); |
225 |
openResultButton.addActionListener(new java.awt.event.ActionListener() {
|
226 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
227 |
openResultFile(); |
228 |
} |
229 |
} |
230 |
); |
231 |
aux.add(resultTf, BorderLayout.WEST);
|
232 |
aux.add(new JLabel(" "), BorderLayout.CENTER); |
233 |
aux.add(openResultButton, BorderLayout.EAST);
|
234 |
addComponent(resultLayerText, aux, GridBagConstraints.HORIZONTAL, insets );
|
235 |
} |
236 |
|
237 |
//FIXME Move this to an open result layer control
|
238 |
|
239 |
/**
|
240 |
* Opens a dialog to select where (file, database, etc)
|
241 |
* to save the result layer.
|
242 |
*
|
243 |
*/
|
244 |
public void openResultFile() { |
245 |
JFileChooser jfc = new JFileChooser(); |
246 |
jfc |
247 |
.addChoosableFileFilter(new GenericFileFilter("shp", |
248 |
"Ficheros SHP"));
|
249 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
250 |
File file = jfc.getSelectedFile();
|
251 |
if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith( |
252 |
".SHP"))) {
|
253 |
file = new File(file.getPath() + ".shp"); |
254 |
} |
255 |
}// if
|
256 |
if (jfc.getSelectedFile() != null) { |
257 |
resultTf.setText( |
258 |
jfc.getSelectedFile().getAbsolutePath()); |
259 |
} |
260 |
|
261 |
} |
262 |
|
263 |
|
264 |
public void setFLayers(FLayers layers) { |
265 |
this.layers = layers;
|
266 |
} |
267 |
|
268 |
public FLyrVect[] getSelectedLayers() { |
269 |
FLyrVect[] solution = null; |
270 |
String[] selectedNames = this.getLayersSelectedNames(); |
271 |
if (selectedNames == null) { |
272 |
return null; |
273 |
} |
274 |
ArrayList loadedSelectedLayers = new ArrayList(); |
275 |
for (int i = 0; i < selectedNames.length; i++) { |
276 |
String name = selectedNames[i];
|
277 |
FLyrVect layer = (FLyrVect) layers.getLayer(name); |
278 |
if (layer == null) { |
279 |
// it is a directory layer
|
280 |
for (int j = 0; j < aditionalLayers.length; j++) { |
281 |
FLyrVect aditional = aditionalLayers[j]; |
282 |
if (name.equals(aditional.getName())) {
|
283 |
layer = aditional; |
284 |
}//
|
285 |
}// fir
|
286 |
}// if
|
287 |
if (layer != null) |
288 |
loadedSelectedLayers.add(layer); |
289 |
}// for
|
290 |
solution = new FLyrVect[loadedSelectedLayers.size()];
|
291 |
loadedSelectedLayers.toArray(solution); |
292 |
return solution;
|
293 |
} |
294 |
|
295 |
public FLyrVect[] loadLayersInDirectory(File file, final String[] extensions) { |
296 |
if (file.isDirectory()) {
|
297 |
inputLayersToAdd = file.list(new FilenameFilter() { |
298 |
public boolean accept(File dir, String name) { |
299 |
for (int i = 0; i < extensions.length; i++) { |
300 |
if (name.endsWith(extensions[i]))
|
301 |
return true; |
302 |
}// for
|
303 |
return false; |
304 |
}// acept
|
305 |
}); |
306 |
} else {
|
307 |
inputLayersToAdd = new String[] { file.getAbsolutePath() }; |
308 |
} |
309 |
|
310 |
FLyrVect[] solution = null; |
311 |
ArrayList newLyrList = new ArrayList(); |
312 |
if (inputLayersToAdd == null) |
313 |
return solution;
|
314 |
|
315 |
// sin florituras. cogemos la primera que haya
|
316 |
IProjection projection = layers.getLayer(0).getProjection();
|
317 |
DgnMemoryDriver dgnDriver = null;
|
318 |
IndexedShpDriver shpDriver = null;
|
319 |
DXFMemoryDriver dxfDriver = null;
|
320 |
VectorialFileDriver driver = null;
|
321 |
|
322 |
for (int i = 0; i < inputLayersToAdd.length; i++) { |
323 |
String fileName = inputLayersToAdd[i];
|
324 |
String fullPath = file.getAbsolutePath() + "/" + fileName; |
325 |
File afile = new File(fullPath); |
326 |
|
327 |
try {
|
328 |
if (fileName.endsWith("dxf") || fileName.endsWith("DXF")) { |
329 |
dxfDriver = new DXFMemoryDriver();
|
330 |
dxfDriver.open(afile); |
331 |
dxfDriver.initialize(); |
332 |
driver = dxfDriver; |
333 |
} else if (fileName.endsWith("shp") || fileName.endsWith("SHP")) { |
334 |
shpDriver = new IndexedShpDriver();
|
335 |
shpDriver.open(afile); |
336 |
shpDriver.initialize(); |
337 |
driver = shpDriver; |
338 |
} else if (fileName.endsWith("dgn") || fileName.endsWith("DGN")) { |
339 |
dgnDriver = new DgnMemoryDriver();
|
340 |
dgnDriver.open(afile); |
341 |
dgnDriver.initialize(); |
342 |
driver = dxfDriver; |
343 |
} |
344 |
newLyrList.add((FLyrVect) LayerFactory. |
345 |
createLayer(fileName, |
346 |
driver, |
347 |
afile, |
348 |
projection)); |
349 |
|
350 |
} catch(Exception e){ |
351 |
//TODO Estos errores habr?a que notificarlos al usuario
|
352 |
//de forma amigable.
|
353 |
//we catch any possible (and not declared) exception, because we dont know
|
354 |
//the correctness of file layers (for example, shp without dbf, etc)
|
355 |
e.printStackTrace(); |
356 |
} |
357 |
|
358 |
} |
359 |
|
360 |
solution = new FLyrVect[newLyrList.size()];
|
361 |
newLyrList.toArray(solution); |
362 |
return solution;
|
363 |
} |
364 |
|
365 |
public void addLayersToMergeList(FLyrVect[] layers) { |
366 |
// TODO Auto-generated method stub
|
367 |
|
368 |
} |
369 |
|
370 |
public FLyrVect getSelectedSchema() {
|
371 |
FLyrVect solution = null;
|
372 |
String layerName = (String) fieldsJComboBox.getSelectedItem(); |
373 |
if(layerName == null) |
374 |
return null; |
375 |
solution = (FLyrVect) layers.getLayer(layerName); |
376 |
if (solution == null){ |
377 |
//see if it is an aditionallayer
|
378 |
for(int i = 0; i < aditionalLayers.length; i++){ |
379 |
FLyrVect layer = aditionalLayers[i]; |
380 |
if(layer.getName() == layerName)
|
381 |
solution = layer; |
382 |
} |
383 |
} |
384 |
return solution;
|
385 |
} |
386 |
|
387 |
public void layersSelected() { |
388 |
LayerSelectorListener layerSelectorListener = new LayerSelectorListener(layers);
|
389 |
inputLayersList.addListSelectionListener(layerSelectorListener); |
390 |
LayersListModel model = new LayersListModel(layers);
|
391 |
inputLayersList.setModel(model); |
392 |
AditionalLayerSelectorListener aditionalListener = new
|
393 |
AditionalLayerSelectorListener(aditionalLayers); |
394 |
directoryLayerList.addListSelectionListener(aditionalListener); |
395 |
AditionalLayersListModel aditionalListModel = |
396 |
new AditionalLayersListModel(aditionalLayers);
|
397 |
directoryLayerList.setModel(aditionalListModel); |
398 |
} |
399 |
|
400 |
public void openResultFileDialog() { |
401 |
openResultFile(); |
402 |
} |
403 |
|
404 |
/**
|
405 |
* Runs when user pushs Additional Layer button
|
406 |
*/
|
407 |
public void openDirectoryLayersDialog() { |
408 |
JFileChooser jfc = new JFileChooser(); |
409 |
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
410 |
final String[] extensions = { "shp", "dxf", "dwg" }; |
411 |
jfc.addChoosableFileFilter(new GenericFileFilter(extensions,
|
412 |
PluginServices.getText(this, "Ficheros_de_cartografia"))); |
413 |
if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
414 |
File file = jfc.getSelectedFile();
|
415 |
FLyrVect[] newlayers = loadLayersInDirectory(file, extensions);
|
416 |
String directoryLayersText = PluginServices.getText(this, |
417 |
"Capas_del_directorio")
|
418 |
+ ":";
|
419 |
directoryLayersText += file.getAbsolutePath(); |
420 |
directoryLyrsLabel.setText(directoryLayersText); |
421 |
|
422 |
this.aditionalLayers = newlayers;
|
423 |
} |
424 |
layersSelected(); |
425 |
} |
426 |
|
427 |
|
428 |
// mover a una utility class
|
429 |
protected String[] getLayerNames() { |
430 |
String[] solution = null; |
431 |
int numLayers = layers.getLayersCount();
|
432 |
if (layers != null && numLayers > 0) { |
433 |
ArrayList list = new ArrayList(); |
434 |
for (int i = 0; i < numLayers; i++) { |
435 |
FLayer layer = layers.getLayer(i); |
436 |
if (layer instanceof FLyrVect) |
437 |
list.add(layer.getName()); |
438 |
if (layer instanceof FLayers) { |
439 |
FLayers layers = (FLayers) layer; |
440 |
FLyrVect[] vectorials = getVectorialLayers(layers);
|
441 |
for (int j = 0; j < vectorials.length; j++) { |
442 |
list.add(vectorials[j].getName()); |
443 |
} |
444 |
} |
445 |
}// for
|
446 |
solution = new String[list.size()]; |
447 |
list.toArray(solution); |
448 |
} |
449 |
return solution;
|
450 |
} |
451 |
|
452 |
// FIXME mover a una utility class
|
453 |
protected FLyrVect[] getVectorialLayers(FLayers layers) { |
454 |
FLyrVect[] solution = null; |
455 |
ArrayList list = new ArrayList(); |
456 |
int numLayers = layers.getLayersCount();
|
457 |
for (int i = 0; i < numLayers; i++) { |
458 |
FLayer layer = layers.getLayer(i); |
459 |
if (layer instanceof FLyrVect) |
460 |
list.add(layer); |
461 |
else if (layer instanceof FLayers) |
462 |
list.addAll(Arrays.asList(getVectorialLayers((FLayers) layer)));
|
463 |
} |
464 |
solution = new FLyrVect[list.size()];
|
465 |
list.toArray(solution); |
466 |
return solution;
|
467 |
} |
468 |
|
469 |
protected String[] getDirectoryLayerNames() { |
470 |
String[] solution = null; |
471 |
ArrayList layerNames = new ArrayList(); |
472 |
if (aditionalLayers != null) { |
473 |
for (int i = 0; i < aditionalLayers.length; i++) { |
474 |
layerNames.add(aditionalLayers[i].getName()); |
475 |
}// for
|
476 |
} |
477 |
solution = new String[layerNames.size()]; |
478 |
layerNames.toArray(solution); |
479 |
return solution;
|
480 |
} |
481 |
|
482 |
private String[] getLayersSelectedNames() { |
483 |
if (layersSelected == null && aditionalLayersSelection == null) |
484 |
return null; |
485 |
ArrayList solution = new ArrayList(); |
486 |
if (layersSelected != null) { |
487 |
for (int i = 0; i < layersSelected.length; i++) { |
488 |
solution.add(layersSelected[i].getName()); |
489 |
} |
490 |
} |
491 |
if (aditionalLayersSelection != null) { |
492 |
for (int i = 0; i < aditionalLayersSelection.length; i++) { |
493 |
solution.add(aditionalLayersSelection[i].getName()); |
494 |
} |
495 |
} |
496 |
String[] layersSelectedNames = new String[solution.size()]; |
497 |
solution.toArray(layersSelectedNames); |
498 |
return layersSelectedNames;
|
499 |
} |
500 |
|
501 |
/**
|
502 |
* Listens selection of layers in input layers list, and refresh selected
|
503 |
* layers list
|
504 |
*
|
505 |
* @author azabala
|
506 |
*
|
507 |
*/
|
508 |
private class LayerSelectorListener implements ListSelectionListener { |
509 |
private FLayers layers;
|
510 |
|
511 |
public LayerSelectorListener(FLayers layers) {
|
512 |
this.layers = layers;
|
513 |
} |
514 |
|
515 |
public void valueChanged(javax.swing.event.ListSelectionEvent e) { |
516 |
Object[] layersSelectedNames = inputLayersList.getSelectedValues(); |
517 |
if (layersSelectedNames == null) |
518 |
return;
|
519 |
layersSelected = new FLyrVect[layersSelectedNames.length];
|
520 |
for (int i = 0; i < layersSelectedNames.length; i++) { |
521 |
String layerString = (String) layersSelectedNames[i]; |
522 |
FLyrVect lyr = (FLyrVect) layers.getLayer(layerString); |
523 |
if (lyr != null) |
524 |
layersSelected[i] = lyr; |
525 |
} |
526 |
// refresh combo box of schema preserve of layers
|
527 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel( |
528 |
getLayersSelectedNames()); |
529 |
fieldsJComboBox.setModel(defaultModel); |
530 |
}// valueChanged
|
531 |
} |
532 |
|
533 |
private class AditionalLayerSelectorListener implements |
534 |
ListSelectionListener {
|
535 |
private FLyrVect[] aditionalLayers; |
536 |
|
537 |
public AditionalLayerSelectorListener(FLyrVect[] aditionalLayers) { |
538 |
this.aditionalLayers = aditionalLayers;
|
539 |
} |
540 |
|
541 |
public void valueChanged(javax.swing.event.ListSelectionEvent e) { |
542 |
Object[] layersSelectedNames = directoryLayerList |
543 |
.getSelectedValues(); |
544 |
if (layersSelectedNames == null) |
545 |
return;
|
546 |
if (this.aditionalLayers == null) |
547 |
return;
|
548 |
aditionalLayersSelection = new FLyrVect[layersSelectedNames.length];
|
549 |
for (int i = 0; i < layersSelectedNames.length; i++) { |
550 |
String selection = (String) layersSelectedNames[i]; |
551 |
for (int j = 0; j < this.aditionalLayers.length; j++) { |
552 |
if (this.aditionalLayers[j].getName().equals(selection)) { |
553 |
aditionalLayersSelection[i] = this.aditionalLayers[j];
|
554 |
break;
|
555 |
}// if
|
556 |
}// for
|
557 |
}// for
|
558 |
// Any time user add a layer to aditional layers list,
|
559 |
// we create a new comboboxmodel, to add this layers to the
|
560 |
// schema presevation combo box
|
561 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel( |
562 |
getLayersSelectedNames()); |
563 |
fieldsJComboBox.setModel(defaultModel); |
564 |
}// valueChanged
|
565 |
} |
566 |
|
567 |
/**
|
568 |
* ListModel for input layer list (which has layers of the TOC)
|
569 |
* @author azabala
|
570 |
*
|
571 |
*/
|
572 |
class LayersListModel extends AbstractListModel{ |
573 |
private static final long serialVersionUID = 1L; |
574 |
private FLayers layers;
|
575 |
LayersListModel(FLayers layers){ |
576 |
this.layers = layers;
|
577 |
} |
578 |
|
579 |
public int getSize() { |
580 |
return layers.getLayersCount();
|
581 |
} |
582 |
|
583 |
public Object getElementAt(int arg0) { |
584 |
if(arg0 < layers.getLayersCount())
|
585 |
return layers.getLayer(arg0).getName();
|
586 |
else{
|
587 |
if(aditionalLayers == null) |
588 |
return null; |
589 |
else{
|
590 |
FLyrVect layer = aditionalLayers[arg0 - layers.getLayersCount()]; |
591 |
if(layer == null) |
592 |
return ""; |
593 |
else
|
594 |
return layer.getName();
|
595 |
}//else
|
596 |
}//else
|
597 |
}//getElementAt
|
598 |
} |
599 |
|
600 |
class AditionalLayersListModel extends AbstractListModel{ |
601 |
private static final long serialVersionUID = 6123487908892908100L; |
602 |
private FLyrVect[] layers; |
603 |
|
604 |
AditionalLayersListModel(FLyrVect[] layers){
|
605 |
this.layers = layers;
|
606 |
} |
607 |
public int getSize() { |
608 |
if(layers != null){ |
609 |
return layers.length;
|
610 |
} |
611 |
return 0; |
612 |
} |
613 |
|
614 |
public Object getElementAt(int position) { |
615 |
if(layers != null){ |
616 |
return layers[position].getName();
|
617 |
} |
618 |
return null; |
619 |
} |
620 |
} |
621 |
|
622 |
//FIXME Move to an abstract base class
|
623 |
public File getOutputFile() throws FileNotFoundException{ |
624 |
String fileName = resultTf.getText();
|
625 |
if(fileName.length() == 0){ |
626 |
throw new FileNotFoundException("No se ha seleccionado ningun fichero de salida"); |
627 |
} |
628 |
if(! fileName.endsWith(".shp")){ |
629 |
if(! fileName.endsWith(".")) |
630 |
fileName += ".";
|
631 |
fileName += "shp";
|
632 |
} |
633 |
return new File(fileName); |
634 |
} |
635 |
|
636 |
//FIXME Move to an abstract base class
|
637 |
/**
|
638 |
* Returns layers.
|
639 |
*
|
640 |
* @return
|
641 |
*/
|
642 |
public FLayers getFLayers() {
|
643 |
return layers;
|
644 |
} |
645 |
/**
|
646 |
* Shows to the user a dialog error, whith the title and message body
|
647 |
* specified as parameters.
|
648 |
*
|
649 |
* @param message
|
650 |
* body of the error message
|
651 |
* @param title
|
652 |
* title of the error message
|
653 |
*/
|
654 |
public void error(String message, String title) { |
655 |
JOptionPane.showMessageDialog(this, message, title, |
656 |
JOptionPane.ERROR_MESSAGE);
|
657 |
} |
658 |
/**
|
659 |
* Asks to the user for the creation of a spatial index for the specified
|
660 |
* layer. It will be of help for certain geoprocesses.
|
661 |
*
|
662 |
* FLyrVect default spatial index is MapServer quadtree, that hasnt the
|
663 |
* ability to do nearest neighbour searches.
|
664 |
*
|
665 |
* For those geoprocesses that needs it (NN searches) overwrite this method
|
666 |
* and use JSI RTree, or SIL RTree.
|
667 |
*
|
668 |
* It returns an IMonitorableTask, a task to build the spatial index in
|
669 |
* background.
|
670 |
*
|
671 |
* @param layer
|
672 |
* @return an ITask
|
673 |
*/
|
674 |
public IMonitorableTask askForSpatialIndexCreation(FLyrVect layer) {
|
675 |
String title = PluginServices.getText(this, "Crear_Indice"); |
676 |
String confirmDialogText = PluginServices.getText(this, |
677 |
"Crear_Indice_Pregunta_1")
|
678 |
+ " "
|
679 |
+ layer.getName() |
680 |
+ " "
|
681 |
+ PluginServices.getText(this, "Crear_Indice_Pregunta_2"); |
682 |
int option = JOptionPane.showConfirmDialog(this, confirmDialogText, |
683 |
title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, |
684 |
null);
|
685 |
if (option == JOptionPane.YES_OPTION) { |
686 |
// Usually we want task like spatial index creation dont block
|
687 |
// GUI responses. Now, we dont want to start geoprocess execution
|
688 |
// until spatial index creation would finish, to have advantage
|
689 |
// of the spatial index
|
690 |
try {
|
691 |
CreateSpatialIndexMonitorableTask task = new CreateSpatialIndexMonitorableTask(
|
692 |
layer); |
693 |
return task;
|
694 |
} catch (DriverIOException e) {
|
695 |
// TODO Auto-generated catch block
|
696 |
e.printStackTrace(); |
697 |
return null; |
698 |
} catch (DriverException e) {
|
699 |
// TODO Auto-generated catch block
|
700 |
e.printStackTrace(); |
701 |
return null; |
702 |
} |
703 |
} else
|
704 |
return null; |
705 |
|
706 |
} |
707 |
|
708 |
/**
|
709 |
* Confirm overwrite the output file if it allready exist.
|
710 |
*
|
711 |
*
|
712 |
* @param outputFile
|
713 |
* @return answer
|
714 |
*/
|
715 |
public boolean askForOverwriteOutputFile(File outputFile) { |
716 |
String title = PluginServices.getText(this, "Sobreescribir_fichero"); |
717 |
String confirmDialogText = PluginServices.getText(this, |
718 |
"Sobreescribir_fichero_Pregunta_1")
|
719 |
+ "\n'"
|
720 |
+ outputFile.getAbsolutePath() |
721 |
+ "'\n"
|
722 |
+ PluginServices.getText(this,
|
723 |
"Sobreescribir_fichero_Pregunta_2");
|
724 |
int option = JOptionPane.showConfirmDialog(this, confirmDialogText, |
725 |
title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, |
726 |
null);
|
727 |
if (option == JOptionPane.YES_OPTION) { |
728 |
return true; |
729 |
} |
730 |
return false; |
731 |
} |
732 |
|
733 |
public FLyrVect getInputLayer() {
|
734 |
return null; |
735 |
} |
736 |
|
737 |
} |