Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / convexhull / gui / GeoProcessingConvexHullPanel.java @ 24989

History | View | Annotate | Download (10.3 KB)

1
/*
2
 * Created on 03-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: GeoProcessingConvexHullPanel.java 24989 2008-11-12 12:28:13Z jcampos $
47
 * $Log$
48
 * Revision 1.7  2007-03-06 16:47:58  caballero
49
 * Exceptions
50
 *
51
 * Revision 1.6  2006/08/29 07:56:30  cesar
52
 * Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
53
 *
54
 * Revision 1.5  2006/08/29 07:13:56  cesar
55
 * Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
56
 *
57
 * Revision 1.4  2006/08/11 16:20:24  azabala
58
 * *** empty log message ***
59
 *
60
 * Revision 1.3  2006/07/21 09:10:34  azabala
61
 * fixed bug 608: user doesnt enter any result file to the geoprocess panel
62
 *
63
 * Revision 1.2  2006/06/29 17:32:10  azabala
64
 * result layer selection is congruent with AbstractGeoprocessPanel
65
 *
66
 * Revision 1.1  2006/06/20 18:20:45  azabala
67
 * first version in cvs
68
 *
69
 * Revision 1.2  2006/05/24 23:19:10  azabala
70
 * arreglado bug que hacia que falle el geoprocessing cuando el fichero resultado no acaba en shp
71
 *
72
 * Revision 1.1  2006/05/24 21:13:44  azabala
73
 * primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
74
 *
75
 * Revision 1.5  2006/04/11 18:02:42  azabala
76
 * Intento de que el Panel salga bien en todas las resoluciones (y de dejarlos mas bonitos)
77
 *
78
 * Revision 1.4  2006/03/28 16:25:53  azabala
79
 * *** empty log message ***
80
 *
81
 * Revision 1.3  2006/03/21 19:26:08  azabala
82
 * *** empty log message ***
83
 *
84
 * Revision 1.2  2006/03/09 17:04:15  azabala
85
 * *** empty log message ***
86
 *
87
 * Revision 1.1  2006/03/05 19:56:06  azabala
88
 * *** empty log message ***
89
 *
90
 *
91
 */
92
package com.iver.cit.gvsig.geoprocess.impl.convexhull.gui;
93

    
94
import java.awt.Component;
95
import java.io.File;
96

    
97
import javax.swing.DefaultComboBoxModel;
98
import javax.swing.JButton;
99
import javax.swing.JCheckBox;
100
import javax.swing.JComboBox;
101
import javax.swing.JFileChooser;
102
import javax.swing.JLabel;
103
import javax.swing.JPanel;
104
import javax.swing.JTextField;
105

    
106
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
107
import com.iver.andami.PluginServices;
108
import com.iver.andami.ui.mdiManager.IWindow;
109
import com.iver.andami.ui.mdiManager.WindowInfo;
110
import com.iver.cit.gvsig.fmap.layers.FBitSet;
111
import com.iver.cit.gvsig.fmap.layers.FLayers;
112
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
113
import com.iver.cit.gvsig.geoprocess.core.gui.AbstractGeoprocessPanel;
114
import com.iver.utiles.GenericFileFilter;
115

    
116
public class GeoProcessingConvexHullPanel extends AbstractGeoprocessPanel
117
implements IWindow, ConvexHullPanelIF{
118

    
119
        private static final long serialVersionUID = 1L;
120
    private JLabel jLabel = null;
121
        private JCheckBox selectedOnlyCheckbox = null;
122
        private JButton openFileButton = null;
123
        private WindowInfo viewInfo;
124
        private JPanel resultLayerPanel = null;
125
        private JLabel jLabel1 = null;
126
        private JPanel inputLayerPanel = null;
127
        private JLabel jLabel2 = null;
128

    
129
    /**
130
         * This constructor initializes the set of layers
131
         */
132
        public GeoProcessingConvexHullPanel(FLayers layers) {
133
                super();
134
                this.layers = layers;
135
                initialize();
136
        }
137
        /**
138
         * This method initializes this
139
         *
140
         * @return void
141
         */
142
        private  void initialize() {
143
                jLabel = new JLabel();
144
                this.setLayout(null);
145
                this.setBounds(new java.awt.Rectangle(0,0,486,377));
146
                jLabel.setText("Convex_Hull._Introduccion_de_datos");
147
                jLabel.setBounds(10, 26, 426, 21);
148
                this.add(jLabel, null);
149
                this.add(getLayersComboBox(), null);
150
                this.add(getResultLayerPanel(), null);
151
                this.add(getInputLayerPanel(), null);
152
        layersComboBox.setSelectedIndex(0);
153
        initSelectedItemsJCheckBox();
154
        }
155

    
156

    
157
    private void initSelectedItemsJCheckBox() {
158
            String selectedLayer = (String)layersComboBox.getSelectedItem();
159
        FLyrVect inputLayer = (FLyrVect)layers.getLayer(selectedLayer);
160
        FBitSet fBitSet = null;
161
                try {
162
                        fBitSet = inputLayer.getRecordset().getSelection();
163
                } catch (ReadDriverException e) {
164
                        // TODO Auto-generated catch block
165
                        e.printStackTrace();
166
                }
167
        if (fBitSet.cardinality()==0) {
168
            selectedOnlyCheckbox.setEnabled(false);
169
        } else {
170
            selectedOnlyCheckbox.setEnabled(true);
171
        }
172
        selectedOnlyCheckbox.setSelected(false);
173
    }
174

    
175

    
176
        private JCheckBox getSelectedOnlyCheckBox() {
177
                if (selectedOnlyCheckbox == null) {
178
                        selectedOnlyCheckbox = new JCheckBox();
179
                        selectedOnlyCheckbox.setText(PluginServices.getText(this,"Usar_solamente_los_elementos_seleccionados"));
180
                        selectedOnlyCheckbox.setBounds(new java.awt.Rectangle(10,72,300,24));
181
                }
182
                return selectedOnlyCheckbox;
183
        }
184
        /**
185
         * This method initializes layersComboBox
186
         *
187
         * @return javax.swing.JComboBox
188
         */
189
        private JComboBox getLayersComboBox() {
190
                if (layersComboBox == null) {
191
            layersComboBox = new JComboBox();
192
            DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames());
193
            layersComboBox.setModel(defaultModel);
194
                        layersComboBox.setBounds(142, 26, 123, 23);
195
                        layersComboBox.addItemListener(new java.awt.event.ItemListener() {
196
                                public void itemStateChanged(java.awt.event.ItemEvent e) {
197
                    // Cambiar el estado del CheckBox
198
                    initSelectedItemsJCheckBox();
199
                                }
200
                        });
201
                }
202
                return layersComboBox;
203
        }
204
        /* (non-Javadoc)
205
         * @see com.iver.cit.gvsig.geoprocess.impl.convexhull.gui.ConvexHullPanelIF#getFileNameResultTextField()
206
         */
207
        public JTextField getFileNameResultTextField() {
208
                if (fileNameResultTextField == null) {
209
                        super.getFileNameResultTextField().
210
                                setBounds(new java.awt.Rectangle(135,11,169,21));
211
                }
212
                return fileNameResultTextField;
213
        }
214
        /**
215
         * This method initializes openFileButton
216
         *
217
         * @return javax.swing.JButton
218
         */
219
        private JButton getOpenFileButton() {
220
                if (openFileButton == null) {
221
                        openFileButton = new JButton();
222
                        openFileButton.setText(PluginServices.getText(this,"Abrir"));
223
                        openFileButton.setBounds(new java.awt.Rectangle(311,12,101,21));
224
                        openFileButton.addActionListener(new java.awt.event.ActionListener() {
225
                                public void actionPerformed(java.awt.event.ActionEvent e) {
226
                                        openResultFile();
227
                                }
228
                        });
229
                }
230
                return openFileButton;
231
        }
232

    
233
    /* (non-Javadoc)
234
         * @see com.iver.cit.gvsig.geoprocess.impl.convexhull.gui.ConvexHullPanelIF#openResultFile()
235
         */
236
    public void openResultFile() {
237
                JFileChooser jfc = new JFileChooser();
238
        jfc.addChoosableFileFilter(new GenericFileFilter("shp",
239
                                                                                "Ficheros SHP"));
240
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) ==
241
                                                                                        JFileChooser.APPROVE_OPTION) {
242
            File file = jfc.getSelectedFile();
243
            if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){
244
                file = new File(file.getPath()+".shp");
245
            }
246
        }//if
247
        if (jfc.getSelectedFile()!=null) {
248
                getFileNameResultTextField().setText(
249
                                jfc.getSelectedFile().getAbsolutePath());
250
        }
251

    
252
        }
253

    
254
        /* (non-Javadoc)
255
         * @see com.iver.cit.gvsig.geoprocess.impl.convexhull.gui.ConvexHullPanelIF#getInputLayer()
256
         */
257
        public FLyrVect getInputLayer() {
258
                FLyrVect solution = null;
259
                String selectedLayer = (String)layersComboBox.getSelectedItem();
260
        solution = (FLyrVect)layers.getLayer(selectedLayer);
261
        return solution;
262
        }
263

    
264
        /* (non-Javadoc)
265
         * @see com.iver.cit.gvsig.geoprocess.impl.convexhull.gui.ConvexHullPanelIF#isConvexHullOnlySelected()
266
         */
267
        public boolean isConvexHullOnlySelected() {
268
                return selectedOnlyCheckbox.isSelected();
269
        }
270

    
271
        public WindowInfo getWindowInfo() {
272
                if (viewInfo == null) {
273
                        viewInfo = new WindowInfo(WindowInfo.MODALDIALOG);
274
                        viewInfo.setTitle(PluginServices.getText(this,
275
                                        "Convex_Hull"));
276
                }
277
                return viewInfo;
278
        }
279
        
280
        public Object getWindowProfile(){
281
                return WindowInfo.DIALOG_PROFILE;
282
        }
283
        /**
284
         * This method initializes resultLayerPanel
285
         *
286
         * @return javax.swing.JPanel
287
         */
288
        private JPanel getResultLayerPanel() {
289
                if (resultLayerPanel == null) {
290
                        jLabel1 = new JLabel();
291
                        jLabel1.setBounds(new java.awt.Rectangle(4,13,126,17));
292
                        jLabel1.setText(PluginServices.getText(this, "Cobertura_de_salida") + ":");
293
                        resultLayerPanel = new JPanel();
294
                        resultLayerPanel.setLayout(null);
295
                        resultLayerPanel.setBounds(new java.awt.Rectangle(11,200,426,39));
296
                        resultLayerPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
297
                        resultLayerPanel.add(getOpenFileButton(), null);
298
                        resultLayerPanel.add(getFileNameResultTextField(), null);
299
                        resultLayerPanel.add(jLabel1, null);
300
                }
301
                return resultLayerPanel;
302
        }
303
        /**
304
         * This method initializes inputLayerPanel
305
         *
306
         * @return javax.swing.JPanel
307
         */
308
        private JPanel getInputLayerPanel() {
309
                if (inputLayerPanel == null) {
310
                        jLabel2 = new JLabel();
311
                        jLabel2.setBounds(new java.awt.Rectangle(11,26,149,23));
312
                        jLabel2.setText(PluginServices.getText(this, "Cobertura_de_entrada") + ":");
313
                        inputLayerPanel = new JPanel();
314
                        inputLayerPanel.setLayout(null);
315
                        inputLayerPanel.setBounds(new java.awt.Rectangle(10,60,428,133));
316
                        inputLayerPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
317
                        inputLayerPanel.add(getSelectedOnlyCheckBox(), null);
318
                        inputLayerPanel.add(jLabel2, null);
319
                        inputLayerPanel.add(getLayersComboBox(), null);
320
                }
321
                return inputLayerPanel;
322
        }
323

    
324
}  //  @jve:decl-index=0:visual-constraint="15,20"