svn-gvsig-desktop / trunk / extensions / extGPS / src / org / gvsig / gps / panel / TestPanel.java @ 6389
History | View | Annotate | Download (9.16 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 6389 2006-07-17 10:27:44Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.10 2006-07-17 10:27:44 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.9 2006/04/12 10:03:32 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.8 2006/04/10 14:09:46 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.7 2006/04/10 11:21:52 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.6 2006/04/07 11:10:26 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.5 2006/04/06 10:35:59 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.4 2006/04/05 17:08:18 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.3 2006/04/05 16:02:09 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.2 2006/04/03 21:07:35 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.1 2006/04/03 16:10:27 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.1 2006/03/31 09:55:34 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
*
|
80 |
*/
|
81 |
/**
|
82 |
*
|
83 |
*/
|
84 |
package org.gvsig.gps.panel; |
85 |
|
86 |
import gnu.io.CommPortIdentifier; |
87 |
import gnu.io.PortInUseException; |
88 |
import gnu.io.SerialPort; |
89 |
|
90 |
import java.awt.geom.Point2D; |
91 |
import java.util.Enumeration; |
92 |
|
93 |
import javax.swing.JButton; |
94 |
import javax.swing.JComboBox; |
95 |
import javax.swing.JLabel; |
96 |
import javax.swing.JPanel; |
97 |
import javax.swing.JTextField; |
98 |
import javax.swing.SwingConstants; |
99 |
|
100 |
import org.cresques.cts.ICoordTrans; |
101 |
import org.cresques.cts.IProjection; |
102 |
import org.cresques.cts.ProjectionPool; |
103 |
import org.cresques.cts.gt2.CoordSys; |
104 |
import org.gvsig.gps.GPSDriver; |
105 |
import org.gvsig.gps.GPSExtension; |
106 |
import org.gvsig.gps.listeners.GPSEventListener; |
107 |
|
108 |
import com.iver.andami.PluginServices; |
109 |
import com.iver.andami.ui.mdiManager.View; |
110 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
111 |
|
112 |
/**
|
113 |
* @author jaume
|
114 |
*
|
115 |
*/
|
116 |
public class TestPanel extends JPanel implements View{ |
117 |
private GPSDriver gps = GPSDriver.getInstance();;
|
118 |
private JLabel lblSampleRate = null; |
119 |
private JTextField txtSampleRate = null; |
120 |
private JButton btnStart = null; |
121 |
private JButton btnPause = null; |
122 |
private JButton btnStop = null; |
123 |
private JLabel lblPort = null; |
124 |
private JComboBox cmbPorts = null; |
125 |
private JLabel lblPosValue; |
126 |
private JLabel lblPos; |
127 |
private boolean alreadyStarted; |
128 |
/**
|
129 |
*
|
130 |
*/
|
131 |
public TestPanel() {
|
132 |
super();
|
133 |
initialize(); |
134 |
} |
135 |
|
136 |
/**
|
137 |
* This method initializes this
|
138 |
*
|
139 |
* @return void
|
140 |
*/
|
141 |
private void initialize() { |
142 |
lblPort = new JLabel(); |
143 |
lblPort.setBounds(10, 80, 143, 20); |
144 |
lblPort.setText("Port:");
|
145 |
lblPort.setHorizontalAlignment(SwingConstants.RIGHT);
|
146 |
lblSampleRate = new JLabel(); |
147 |
lblSampleRate.setBounds(10, 52, 143, 20); |
148 |
lblSampleRate.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
149 |
lblSampleRate.setText("Frecuencia de muestreo:");
|
150 |
lblPosValue = new JLabel(); |
151 |
lblPosValue.setBounds(157, 25, 398, 20); |
152 |
lblPosValue.setFont(new java.awt.Font("MS Sans Serif", java.awt.Font.BOLD, 11)); |
153 |
lblPos = new JLabel(); |
154 |
lblPos.setText("Pos:");
|
155 |
lblPos.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
156 |
lblPos.setBounds(10, 25, 143, 20); |
157 |
this.setLayout(null); |
158 |
this.setSize(581, 200); |
159 |
this.add(lblPos, null); |
160 |
this.add(lblPosValue, null); |
161 |
this.add(getTxtSampleRate(), null); |
162 |
this.add(getBtnStart(), null); |
163 |
this.add(getBtnPause(), null); |
164 |
this.add(getBtnStop(), null); |
165 |
this.add(lblPort, null); |
166 |
this.add(lblSampleRate, null); |
167 |
this.add(getCmbPorts(), null); |
168 |
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
169 |
while (portList.hasMoreElements()) {
|
170 |
getCmbPorts().addItem(((CommPortIdentifier) portList.nextElement()).getName()); |
171 |
} |
172 |
|
173 |
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* This method initializes jTextField
|
178 |
*
|
179 |
* @return javax.swing.JTextField
|
180 |
*/
|
181 |
private JTextField getTxtSampleRate() { |
182 |
if (txtSampleRate == null) { |
183 |
txtSampleRate = new JTextField(); |
184 |
txtSampleRate.setBounds(157, 52, 204, 20); |
185 |
txtSampleRate.addKeyListener(new java.awt.event.KeyAdapter() {
|
186 |
public void keyTyped(java.awt.event.KeyEvent e) { |
187 |
try {
|
188 |
float time = Float.parseFloat(txtSampleRate.getText()); |
189 |
gps.setSampleRate(Math.abs((int) (time * 1000))); |
190 |
|
191 |
} catch (Exception ex) { |
192 |
txtSampleRate.setText("");
|
193 |
}; |
194 |
} |
195 |
}); |
196 |
} |
197 |
return txtSampleRate;
|
198 |
} |
199 |
|
200 |
public ViewInfo getViewInfo() {
|
201 |
ViewInfo m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE |
|
202 |
ViewInfo.MAXIMIZABLE | ViewInfo.RESIZABLE); |
203 |
m_viewInfo.setTitle(PluginServices.getText(this, "gps_control_panel")); |
204 |
m_viewInfo.setWidth(this.getWidth()+8); |
205 |
m_viewInfo.setHeight(this.getHeight()+8); |
206 |
|
207 |
return m_viewInfo;
|
208 |
} |
209 |
|
210 |
/**
|
211 |
* This method initializes btnStart
|
212 |
*
|
213 |
* @return javax.swing.JButton
|
214 |
*/
|
215 |
private JButton getBtnStart() { |
216 |
if (btnStart == null) { |
217 |
btnStart = new JButton(); |
218 |
btnStart.setBounds(49, 140, 104, 41); |
219 |
btnStart.addActionListener(new java.awt.event.ActionListener() {
|
220 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
221 |
start(); |
222 |
} |
223 |
}); |
224 |
btnStart.setText("Start");
|
225 |
} |
226 |
return btnStart;
|
227 |
} |
228 |
|
229 |
|
230 |
public void start() { |
231 |
if (!alreadyStarted) {
|
232 |
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
233 |
while (portList.hasMoreElements()) {
|
234 |
CommPortIdentifier myPortId = (CommPortIdentifier) portList.nextElement(); |
235 |
if (myPortId.getName().equals(getCmbPorts().getSelectedItem().toString()))
|
236 |
try {
|
237 |
gps.setPort(myPortId, 4800, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
|
238 |
gps.addEventListener(new GPSEventListener() {
|
239 |
|
240 |
public void unhandledMessage(String message) { |
241 |
System.out.println("unhandledMessage"+": "+message+"\n"); |
242 |
lblPosValue.setText(message); |
243 |
} |
244 |
|
245 |
public void connectionLost() { |
246 |
System.out.println("connectionLost"); |
247 |
} |
248 |
|
249 |
public void connectionEstablished() { |
250 |
System.out.println("connectionEstablished"); |
251 |
} |
252 |
|
253 |
public void newLonLatPositionReceived(double lon, double lat) { |
254 |
IProjection reqProj = ProjectionPool.get("EPSG:23030");
|
255 |
IProjection latLonProj = ProjectionPool.get("EPSG:4326");
|
256 |
ICoordTrans ct = latLonProj.getCT((CoordSys) reqProj); |
257 |
Point2D pDst = new Point2D.Double(); |
258 |
Point2D pSrc = new Point2D.Double(lon, lat); |
259 |
pDst = ct.convert(pSrc, pDst); |
260 |
lblPosValue.setText("("+pDst.getX()+", "+pDst.getY()+")"); |
261 |
|
262 |
GPSExtension ext = (GPSExtension) PluginServices.getExtension(GPSExtension.class); |
263 |
ext.drawSymbol(null, null, pDst, false); |
264 |
} |
265 |
|
266 |
public void signalQualityChanged(float level, int satellites, String qualityStatus) { |
267 |
} |
268 |
|
269 |
public void speedChanged(float speed, short course) { |
270 |
} |
271 |
|
272 |
public void estimatedPosErrorChanged(double f) { |
273 |
} |
274 |
|
275 |
public void altitudeChanged(float height) { |
276 |
} |
277 |
|
278 |
public void precisionChanged(float pDop, float hDop, float vDop) { |
279 |
} |
280 |
|
281 |
}); |
282 |
gps.connect(); |
283 |
alreadyStarted = true;
|
284 |
} catch (PortInUseException e) {
|
285 |
e.printStackTrace(); |
286 |
} |
287 |
} |
288 |
} |
289 |
} |
290 |
/**
|
291 |
* This method initializes btnStop
|
292 |
*
|
293 |
* @return javax.swing.JButton
|
294 |
*/
|
295 |
private JButton getBtnPause() { |
296 |
if (btnPause == null) { |
297 |
btnPause = new JButton(); |
298 |
btnPause.setBounds(158, 140, 102, 40); |
299 |
btnPause.addActionListener(new java.awt.event.ActionListener() {
|
300 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
301 |
gps.silence(); |
302 |
} |
303 |
}); |
304 |
btnPause.setText("Pause");
|
305 |
|
306 |
} |
307 |
return btnPause;
|
308 |
} |
309 |
|
310 |
/**
|
311 |
* This method initializes btnStop
|
312 |
*
|
313 |
* @return javax.swing.JButton
|
314 |
*/
|
315 |
private JButton getBtnStop() { |
316 |
if (btnStop == null) { |
317 |
btnStop = new JButton(); |
318 |
btnStop.setBounds(450, 140, 102, 40); |
319 |
btnStop.addActionListener(new java.awt.event.ActionListener() {
|
320 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
321 |
gps.close(); |
322 |
} |
323 |
}); |
324 |
btnStop.setText("Stop");
|
325 |
} |
326 |
return btnStop;
|
327 |
} |
328 |
|
329 |
/**
|
330 |
* This method initializes cmvPorts
|
331 |
*
|
332 |
* @return javax.swing.JComboBox
|
333 |
*/
|
334 |
private JComboBox getCmbPorts() { |
335 |
if (cmbPorts == null) { |
336 |
cmbPorts = new JComboBox(); |
337 |
cmbPorts.setBounds(157, 80, 204, 20); |
338 |
} |
339 |
return cmbPorts;
|
340 |
} |
341 |
|
342 |
} // @jve:decl-index=0:visual-constraint="10,10"
|