Statistics
| Revision:

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

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

    
82
import java.io.File;
83
import java.util.ArrayList;
84

    
85
import javax.swing.JComboBox;
86
import javax.swing.JOptionPane;
87
import javax.swing.JPanel;
88

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

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

    
231
}
232

    
233

    
234