Statistics
| Revision:

root / trunk / extensions / extGPS / src / org / gvsig / gps / panel / TestPanel.java @ 4720

History | View | Annotate | Download (8.37 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: TestPanel.java 4720 2006-04-03 16:10:27Z jaume $
45
 * $Log$
46
 * Revision 1.1  2006-04-03 16:10:27  jaume
47
 * *** empty log message ***
48
 *
49
 * Revision 1.1  2006/03/31 09:55:34  jaume
50
 * *** empty log message ***
51
 *
52
 *
53
 */
54
/**
55
 * 
56
 */
57
package org.gvsig.gps.panel;
58

    
59
import gnu.io.CommPortIdentifier;
60
import gnu.io.PortInUseException;
61

    
62
import java.awt.geom.Point2D;
63
import java.util.Enumeration;
64

    
65
import javax.swing.JButton;
66
import javax.swing.JComboBox;
67
import javax.swing.JLabel;
68
import javax.swing.JPanel;
69
import javax.swing.JTextField;
70
import javax.swing.SwingConstants;
71

    
72
import org.cresques.cts.ICoordTrans;
73
import org.cresques.cts.IProjection;
74
import org.cresques.cts.ProjectionPool;
75
import org.cresques.cts.gt2.CoordSys;
76
import org.cresques.cts.gt2.CoordTrans;
77
import org.gvsig.gps.GPSReader;
78
import org.gvsig.gps.listeners.GPSEventListener;
79

    
80
import com.iver.andami.PluginServices;
81
import com.iver.andami.ui.mdiManager.View;
82
import com.iver.andami.ui.mdiManager.ViewInfo;
83

    
84
/**
85
 * @author jaume
86
 *
87
 */
88
public class TestPanel extends JPanel implements View{
89
        private GPSReader gps;
90
        private JLabel lblSampleRate = null;
91
        private JTextField txtSampleRate = null;
92
        private JButton btnStart = null;
93
        private JButton btnPause = null;
94
        private JButton btnStop = null;
95
        private JLabel lblPort = null;
96
        private JComboBox cmbPorts = null;
97
        private JLabel lblPosValue;
98
        private JLabel lblPos;
99
        /**
100
         * 
101
         */
102
        public TestPanel() {
103
                super();
104
                // TODO Auto-generated constructor stub
105
                initialize();
106
        }
107
        
108
        /**
109
         * This method initializes this
110
         * 
111
         * @return void
112
         */
113
        private void initialize() {
114
                lblPort = new JLabel();
115
                lblPort.setBounds(10, 80, 143, 20);
116
                lblPort.setText("Port:");
117
                lblPort.setHorizontalAlignment(SwingConstants.RIGHT);
118
                lblSampleRate = new JLabel();
119
                lblSampleRate.setBounds(10, 52, 143, 20);
120
                lblSampleRate.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
121
                lblSampleRate.setText("Frecuencia de muestreo:");
122
                lblPosValue = new JLabel();
123
                lblPosValue.setBounds(157, 25, 398, 20);
124
                lblPosValue.setFont(new java.awt.Font("MS Sans Serif", java.awt.Font.BOLD, 11));
125
                lblPos = new JLabel();
126
                lblPos.setText("Pos:");
127
                lblPos.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
128
                lblPos.setBounds(10, 25, 143, 20);
129
                this.setLayout(null);
130
                this.setSize(581, 200);
131
                this.add(lblPos, null);
132
                this.add(lblPosValue, null);
133
                this.add(getTxtSampleRate(), null);
134
                this.add(getBtnStart(), null);
135
                this.add(getBtnPause(), null);
136
                this.add(getBtnStop(), null);
137
                this.add(lblPort, null);
138
                this.add(getCmbPorts(), null);
139
                Enumeration portList = CommPortIdentifier.getPortIdentifiers();
140
                while (portList.hasMoreElements()) {
141
                        getCmbPorts().addItem(((CommPortIdentifier) portList.nextElement()).getName());
142
                }
143
                portList = CommPortIdentifier.getPortIdentifiers();
144
                
145
        }
146

    
147
        /**
148
         * This method initializes jTextField        
149
         *         
150
         * @return javax.swing.JTextField        
151
         */    
152
        private JTextField getTxtSampleRate() {
153
                if (txtSampleRate == null) {
154
                        txtSampleRate = new JTextField();
155
                        txtSampleRate.setBounds(157, 52, 204, 20);
156
                        txtSampleRate.addKeyListener(new java.awt.event.KeyAdapter() { 
157
                                public void keyTyped(java.awt.event.KeyEvent e) {    
158
                                        try {
159
                                                float time = Float.parseFloat(txtSampleRate.getText());
160
                                                gps.setSampleRate(Math.abs((int) (time * 1000)));
161
                                                
162
                                        } catch (Exception ex) {
163
                                                txtSampleRate.setText("");
164
                                        };
165
                                }
166
                        });
167
                }
168
                return txtSampleRate;
169
        }
170

    
171
        public ViewInfo getViewInfo() {
172
                ViewInfo m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE |
173
                                ViewInfo.MAXIMIZABLE | ViewInfo.RESIZABLE);
174
                m_viewInfo.setTitle(PluginServices.getText(this, "GPS Control panel"));
175
                m_viewInfo.setWidth(this.getWidth());
176
                m_viewInfo.setHeight(this.getHeight());
177
                
178
                return m_viewInfo;
179
        }
180

    
181
        /**
182
         * This method initializes btnStart        
183
         *         
184
         * @return javax.swing.JButton        
185
         */    
186
        private JButton getBtnStart() {
187
                if (btnStart == null) {
188
                        btnStart = new JButton();
189
                        btnStart.setBounds(49, 140, 104, 41);
190
                        btnStart.addActionListener(new java.awt.event.ActionListener() { 
191
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
192
                                        start();
193
                                }
194
                        });
195
                        btnStart.setText("Start");
196
                }
197
                return btnStart;
198
        }
199

    
200
        
201
        public void start() {
202
                Enumeration portList = CommPortIdentifier.getPortIdentifiers();
203
                while (portList.hasMoreElements()) {
204
                        CommPortIdentifier myPortId = (CommPortIdentifier) portList.nextElement();
205
                        if (myPortId.getName().equals("COM3"))
206
                                try {
207
                                        gps = GPSReader.getInstance();
208
                                        gps.setPort(myPortId, 4800);
209
                                        gps.addEventListener(new GPSEventListener() {
210

    
211
                                                public void unhandledMessage(String message) {
212
                                                        System.out.println("\nunhandledMessage"+": "+message+"\n");
213
                                                        lblPosValue.setText(message);
214
                                                }
215

    
216
                                                public void connectionLost() {
217
                                                        System.out.println("connectionLost");
218
                                                }
219

    
220
                                                public void connectionEstablished() {
221
                                                        System.out.println("connectionEstablished");
222
                                                }
223

    
224
                                                public void newLonLatPositionReceived(double lon, double lat) {
225
                                                        IProjection reqProj = ProjectionPool.get("EPSG:23030");
226
                                                IProjection latLonProj = ProjectionPool.get("EPSG:4326");                    
227
                                                ICoordTrans ct = new CoordTrans((CoordSys) latLonProj, (CoordSys) reqProj);
228
                                                Point2D pDst = new Point2D.Double();
229
                                                //Point2D pSrc = new Point2D.Double(lon, lat);
230
                                                Point2D pSrc = new Point2D.Double(-0.36297333240509033, 39.463722229003906);
231
                                                pDst = ct.convert(pSrc, pDst);
232
                                                lblPosValue.setText("("+pDst.getX()+", "+pDst.getY()+")");
233
                                                
234
                                                }
235

    
236
                                                public void signalLevelChanged(float level) {
237
                                                        // TODO Auto-generated method stub
238
                                                        
239
                                                }
240

    
241
                                                public void speedChanged(float speed, short course) {
242
                                                        // TODO Auto-generated method stub
243
                                                        
244
                                                }
245

    
246
                                                public void estimatedPosErrorChanged(double f) {
247
                                                        // TODO Auto-generated method stub
248
                                                        
249
                                                }
250

    
251
                                                public void heightChanged() {
252
                                                        // TODO Auto-generated method stub
253
                                                        
254
                                                }
255
                                                
256
                                        });
257
                                        gps.start();
258
                                } catch (PortInUseException e) {
259
                                        // TODO Auto-generated catch block
260
                                        e.printStackTrace();
261
                                }
262
                }
263
                
264
        }
265
        /**
266
         * This method initializes btnStop        
267
         *         
268
         * @return javax.swing.JButton        
269
         */    
270
        private JButton getBtnPause() {
271
                if (btnPause == null) {
272
                        btnPause = new JButton();
273
                        btnPause.setBounds(158, 140, 102, 40);
274
                        btnPause.addActionListener(new java.awt.event.ActionListener() { 
275
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
276
                                        gps.silence();
277
                                }
278
                        });
279
                        btnPause.setText("Pause");
280
                        
281
                }
282
                return btnPause;
283
        }
284

    
285
        /**
286
         * This method initializes btnStop        
287
         *         
288
         * @return javax.swing.JButton        
289
         */    
290
        private JButton getBtnStop() {
291
                if (btnStop == null) {
292
                        btnStop = new JButton();
293
                        btnStop.setBounds(450, 140, 102, 40);
294
                        btnStop.addActionListener(new java.awt.event.ActionListener() { 
295
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
296
                                        gps.closePort();
297
                                }
298
                        });
299
                        btnStop.setText("Stop");
300
                }
301
                return btnStop;
302
        }
303

    
304
        /**
305
         * This method initializes cmvPorts        
306
         *         
307
         * @return javax.swing.JComboBox        
308
         */    
309
        private JComboBox getCmbPorts() {
310
                if (cmbPorts == null) {
311
                        cmbPorts = new JComboBox();
312
                        cmbPorts.setBounds(157, 80, 204, 20);
313
                }
314
                return cmbPorts;
315
        }
316

    
317
}  //  @jve:decl-index=0:visual-constraint="10,10"