Statistics
| Revision:

root / trunk / extensions / extGPS / src / org / gvsig / gps / panel / GPSConfigPanel.java @ 4752

History | View | Annotate | Download (11.1 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

    
42
/* CVS MESSAGES:
43
 *
44
 * $Id: GPSConfigPanel.java 4752 2006-04-06 10:36:05Z jaume $
45
 * $Log$
46
 * Revision 1.1  2006-04-06 10:35:14  jaume
47
 * *** empty log message ***
48
 *
49
 *
50
 */
51
package org.gvsig.gps.panel;
52

    
53
import gnu.io.CommPortIdentifier;
54

    
55
import java.awt.Component;
56
import java.util.Enumeration;
57

    
58
import javax.swing.JButton;
59
import javax.swing.JComboBox;
60
import javax.swing.JLabel;
61
import javax.swing.JOptionPane;
62
import javax.swing.JPanel;
63
import javax.swing.JTextField;
64
import javax.swing.SwingConstants;
65

    
66
import com.iver.andami.PluginServices;
67
import com.iver.andami.ui.mdiManager.View;
68
import com.iver.andami.ui.mdiManager.ViewInfo;
69
import com.iver.utiles.XMLEntity;
70

    
71
public class GPSConfigPanel extends JPanel implements View{
72
        private JComboBox cmbPorts = null;
73
        private JPanel pnlPortConfig = null;
74
        private JTextField txtSampleRate;
75
        private JLabel lblSampleRate;
76
        private JLabel lblPort;
77
        private JLabel lblPortSpeed = null;
78
        private JComboBox cmbPortSpeed = null;
79
        private JButton btnOk = null;
80
        private JButton btnCancel = null;
81
        private GPSControlPanel control;
82
        private JComboBox cmbDataBits = null;
83
        private JLabel lblDataBits = null;
84
        private JLabel lblStopBits = null;
85
        private JComboBox cmbStopBits = null;
86
        private JComboBox cmbParity = null;
87
        private JLabel lblParity = null;
88

    
89
        /**
90
         * This is the default constructor
91
         */
92
        public GPSConfigPanel(GPSControlPanel control) {
93
                super();
94
                this.control = control;
95
                initialize();
96
        }
97

    
98
        /**
99
         * This method initializes this
100
         * 
101
         * @return void
102
         */
103
        private void initialize() {
104
                this.setLayout(null);
105
                this.setSize(247, 214);
106
                this.add(getPnlPortConfig(), null);
107
                this.add(getBtnOk(), null);
108
                this.add(getBtnCancel(), null);
109
        }
110

    
111
        public ViewInfo getViewInfo() {
112
                ViewInfo m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE);
113
                m_viewInfo.setTitle(PluginServices.getText(this, "gps_settings"));
114
                m_viewInfo.setWidth(this.getWidth()+8);
115
                m_viewInfo.setHeight(this.getHeight()+8);
116
                return m_viewInfo;
117
        }
118

    
119
        /**
120
         * This method initializes jPanel        
121
         *         
122
         * @return javax.swing.JPanel        
123
         */    
124
        private JPanel getPnlPortConfig() {
125
                if (pnlPortConfig == null) {
126
                        lblParity = new JLabel();
127
                        lblParity.setBounds(10, 146, 112, 20);
128
                        lblParity.setHorizontalAlignment(SwingConstants.RIGHT);
129
                        lblParity.setText(PluginServices.getText(this, "parity")+":");
130
                        lblStopBits = new JLabel();
131
                        lblStopBits.setBounds(10, 123, 112, 20);
132
                        lblStopBits.setHorizontalAlignment(SwingConstants.RIGHT);
133
                        lblStopBits.setText(PluginServices.getText(this, "stop_bits")+":");
134
                        lblDataBits = new JLabel();
135
                        lblDataBits.setBounds(10, 100, 112, 20);
136
                        lblDataBits.setHorizontalAlignment(SwingConstants.RIGHT);
137
                        lblDataBits.setText(PluginServices.getText(this, "data_bits")+":");
138
                        lblPortSpeed = new JLabel();
139
                        lblPortSpeed.setBounds(10, 77, 112, 20);
140
                        lblPortSpeed.setHorizontalAlignment(SwingConstants.RIGHT);
141
                        lblPortSpeed.setText(PluginServices.getText(this, "port_speed")+":");
142
                        pnlPortConfig = new JPanel();
143
                        pnlPortConfig.setLayout(null);
144
                        pnlPortConfig.setBounds(0, 0, 247, 179);
145
                        pnlPortConfig.setBorder(javax.swing.BorderFactory.createTitledBorder(
146
                                          null, PluginServices.getText(this, "port_config"),
147
                                          javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, 
148
                                          javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
149
                        pnlPortConfig.add(getTxtSampleRate(), null);
150
                        pnlPortConfig.add(getCmbPorts(), null);
151
                        lblSampleRate = new JLabel();
152
                        lblSampleRate.setBounds(10, 31, 112, 20);
153
                        lblSampleRate.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
154
                        lblSampleRate.setText(PluginServices.getText(this, "sample_rate")+":");
155
                        lblPort = new JLabel();
156
                        lblPort.setBounds(10, 54, 112, 20);
157
                        lblPort.setText(PluginServices.getText(this, "port")+":");
158
                        lblPort.setHorizontalAlignment(SwingConstants.RIGHT);
159
                        pnlPortConfig.add(lblSampleRate, null);
160
                        pnlPortConfig.add(lblPort, null);
161
                        pnlPortConfig.add(lblPortSpeed, null);
162
                        pnlPortConfig.add(getCmbPortSpeed(), null);
163
                        pnlPortConfig.add(getCmbDataBits(), null);
164
                        pnlPortConfig.add(getCmbStopBits(), null);
165
                        pnlPortConfig.add(getCmbParity(), null);
166
                        pnlPortConfig.add(lblDataBits, null);
167
                        pnlPortConfig.add(lblStopBits, null);
168
                        pnlPortConfig.add(lblParity, null);
169
                }
170
                return pnlPortConfig;
171
        }
172

    
173
        private JTextField getTxtSampleRate() {
174
                if (txtSampleRate == null) {
175
                        txtSampleRate = new JTextField();
176
                        txtSampleRate.setBounds(126, 31, 111, 20);
177
                        txtSampleRate.addKeyListener(new java.awt.event.KeyAdapter() { 
178
                                public void keyTyped(java.awt.event.KeyEvent e) {    
179
//                                        try {
180
//                                                float time = Float.parseFloat(txtSampleRate.getText());
181
//                                                gps.setSampleRate(Math.abs((int) (time * 1000)));
182
//                                                
183
//                                        } catch (Exception ex) {
184
//                                                txtSampleRate.setText("");
185
//                                        };
186
                                }
187
                        });
188
                }
189
                return txtSampleRate;
190
        }
191
        
192
        /**
193
         * This method initializes jComboBox        
194
         *         
195
         * @return javax.swing.JComboBox        
196
         */    
197
        private JComboBox getCmbPorts() {
198
                if (cmbPorts == null) {
199
                        cmbPorts = new JComboBox();
200
                        cmbPorts.setBounds(126, 54, 111, 20);
201
                        XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
202
                        String portName = xml.getStringProperty("gps-lastSerialPortSpeed");
203
                        Enumeration portList = CommPortIdentifier.getPortIdentifiers();
204
                        while (portList.hasMoreElements()) {
205
                                CommPortIdentifier port = (CommPortIdentifier) portList.nextElement();
206
                                cmbPorts.addItem(port.getName());
207
                                if (portName != null && portName.equals(port.getName())) {
208
                                        cmbPorts.setSelectedIndex(cmbPorts.getItemCount()-1);
209
                                }
210
                        }
211
                }
212
                return cmbPorts;
213
        }
214

    
215
        /**
216
         * This method initializes jComboBox        
217
         *         
218
         * @return javax.swing.JComboBox        
219
         */    
220
        private JComboBox getCmbPortSpeed() {
221
                if (cmbPortSpeed == null) {
222
                        cmbPortSpeed = new JComboBox();
223
                        cmbPortSpeed.setBounds(126, 77, 111, 20);
224
                        cmbPortSpeed.setEditable(false);
225
                        XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
226
                        String[] speeds = new String[] {
227
                                         "75"  ,  "110" ,  "134" ,  "150" ,  "300",
228
                                        "600"  , "1200" , "1800" , "2400" , "4800",
229
                                        "9600" , "14400", "19200", "38400","57600",
230
                                        "115200"        
231
                                };
232
                        int speed = xml.getIntProperty("gps-serialPortSpeed");
233
                        for (int i = 0; i < speeds.length; i++) {
234
                                cmbPortSpeed.addItem(speeds[i]);
235
                                if (Integer.parseInt(speeds[i]) == speed)
236
                                        cmbPortSpeed.setSelectedIndex(i);
237
                        }
238
                        
239
                }
240
                return cmbPortSpeed;
241
        }
242

    
243
        /**
244
         * This method initializes btnOk        
245
         *         
246
         * @return javax.swing.JButton        
247
         */    
248
        private JButton getBtnOk() {
249
                if (btnOk == null) {
250
                        btnOk = new JButton();
251
                        btnOk.setBounds(53, 183, 70, 25);
252
                        btnOk.setText(PluginServices.getText(this, "ok"));
253
                        btnOk.addActionListener(new java.awt.event.ActionListener() { 
254
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
255
                                        ok();
256
                                }
257
                        });
258
                }
259
                return btnOk;
260
        }
261

    
262
        /**
263
         * This method initializes btnCancel        
264
         *         
265
         * @return javax.swing.JButton        
266
         */    
267
        private JButton getBtnCancel() {
268
                if (btnCancel == null) {
269
                        btnCancel = new JButton();
270
                        btnCancel.setBounds(123, 183, 70, 25);
271
                        btnCancel.addActionListener(new java.awt.event.ActionListener() { 
272
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
273
                                        cancel();
274
                                }
275
                        });
276
                        btnCancel.setText(PluginServices.getText(this, "cancel"));
277
                }
278
                return btnCancel;
279
        }
280

    
281
        protected void cancel() {
282
                PluginServices.getMDIManager().closeView(this);                
283
        }
284
        
285
        protected void ok() {
286
                try {
287
                        control.setPort((CommPortIdentifier) cmbPorts.getSelectedItem());
288
                        control.setPortSpeed(Integer.parseInt((String) cmbPortSpeed.getSelectedItem()));
289
                        control.setPortDataBits(Integer.parseInt((String) cmbDataBits.getSelectedItem()));
290
                        control.setPortStopBits((String) cmbStopBits.getSelectedItem());
291
                        control.setPortParity((String) cmbParity.getSelectedItem());
292
                        PluginServices.getMDIManager().closeView(this);
293
                } catch (Exception e) {
294
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this, "config_error"));
295
                }
296
        }
297

    
298
        /**
299
         * This method initializes jComboBox        
300
         *         
301
         * @return javax.swing.JComboBox        
302
         */    
303
        private JComboBox getCmbDataBits() {
304
                if (cmbDataBits == null) {
305
                        cmbDataBits = new JComboBox();
306
                        cmbDataBits.setBounds(126, 100, 111, 20);
307
                        String[] dataBitsValues;
308
                        XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
309
                        dataBitsValues = new String[] { "5", "6", "7", "8" };
310
                        int dataBits = xml.getIntProperty("gps-serialPortDataBits");
311
                        for (int i = 0; i < dataBitsValues.length; i++) {
312
                                cmbDataBits.addItem(dataBitsValues[i]);
313
                                if (Integer.parseInt(dataBitsValues[i]) == dataBits)
314
                                        cmbDataBits.setSelectedIndex(i);
315
                        }
316
                }
317
                return cmbDataBits;
318
        }
319

    
320
        /**
321
         * This method initializes jComboBox1        
322
         *         
323
         * @return javax.swing.JComboBox        
324
         */    
325
        private JComboBox getCmbStopBits() {
326
                if (cmbStopBits == null) {
327
                        cmbStopBits = new JComboBox();
328
                        cmbStopBits.setBounds(126, 123, 111, 20);
329
                        cmbStopBits.setEditable(false);
330
                        
331
                        XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
332
                        String stopBits = xml.getStringProperty("gps-serialPortStopBits");
333
                        
334
                        String[] stopBitsValues = new String[] { "1", "1.5", "2" };
335
                        for (int i = 0; i < stopBitsValues.length; i++) {
336
                                cmbStopBits.addItem(stopBitsValues[i]);
337
                                if (stopBitsValues[i].equals(stopBits))
338
                                        cmbStopBits.setSelectedIndex(i);
339
                        }
340
                }
341
                return cmbStopBits;
342
        }
343

    
344
        /**
345
         * This method initializes jComboBox2        
346
         *         
347
         * @return javax.swing.JComboBox        
348
         */    
349
        private JComboBox getCmbParity() {
350
                if (cmbParity == null) {
351
                        cmbParity = new JComboBox();
352
                        cmbParity.setBounds(126, 146, 111, 20);
353
                        cmbParity.setEditable(false);
354
                        String[] parities = new String[] { "even", "odd", "mark", "space", "none" };
355
                        XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
356
                        
357
                        String parity = xml.getStringProperty("gps-serialPortParities");
358
                        
359
                        for (int i = 0; i < parities.length; i++) {
360
                                cmbParity.addItem(PluginServices.getText(this, parities[i]));
361
                                if (parities[i].equals(parity))
362
                                        cmbParity.setSelectedIndex(i);
363
                        }
364
                }
365
                return cmbParity;
366
        }
367
}  //  @jve:decl-index=0:visual-constraint="13,19"