Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoprocessingExtensions / src / com / iver / cit / gvsig / geoprocess / impl / xyshift / gui / GeoprocessingXYShiftPanel.java @ 10626

History | View | Annotate | Download (9.15 KB)

1
/*
2
 * Created on 28-jun-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: GeoprocessingXYShiftPanel.java 10626 2007-03-06 16:55:54Z caballero $
47
* $Log$
48
* Revision 1.5  2007-03-06 16:48:14  caballero
49
* Exceptions
50
*
51
* Revision 1.4  2006/08/11 17:17:55  azabala
52
* *** empty log message ***
53
*
54
* Revision 1.3  2006/07/03 20:29:08  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.2  2006/06/29 17:58:31  azabala
58
* *** empty log message ***
59
*
60
* Revision 1.1  2006/06/28 18:17:21  azabala
61
* first version in cvs
62
*
63
*
64
*/
65
package com.iver.cit.gvsig.geoprocess.impl.xyshift.gui;
66

    
67
import java.awt.event.ItemEvent;
68

    
69
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
70
import com.iver.cit.gvsig.fmap.layers.FBitSet;
71
import com.iver.cit.gvsig.fmap.layers.FLayers;
72
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
73
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
74
import com.iver.cit.gvsig.geoprocess.core.gui.AbstractGeoprocessPanel;
75

    
76
import javax.swing.DefaultComboBoxModel;
77
import javax.swing.JComboBox;
78
import javax.swing.JLabel;
79
import com.iver.andami.PluginServices;
80
import javax.swing.JCheckBox;
81
import javax.swing.JPanel;
82
import javax.swing.JButton;
83
import java.awt.Rectangle;
84
import java.io.File;
85

    
86
import javax.swing.JTextField;
87
import javax.swing.BorderFactory;
88
import javax.swing.border.EtchedBorder;
89

    
90
public class GeoprocessingXYShiftPanel
91
                                        extends AbstractGeoprocessPanel  {
92

    
93
        private static final long serialVersionUID = 1L;
94
        private JLabel jLabel = null;
95
        private JLabel jLabel1 = null;
96
        private JCheckBox selectedOnlyCheckBox = null;
97
        private JPanel resultSelectionPanel = null;
98
        private JButton openResultButton = null;
99
        private JLabel jLabel2 = null;
100
        private JLabel xoffsetLabel = null;
101
        private JTextField xoffsetTextField = null;
102
        private JLabel jLabel3 = null;
103
        private JTextField yoffsetTextField = null;
104
        private JLabel offsetLabel = null;
105

    
106
        /**
107
         * This method initializes
108
         *
109
         */
110
        public GeoprocessingXYShiftPanel(FLayers layers) {
111
                super();
112
                this.layers = layers;
113
                initialize();
114
        }
115

    
116
        public double getXOffset() throws GeoprocessException{
117
                try {
118
                        String strDist = xoffsetTextField.getText();
119
                        return Double.parseDouble(strDist);
120
                } catch (NumberFormatException ex) {
121
                        throw new GeoprocessException(
122
                                        "Offset en x introducido no numerico");
123
                }
124
        }
125

    
126
        public double getYOffset() throws GeoprocessException{
127
                try {
128
                        String strDist = yoffsetTextField.getText();
129
                        return Double.parseDouble(strDist);
130
                } catch (NumberFormatException ex) {
131
                        throw new GeoprocessException(
132
                                        "Distancia de buffer introducida no numerica");
133
                }
134
        }
135

    
136
        /**
137
         * Tells if apply geoprocess only to selected features of the input
138
         * layer or to all features
139
         * @return
140
         */
141
        public boolean isOnlySelected(){
142
                return selectedOnlyCheckBox.isSelected();
143
        }
144

    
145
        /**
146
         * This method initializes this
147
         *
148
         */
149
        private void initialize() {
150
        offsetLabel = new JLabel();
151
        offsetLabel.setBounds(new java.awt.Rectangle(29,147,211,23));
152
        offsetLabel.setText(PluginServices.getText(this,"Introducir_valores_desplazamiento"));
153
        jLabel3 = new JLabel();
154
        jLabel3.setBounds(new java.awt.Rectangle(27,215,152,27));
155
        jLabel3.setText(PluginServices.getText(this,"yOffset")+":");
156
        xoffsetLabel = new JLabel();
157
        xoffsetLabel.setBounds(new java.awt.Rectangle(26,182,154,26));
158
        xoffsetLabel.setText(PluginServices.getText(this,"xOffset")+":");
159
        jLabel1 = new JLabel();
160
        jLabel1.setBounds(new java.awt.Rectangle(27,60,384,23));
161
        jLabel1.setText(PluginServices.getText(this, "Cobertura_de_entrada") + ":");
162
        jLabel = new JLabel();
163
        jLabel.setBounds(new java.awt.Rectangle(27,17,384,27));
164
        jLabel.setText(PluginServices.getText(this, "XYShift._Introduccion_de_datos") + ":");
165
        this.setLayout(null);
166
        this.setBounds(new java.awt.Rectangle(0,0,500,400));
167
        this.add(jLabel, null);
168
        this.add(jLabel1, null);
169
        this.add(getSelectedOnlyCheckBox(), null);
170
        this.add(getResultPanel(), null);
171
        this.add(xoffsetLabel, null);
172
        this.add(getXoffsetTextField(), null);
173
        this.add(jLabel3, null);
174
        this.add(getYoffsetjTextField1(), null);
175
        this.add(offsetLabel, null);
176
        this.add(getLayersComboBox(), null);
177
        }
178

    
179
        /**
180
         * This method initializes selectedOnlyCheckBox
181
         *
182
         * @return javax.swing.JCheckBox
183
         */
184
        private JCheckBox getSelectedOnlyCheckBox() {
185
                if (selectedOnlyCheckBox == null) {
186
                        selectedOnlyCheckBox = new JCheckBox();
187
                        selectedOnlyCheckBox.setBounds(new java.awt.Rectangle(27,94,383,23));
188
                        selectedOnlyCheckBox.setText(PluginServices.getText(this, "Usar_solamente_los_elementos_seleccionados"));
189
                }
190
                return selectedOnlyCheckBox;
191
        }
192

    
193
        private JComboBox getLayersComboBox() {
194
                if (layersComboBox == null) {
195
                        layersComboBox = new JComboBox();
196
                        DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(
197
                                        getLayerNames());
198
                        layersComboBox.setModel(defaultModel);
199
                        layersComboBox.setBounds(142, 63, 260, 21);
200
                        layersComboBox.addItemListener(new java.awt.event.ItemListener() {
201
                                public void itemStateChanged(ItemEvent e) {
202
                                        if (e.getStateChange() == ItemEvent.SELECTED) {
203
                                                // Cambiar el estado del CheckBox
204
                                                initSelectedItemsJCheckBox();
205
                                        }
206
                                }//itemStateChange
207
                        });
208
                }
209
                return layersComboBox;
210
        }
211

    
212
        private void initSelectedItemsJCheckBox() {
213
                String selectedLayer = (String) layersComboBox.getSelectedItem();
214
                FLyrVect inputLayer = (FLyrVect) layers.getLayer(selectedLayer);
215
                FBitSet fBitSet = null;
216
                try {
217
                        fBitSet = inputLayer.getRecordset().getSelection();
218
                } catch (ReadDriverException e) {
219
                        // TODO Auto-generated catch block
220
                        e.printStackTrace();
221
                }
222
                if (fBitSet.cardinality() == 0) {
223
                        selectedOnlyCheckBox.setEnabled(false);
224
                } else {
225
                        selectedOnlyCheckBox.setEnabled(true);
226
                }
227
                selectedOnlyCheckBox.setSelected(false);
228
        }
229

    
230
        /**
231
         * This method initializes resultSelectionPanel
232
         *
233
         * @return javax.swing.JPanel
234
         */
235
        private JPanel getResultPanel() {
236
                if (resultSelectionPanel == null) {
237
                        jLabel2 = new JLabel();
238
                        jLabel2.setBounds(new Rectangle(4, 13, 126, 17));
239
                        jLabel2.setText(PluginServices.getText(this, "Cobertura_de_salida") + ":");
240
                        resultSelectionPanel = new JPanel();
241
                        resultSelectionPanel.setLayout(null);
242
                        resultSelectionPanel.setBounds(new java.awt.Rectangle(26,259,443,46));
243
                        resultSelectionPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
244
                        resultSelectionPanel.add(getOpenResultButton(), null);
245
                        resultSelectionPanel.add(getFileNameResultTextField(), null);
246
                        resultSelectionPanel.add(jLabel2, null);
247
                }
248
                return resultSelectionPanel;
249
        }
250

    
251
        /**
252
         * This method initializes openResultButton
253
         *
254
         * @return javax.swing.JButton
255
         */
256
        private JButton getOpenResultButton() {
257
                if (openResultButton == null) {
258
                        openResultButton = new JButton();
259
                        openResultButton.setBounds(new Rectangle(311, 12, 101, 21));
260
                        openResultButton.setText(PluginServices.getText(this, "Abrir"));
261
                        openResultButton.addActionListener(new java.awt.event.ActionListener() {
262
                                public void actionPerformed(java.awt.event.ActionEvent e) {
263
                                        openResultFile();
264
                                }
265
                        });
266
                }
267
                return openResultButton;
268
        }
269

    
270
        /**
271
         * This method initializes jTextField
272
         *
273
         * @return javax.swing.JTextField
274
         */
275
        public JTextField getFileNameResultTextField() {
276
                if (fileNameResultTextField == null) {
277
                        super.getFileNameResultTextField().
278
                                setBounds(new Rectangle(135, 11,
279
                                                                                169, 21));
280
                }
281
                return fileNameResultTextField;
282
        }
283

    
284
        /**
285
         * This method initializes xoffsetTextField
286
         *
287
         * @return javax.swing.JTextField
288
         */
289
        private JTextField getXoffsetTextField() {
290
                if (xoffsetTextField == null) {
291
                        xoffsetTextField = new JTextField();
292
                        xoffsetTextField.setBounds(new java.awt.Rectangle(193,182,216,25));
293
                }
294
                return xoffsetTextField;
295
        }
296

    
297
        /**
298
         * This method initializes yoffsetjTextField1
299
         *
300
         * @return javax.swing.JTextField
301
         */
302
        private JTextField getYoffsetjTextField1() {
303
                if (yoffsetTextField == null) {
304
                        yoffsetTextField = new JTextField();
305
                        yoffsetTextField.setBounds(new java.awt.Rectangle(193,216,216,25));
306
                }
307
                return yoffsetTextField;
308
        }
309

    
310
}  //  @jve:decl-index=0:visual-constraint="13,15"
311