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