Statistics
| Revision:

root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / gui / AbstractGeoprocessPanel.java @ 5425

History | View | Annotate | Download (6.29 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 5425 2006-05-25 08:21:14Z jmvivo $
47
* $Log$
48
* Revision 1.2  2006-05-25 08:21:14  jmvivo
49
* A?adido metodo de peticion de confirmacion para sobreescribir el fichero de salida
50
*
51
* Revision 1.1  2006/05/24 21:13:09  azabala
52
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
53
*
54
* Revision 1.2  2006/05/08 15:36:33  azabala
55
* check and ask for spatial index creation
56
*
57
* Revision 1.1  2006/04/11 18:01:23  azabala
58
* primera version en cvs
59
*
60
* Revision 1.5  2006/04/07 19:00:58  azabala
61
* *** empty log message ***
62
*
63
* Revision 1.4  2006/03/23 21:02:37  azabala
64
* *** empty log message ***
65
*
66
* Revision 1.3  2006/03/21 19:26:08  azabala
67
* *** empty log message ***
68
*
69
* Revision 1.2  2006/03/14 19:32:22  azabala
70
* *** empty log message ***
71
*
72
* Revision 1.1  2006/03/09 17:03:59  azabala
73
* *** empty log message ***
74
*
75
*
76
*/
77
package com.iver.cit.gvsig.geoprocess.core.gui;
78

    
79
import java.io.File;
80
import java.util.ArrayList;
81

    
82
import javax.swing.JComboBox;
83
import javax.swing.JOptionPane;
84
import javax.swing.JPanel;
85

    
86
import com.iver.andami.PluginServices;
87
import com.iver.cit.gvsig.fmap.DriverException;
88
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
89
import com.iver.cit.gvsig.fmap.layers.FLayer;
90
import com.iver.cit.gvsig.fmap.layers.FLayers;
91
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
92
import com.iver.cit.gvsig.gui.thememanager.CreateSpatialIndexMonitorableTask;
93
import com.iver.utiles.swing.threads.IMonitorableTask;
94

    
95
/**
96
 * Abstract base class with utility methods
97
 * commons to all GeoprocessXXXPanel
98
 * @author azabala
99
 *
100
 */
101
public abstract class AbstractGeoprocessPanel extends JPanel implements IGeoprocessPanel{
102
        protected FLayers layers = null;
103
        protected JComboBox layersComboBox = null;
104
        
105
        public FLyrVect getInputLayer() {
106
                FLyrVect solution = null;
107
                String selectedLayer = (String)layersComboBox.getSelectedItem();
108
        solution = (FLyrVect)layers.getLayer(selectedLayer);
109
        return solution;
110
        }
111
        
112
        public void setFLayers(FLayers layers){
113
                this.layers = layers;
114
        }
115
        
116
        public FLayers getFLayers(){
117
                return layers;
118
        }
119
        
120
        protected String[] getLayerNames() {
121
                String[] solution = null;
122
                int numLayers = layers.getLayersCount();
123
                if(layers != null &&  numLayers > 0){
124
                        ArrayList list = new ArrayList();
125
                        for(int i = 0; i < numLayers; i++){
126
                                FLayer layer = layers.getLayer(i);
127
                                if(layer instanceof FLyrVect)
128
                                        list.add(layer.getName());
129
                        }//for
130
                        solution = new String[list.size()];
131
                        list.toArray(solution);
132
                }
133
                return solution;
134
        }
135
        
136
        /**
137
         * Shows to the user a dialog error, whith the title and message body
138
         * specified as parameters.
139
         * 
140
         * @param message body of the error message
141
         * @param title title of the error message
142
         */
143
        public void error(String message, String title) {
144
                JOptionPane.showMessageDialog(this, message, title,
145
                                JOptionPane.ERROR_MESSAGE);
146
        }
147
        
148
        
149
        /**
150
         * Asks to the user for the creation of a spatial index for the
151
         * specified layer.
152
         * It will be of help for certain geoprocesses.
153
         * 
154
         * FLyrVect default spatial index is MapServer quadtree, that hasnt
155
         * the ability to do nearest neighbour searches.
156
         * 
157
         * For those geoprocesses that needs it (NN searches) overwrite this
158
         * method and use JSI RTree, or SIL RTree.
159
         * 
160
         * 
161
         * @param layer
162
         * @return an ITask
163
         */
164
        public IMonitorableTask askForSpatialIndexCreation(FLyrVect layer){
165
                String title = PluginServices.getText(this, "Crear_Indice");
166
                String confirmDialogText = 
167
                        PluginServices.getText(this, "Crear_Indice_Pregunta_1")+
168
                                        " " +
169
                                        layer.getName()+
170
                                        " " +
171
                        PluginServices.getText(this, "Crear_Indice_Pregunta_2");
172
                int option = JOptionPane.showConfirmDialog(this, 
173
                                        confirmDialogText,
174
                                        title, 
175
                                        JOptionPane.YES_NO_OPTION, 
176
                                        JOptionPane.QUESTION_MESSAGE, null);
177
                if(option == JOptionPane.YES_OPTION){
178
                        //Usually we want task like spatial index creation dont block
179
                        //GUI responses. Now, we dont want to start geoprocess execution
180
                        //until spatial index creation would finish, to have advantage
181
                        //of the spatial index
182
                        try {
183
                                CreateSpatialIndexMonitorableTask task
184
                                        = new CreateSpatialIndexMonitorableTask(layer);
185
                                return task;
186
                        } catch (DriverIOException e) {
187
                                // TODO Auto-generated catch block
188
                                e.printStackTrace();
189
                                return null;
190
                        } catch (DriverException e) {
191
                                // TODO Auto-generated catch block
192
                                e.printStackTrace();
193
                                return null;
194
                        }
195
                }else
196
                        return null;
197
                                        
198
        }
199
        /**
200
         * Confirm overwrite the output file
201
         * if it allready exist.
202
         * 
203
         * 
204
         * @param outputFile
205
         * @return answer
206
         */
207
        public boolean askForOverwriteOutputFile(File outputFile){
208
                String title = PluginServices.getText(this, "Sobreescribir_fichero");
209
                String confirmDialogText = 
210
                        PluginServices.getText(this, "Sobreescribir_fichero_Pregunta_1")+
211
                                        "\n'" +
212
                                        outputFile.getAbsolutePath()+
213
                                        "'\n" +
214
                        PluginServices.getText(this, "Sobreescribir_fichero_Pregunta_2");
215
                int option = JOptionPane.showConfirmDialog(this, 
216
                                        confirmDialogText,
217
                                        title, 
218
                                        JOptionPane.YES_NO_OPTION, 
219
                                        JOptionPane.QUESTION_MESSAGE, null);
220
                if(option == JOptionPane.YES_OPTION){
221
                        return true;
222
                }
223
                return false;
224
        }
225

    
226
}
227

    
228

    
229