root / trunk / extensions / extGPS / src / org / gvsig / gps / panel / TestPanel.java @ 13881
History | View | Annotate | Download (9.4 KB)
1 | 4720 | jaume | /* 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$
|
||
45 | * $Log$
|
||
46 | 13881 | jaume | * 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 | 7703 | luisw2 | * CRSFactory.getCRS substitutes ProjectionPool.get
|
51 | *
|
||
52 | * Revision 1.14 2006/08/29 11:52:17 jaume
|
||
53 | 6879 | jaume | * *** empty log message ***
|
54 | *
|
||
55 | 6897 | jaume | * Revision 1.13 2006/08/29 07:45:35 jaume
|
56 | * *** empty log message ***
|
||
57 | *
|
||
58 | 6879 | jaume | * Revision 1.12 2006/07/31 07:19:39 jaume
|
59 | 6569 | jaume | * improved appearance
|
60 | *
|
||
61 | * Revision 1.11 2006/07/31 06:46:02 jaume
|
||
62 | 4720 | jaume | * *** empty log message ***
|
63 | *
|
||
64 | 6389 | jaume | * Revision 1.9 2006/04/12 10:03:32 jaume
|
65 | * *** empty log message ***
|
||
66 | *
|
||
67 | 4829 | jaume | * Revision 1.8 2006/04/10 14:09:46 jaume
|
68 | * *** empty log message ***
|
||
69 | *
|
||
70 | 4787 | jaume | * Revision 1.7 2006/04/10 11:21:52 jaume
|
71 | * *** empty log message ***
|
||
72 | *
|
||
73 | 4784 | jaume | * Revision 1.6 2006/04/07 11:10:26 jaume
|
74 | * *** empty log message ***
|
||
75 | *
|
||
76 | 4763 | jaume | * Revision 1.5 2006/04/06 10:35:59 jaume
|
77 | * *** empty log message ***
|
||
78 | *
|
||
79 | 4752 | jaume | * Revision 1.4 2006/04/05 17:08:18 jaume
|
80 | * *** empty log message ***
|
||
81 | *
|
||
82 | 4749 | jaume | * Revision 1.3 2006/04/05 16:02:09 jaume
|
83 | * *** empty log message ***
|
||
84 | *
|
||
85 | 4747 | jaume | * Revision 1.2 2006/04/03 21:07:35 jaume
|
86 | * *** empty log message ***
|
||
87 | *
|
||
88 | 4722 | jaume | * Revision 1.1 2006/04/03 16:10:27 jaume
|
89 | * *** empty log message ***
|
||
90 | *
|
||
91 | 4720 | jaume | * Revision 1.1 2006/03/31 09:55:34 jaume
|
92 | * *** empty log message ***
|
||
93 | *
|
||
94 | *
|
||
95 | */
|
||
96 | /**
|
||
97 | 6567 | jaume | *
|
98 | 4720 | jaume | */
|
99 | package org.gvsig.gps.panel; |
||
100 | |||
101 | import gnu.io.CommPortIdentifier; |
||
102 | import gnu.io.PortInUseException; |
||
103 | 4752 | jaume | import gnu.io.SerialPort; |
104 | 4720 | jaume | |
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 | 6389 | jaume | import org.gvsig.gps.GPSDriver; |
117 | 4747 | jaume | import org.gvsig.gps.GPSExtension; |
118 | 4720 | jaume | import org.gvsig.gps.listeners.GPSEventListener; |
119 | 6569 | jaume | import org.gvsig.gui.beans.swing.JButton; |
120 | 4720 | jaume | |
121 | import com.iver.andami.PluginServices; |
||
122 | 6879 | jaume | import com.iver.andami.ui.mdiManager.IWindow; |
123 | 6897 | jaume | import com.iver.andami.ui.mdiManager.WindowInfo; |
124 | 7703 | luisw2 | import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
125 | 4720 | jaume | |
126 | /**
|
||
127 | * @author jaume
|
||
128 | *
|
||
129 | */
|
||
130 | 6879 | jaume | public class TestPanel extends JPanel implements IWindow{ |
131 | 4749 | jaume | private GPSDriver gps = GPSDriver.getInstance();;
|
132 | 4720 | jaume | 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 | 4749 | jaume | private boolean alreadyStarted; |
142 | 4720 | jaume | /**
|
143 | 6567 | jaume | *
|
144 | 4720 | jaume | */
|
145 | public TestPanel() {
|
||
146 | super();
|
||
147 | initialize(); |
||
148 | } |
||
149 | 6567 | jaume | |
150 | 4720 | jaume | /**
|
151 | * This method initializes this
|
||
152 | 6567 | jaume | *
|
153 | 4720 | jaume | * @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 | 4749 | jaume | this.add(lblSampleRate, null); |
181 | 4720 | jaume | this.add(getCmbPorts(), null); |
182 | Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
||
183 | while (portList.hasMoreElements()) {
|
||
184 | getCmbPorts().addItem(((CommPortIdentifier) portList.nextElement()).getName()); |
||
185 | } |
||
186 | 6567 | jaume | |
187 | |||
188 | 4720 | jaume | } |
189 | |||
190 | /**
|
||
191 | 6567 | jaume | * This method initializes jTextField
|
192 | *
|
||
193 | * @return javax.swing.JTextField
|
||
194 | */
|
||
195 | 4720 | jaume | private JTextField getTxtSampleRate() { |
196 | if (txtSampleRate == null) { |
||
197 | txtSampleRate = new JTextField(); |
||
198 | txtSampleRate.setBounds(157, 52, 204, 20); |
||
199 | 6567 | jaume | txtSampleRate.addKeyListener(new java.awt.event.KeyAdapter() {
|
200 | public void keyTyped(java.awt.event.KeyEvent e) { |
||
201 | 4720 | jaume | try {
|
202 | float time = Float.parseFloat(txtSampleRate.getText()); |
||
203 | gps.setSampleRate(Math.abs((int) (time * 1000))); |
||
204 | 6567 | jaume | |
205 | 4720 | jaume | } catch (Exception ex) { |
206 | txtSampleRate.setText("");
|
||
207 | }; |
||
208 | } |
||
209 | }); |
||
210 | } |
||
211 | return txtSampleRate;
|
||
212 | } |
||
213 | |||
214 | 6897 | jaume | 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 | 6567 | jaume | |
221 | 6897 | jaume | return m_WindowInfo;
|
222 | 4720 | jaume | } |
223 | |||
224 | /**
|
||
225 | 6567 | jaume | * This method initializes btnStart
|
226 | *
|
||
227 | * @return javax.swing.JButton
|
||
228 | */
|
||
229 | 4720 | jaume | private JButton getBtnStart() { |
230 | if (btnStart == null) { |
||
231 | btnStart = new JButton(); |
||
232 | btnStart.setBounds(49, 140, 104, 41); |
||
233 | 6567 | jaume | btnStart.addActionListener(new java.awt.event.ActionListener() {
|
234 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
235 | 4720 | jaume | start(); |
236 | } |
||
237 | }); |
||
238 | btnStart.setText("Start");
|
||
239 | } |
||
240 | return btnStart;
|
||
241 | } |
||
242 | |||
243 | 6567 | jaume | |
244 | 4720 | jaume | public void start() { |
245 | 4749 | jaume | 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 | 4752 | jaume | gps.setPort(myPortId, 4800, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
|
252 | 4749 | jaume | gps.addEventListener(new GPSEventListener() {
|
253 | 6567 | jaume | |
254 | 4749 | jaume | public void unhandledMessage(String message) { |
255 | System.out.println("unhandledMessage"+": "+message+"\n"); |
||
256 | lblPosValue.setText(message); |
||
257 | } |
||
258 | 6567 | jaume | |
259 | 4749 | jaume | public void connectionLost() { |
260 | System.out.println("connectionLost"); |
||
261 | } |
||
262 | 6567 | jaume | |
263 | 4749 | jaume | public void connectionEstablished() { |
264 | System.out.println("connectionEstablished"); |
||
265 | } |
||
266 | 6567 | jaume | |
267 | 4749 | jaume | public void newLonLatPositionReceived(double lon, double lat) { |
268 | 7703 | luisw2 | IProjection reqProj = CRSFactory.getCRS("EPSG:23030");
|
269 | IProjection latLonProj = CRSFactory.getCRS("EPSG:4326");
|
||
270 | 6567 | jaume | ICoordTrans ct = latLonProj.getCT(reqProj); |
271 | 4749 | jaume | Point2D pDst = new Point2D.Double(); |
272 | 4752 | jaume | Point2D pSrc = new Point2D.Double(lon, lat); |
273 | 4749 | jaume | pDst = ct.convert(pSrc, pDst); |
274 | lblPosValue.setText("("+pDst.getX()+", "+pDst.getY()+")"); |
||
275 | 6567 | jaume | |
276 | 4749 | jaume | GPSExtension ext = (GPSExtension) PluginServices.getExtension(GPSExtension.class); |
277 | 4763 | jaume | ext.drawSymbol(null, null, pDst, false); |
278 | 4749 | jaume | } |
279 | 6567 | jaume | |
280 | 4784 | jaume | public void signalQualityChanged(float level, int satellites, String qualityStatus) { |
281 | 4749 | jaume | } |
282 | 6567 | jaume | |
283 | 4749 | jaume | public void speedChanged(float speed, short course) { |
284 | } |
||
285 | 6567 | jaume | |
286 | 4749 | jaume | public void estimatedPosErrorChanged(double f) { |
287 | } |
||
288 | 4752 | jaume | |
289 | 4784 | jaume | public void altitudeChanged(float height) { |
290 | 4749 | jaume | } |
291 | 4752 | jaume | |
292 | public void precisionChanged(float pDop, float hDop, float vDop) { |
||
293 | } |
||
294 | 6567 | jaume | |
295 | 4749 | jaume | }); |
296 | 4829 | jaume | gps.connect(); |
297 | 4749 | jaume | alreadyStarted = true;
|
298 | } catch (PortInUseException e) {
|
||
299 | e.printStackTrace(); |
||
300 | } |
||
301 | } |
||
302 | 4720 | jaume | } |
303 | } |
||
304 | /**
|
||
305 | 6567 | jaume | * This method initializes btnStop
|
306 | *
|
||
307 | * @return javax.swing.JButton
|
||
308 | */
|
||
309 | 4720 | jaume | private JButton getBtnPause() { |
310 | if (btnPause == null) { |
||
311 | btnPause = new JButton(); |
||
312 | btnPause.setBounds(158, 140, 102, 40); |
||
313 | 6567 | jaume | btnPause.addActionListener(new java.awt.event.ActionListener() {
|
314 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
315 | 4720 | jaume | gps.silence(); |
316 | } |
||
317 | }); |
||
318 | btnPause.setText("Pause");
|
||
319 | 6567 | jaume | |
320 | 4720 | jaume | } |
321 | return btnPause;
|
||
322 | } |
||
323 | |||
324 | /**
|
||
325 | 6567 | jaume | * This method initializes btnStop
|
326 | *
|
||
327 | * @return javax.swing.JButton
|
||
328 | */
|
||
329 | 4720 | jaume | private JButton getBtnStop() { |
330 | if (btnStop == null) { |
||
331 | btnStop = new JButton(); |
||
332 | btnStop.setBounds(450, 140, 102, 40); |
||
333 | 6567 | jaume | btnStop.addActionListener(new java.awt.event.ActionListener() {
|
334 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
335 | 4829 | jaume | gps.close(); |
336 | 4720 | jaume | } |
337 | }); |
||
338 | btnStop.setText("Stop");
|
||
339 | } |
||
340 | return btnStop;
|
||
341 | } |
||
342 | |||
343 | /**
|
||
344 | 6567 | jaume | * This method initializes cmvPorts
|
345 | *
|
||
346 | * @return javax.swing.JComboBox
|
||
347 | */
|
||
348 | 4720 | jaume | 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" |