root / tags / v1_0_2_Build_916 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / gui / AbstractGeoprocessPanel.java @ 12327
History | View | Annotate | Download (9.57 KB)
1 |
/*
|
---|---|
2 |
* Created on 09-mar-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: AbstractGeoprocessPanel.java 12327 2007-06-25 12:40:50Z $
|
47 |
* $Log$
|
48 |
* Revision 1.6.2.1 2006-11-15 00:08:17 jjdelcerro
|
49 |
* *** empty log message ***
|
50 |
*
|
51 |
* Revision 1.7 2006/09/15 10:42:54 caballero
|
52 |
* extensibilidad de documentos
|
53 |
*
|
54 |
* Revision 1.6 2006/07/21 09:10:34 azabala
|
55 |
* fixed bug 608: user doesnt enter any result file to the geoprocess panel
|
56 |
*
|
57 |
* Revision 1.5 2006/06/29 17:29:34 azabala
|
58 |
* Added common functionality to all geoprocess panels (result layer dialog)
|
59 |
*
|
60 |
* Revision 1.4 2006/06/08 18:22:02 azabala
|
61 |
* Arreglado pete cuando abr?amos un dialogo de geoprocessing habiendo agrupaciones en el TOC
|
62 |
*
|
63 |
* Revision 1.3 2006/06/02 18:21:28 azabala
|
64 |
* *** empty log message ***
|
65 |
*
|
66 |
* Revision 1.2 2006/05/25 08:21:14 jmvivo
|
67 |
* A?adido metodo de peticion de confirmacion para sobreescribir el fichero de salida
|
68 |
*
|
69 |
* Revision 1.1 2006/05/24 21:13:09 azabala
|
70 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
71 |
*
|
72 |
* Revision 1.2 2006/05/08 15:36:33 azabala
|
73 |
* check and ask for spatial index creation
|
74 |
*
|
75 |
* Revision 1.1 2006/04/11 18:01:23 azabala
|
76 |
* primera version en cvs
|
77 |
*
|
78 |
* Revision 1.5 2006/04/07 19:00:58 azabala
|
79 |
* *** empty log message ***
|
80 |
*
|
81 |
* Revision 1.4 2006/03/23 21:02:37 azabala
|
82 |
* *** empty log message ***
|
83 |
*
|
84 |
* Revision 1.3 2006/03/21 19:26:08 azabala
|
85 |
* *** empty log message ***
|
86 |
*
|
87 |
* Revision 1.2 2006/03/14 19:32:22 azabala
|
88 |
* *** empty log message ***
|
89 |
*
|
90 |
* Revision 1.1 2006/03/09 17:03:59 azabala
|
91 |
* *** empty log message ***
|
92 |
*
|
93 |
*
|
94 |
*/
|
95 |
package com.iver.cit.gvsig.geoprocess.core.gui; |
96 |
|
97 |
import java.awt.Component; |
98 |
import java.io.File; |
99 |
import java.io.FileNotFoundException; |
100 |
import java.util.ArrayList; |
101 |
import java.util.Arrays; |
102 |
|
103 |
import javax.swing.JComboBox; |
104 |
import javax.swing.JFileChooser; |
105 |
import javax.swing.JFrame; |
106 |
import javax.swing.JOptionPane; |
107 |
import javax.swing.JPanel; |
108 |
import javax.swing.JTextField; |
109 |
|
110 |
import com.iver.andami.PluginServices; |
111 |
import com.iver.cit.gvsig.fmap.DriverException; |
112 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
113 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
114 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
115 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
116 |
import com.iver.cit.gvsig.project.documents.view.legend.CreateSpatialIndexMonitorableTask; |
117 |
import com.iver.utiles.GenericFileFilter; |
118 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
119 |
|
120 |
/**
|
121 |
* Abstract base class with utility methods
|
122 |
* commons to all GeoprocessXXXPanel
|
123 |
* @author azabala
|
124 |
*
|
125 |
*/
|
126 |
public abstract class AbstractGeoprocessPanel extends JPanel implements IGeoprocessPanel{ |
127 |
protected FLayers layers = null; |
128 |
protected JComboBox layersComboBox = null; |
129 |
protected JTextField fileNameResultTextField = null; |
130 |
|
131 |
public FLyrVect getInputLayer() {
|
132 |
FLyrVect solution = null;
|
133 |
String selectedLayer = (String)layersComboBox.getSelectedItem(); |
134 |
solution = (FLyrVect)layers.getLayer(selectedLayer); |
135 |
return solution;
|
136 |
} |
137 |
|
138 |
public void setFLayers(FLayers layers){ |
139 |
this.layers = layers;
|
140 |
} |
141 |
|
142 |
public FLayers getFLayers(){
|
143 |
return layers;
|
144 |
} |
145 |
|
146 |
protected FLyrVect[] getVectorialLayers(FLayers layers){ |
147 |
FLyrVect[] solution = null; |
148 |
ArrayList list = new ArrayList(); |
149 |
int numLayers = layers.getLayersCount();
|
150 |
for(int i = 0; i < numLayers; i++){ |
151 |
FLayer layer = layers.getLayer(i); |
152 |
if(layer instanceof FLyrVect) |
153 |
list.add(layer); |
154 |
else if(layer instanceof FLayers) |
155 |
list.addAll(Arrays.asList(getVectorialLayers((FLayers)layer)));
|
156 |
} |
157 |
solution = new FLyrVect[list.size()];
|
158 |
list.toArray(solution); |
159 |
return solution;
|
160 |
|
161 |
} |
162 |
|
163 |
protected String[] getLayerNames() { |
164 |
String[] solution = null; |
165 |
int numLayers = layers.getLayersCount();
|
166 |
if(layers != null && numLayers > 0){ |
167 |
ArrayList list = new ArrayList(); |
168 |
for(int i = 0; i < numLayers; i++){ |
169 |
FLayer layer = layers.getLayer(i); |
170 |
if(layer instanceof FLyrVect) |
171 |
list.add(layer.getName()); |
172 |
if(layer instanceof FLayers){ |
173 |
FLayers layers = (FLayers) layer; |
174 |
FLyrVect[] vectorials = getVectorialLayers(layers);
|
175 |
for(int j = 0; j < vectorials.length; j++){ |
176 |
list.add(vectorials[j].getName()); |
177 |
} |
178 |
} |
179 |
}//for
|
180 |
solution = new String[list.size()]; |
181 |
list.toArray(solution); |
182 |
} |
183 |
return solution;
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* Shows to the user a dialog error, whith the title and message body
|
188 |
* specified as parameters.
|
189 |
*
|
190 |
* @param message body of the error message
|
191 |
* @param title title of the error message
|
192 |
*/
|
193 |
public void error(String message, String title) { |
194 |
JFrame parentComponent = (JFrame)PluginServices. |
195 |
getMainFrame(); |
196 |
JOptionPane.showMessageDialog(parentComponent, message, title,
|
197 |
JOptionPane.ERROR_MESSAGE);
|
198 |
} |
199 |
|
200 |
|
201 |
/**
|
202 |
* Asks to the user for the creation of a spatial index for the
|
203 |
* specified layer.
|
204 |
* It will be of help for certain geoprocesses.
|
205 |
*
|
206 |
* FLyrVect default spatial index is MapServer quadtree, that hasnt
|
207 |
* the ability to do nearest neighbour searches.
|
208 |
*
|
209 |
* For those geoprocesses that needs it (NN searches) overwrite this
|
210 |
* method and use JSI RTree, or SIL RTree.
|
211 |
*
|
212 |
* It returns an IMonitorableTask, a task to build the spatial
|
213 |
* index in background.
|
214 |
*
|
215 |
* @param layer
|
216 |
* @return an ITask
|
217 |
*/
|
218 |
public IMonitorableTask askForSpatialIndexCreation(FLyrVect layer){
|
219 |
String title = PluginServices.getText(this, "Crear_Indice"); |
220 |
String confirmDialogText =
|
221 |
PluginServices.getText(this, "Crear_Indice_Pregunta_1")+ |
222 |
" " +
|
223 |
layer.getName()+ |
224 |
" " +
|
225 |
PluginServices.getText(this, "Crear_Indice_Pregunta_2"); |
226 |
int option = JOptionPane.showConfirmDialog(this, |
227 |
confirmDialogText, |
228 |
title, |
229 |
JOptionPane.YES_NO_OPTION,
|
230 |
JOptionPane.QUESTION_MESSAGE, null); |
231 |
if(option == JOptionPane.YES_OPTION){ |
232 |
//Usually we want task like spatial index creation dont block
|
233 |
//GUI responses. Now, we dont want to start geoprocess execution
|
234 |
//until spatial index creation would finish, to have advantage
|
235 |
//of the spatial index
|
236 |
try {
|
237 |
CreateSpatialIndexMonitorableTask task |
238 |
= new CreateSpatialIndexMonitorableTask(layer);
|
239 |
return task;
|
240 |
} catch (DriverIOException e) {
|
241 |
// TODO Auto-generated catch block
|
242 |
e.printStackTrace(); |
243 |
return null; |
244 |
} catch (DriverException e) {
|
245 |
// TODO Auto-generated catch block
|
246 |
e.printStackTrace(); |
247 |
return null; |
248 |
} |
249 |
}else
|
250 |
return null; |
251 |
|
252 |
} |
253 |
/**
|
254 |
* Confirm overwrite the output file
|
255 |
* if it allready exist.
|
256 |
*
|
257 |
*
|
258 |
* @param outputFile
|
259 |
* @return answer
|
260 |
*/
|
261 |
public boolean askForOverwriteOutputFile(File outputFile){ |
262 |
String title = PluginServices.getText(this, "Sobreescribir_fichero"); |
263 |
String confirmDialogText =
|
264 |
PluginServices.getText(this, "Sobreescribir_fichero_Pregunta_1")+ |
265 |
"\n'" +
|
266 |
outputFile.getAbsolutePath()+ |
267 |
"'\n" +
|
268 |
PluginServices.getText(this, "Sobreescribir_fichero_Pregunta_2"); |
269 |
int option = JOptionPane.showConfirmDialog(this, |
270 |
confirmDialogText, |
271 |
title, |
272 |
JOptionPane.YES_NO_OPTION,
|
273 |
JOptionPane.QUESTION_MESSAGE, null); |
274 |
if(option == JOptionPane.YES_OPTION){ |
275 |
return true; |
276 |
} |
277 |
return false; |
278 |
} |
279 |
|
280 |
public void openResultFile() { |
281 |
JFileChooser jfc = new JFileChooser(); |
282 |
jfc.addChoosableFileFilter(new GenericFileFilter("shp", |
283 |
"Ficheros SHP"));
|
284 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == |
285 |
JFileChooser.APPROVE_OPTION) {
|
286 |
File file = jfc.getSelectedFile();
|
287 |
if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){ |
288 |
file = new File(file.getPath()+".shp"); |
289 |
} |
290 |
}//if
|
291 |
if (jfc.getSelectedFile()!=null) { |
292 |
getFileNameResultTextField().setText( |
293 |
jfc.getSelectedFile().getAbsolutePath()); |
294 |
} |
295 |
|
296 |
} |
297 |
|
298 |
/**
|
299 |
* Gives access to the text field where user could enter the result
|
300 |
* file path.
|
301 |
* If this method is called during the concrete gui subclasses building,
|
302 |
* caller must sets bounds of this component.
|
303 |
* @return
|
304 |
*/
|
305 |
public JTextField getFileNameResultTextField() { |
306 |
if (fileNameResultTextField == null) { |
307 |
fileNameResultTextField = new JTextField(); |
308 |
} |
309 |
return fileNameResultTextField;
|
310 |
} |
311 |
|
312 |
|
313 |
public File getOutputFile() throws FileNotFoundException{ |
314 |
String fileName = getFileNameResultTextField().getText();
|
315 |
if(fileName.length() == 0){ |
316 |
throw new FileNotFoundException("No se ha seleccionado ningun fichero de salida"); |
317 |
} |
318 |
if(! fileName.endsWith(".shp")){ |
319 |
if(! fileName.endsWith(".")) |
320 |
fileName += ".";
|
321 |
fileName += "shp";
|
322 |
} |
323 |
return new File(fileName); |
324 |
} |
325 |
|
326 |
} |
327 |
|
328 |
|
329 |
|