svn-gvsig-desktop / trunk / extensions / extGPS / src / org / gvsig / gps / panel / GPSControlPanel.java @ 4749
History | View | Annotate | Download (11.6 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: GPSControlPanel.java 4749 2006-04-05 17:08:18Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.5 2006-04-05 17:08:18 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.4 2006/04/05 16:02:09 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.3 2006/04/05 14:50:37 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.2 2006/04/03 17:10:03 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.1 2006/04/03 16:10:27 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
*
|
62 |
*/
|
63 |
package org.gvsig.gps.panel; |
64 |
|
65 |
import gnu.io.CommPortIdentifier; |
66 |
import gnu.io.PortInUseException; |
67 |
|
68 |
import java.awt.Component; |
69 |
import java.awt.geom.Point2D; |
70 |
import java.util.Enumeration; |
71 |
|
72 |
import javax.swing.AbstractButton; |
73 |
import javax.swing.JButton; |
74 |
import javax.swing.JComboBox; |
75 |
import javax.swing.JLabel; |
76 |
import javax.swing.JPanel; |
77 |
import javax.swing.JScrollPane; |
78 |
import javax.swing.JTable; |
79 |
import javax.swing.JTextField; |
80 |
import javax.swing.SwingConstants; |
81 |
import javax.swing.table.AbstractTableModel; |
82 |
import javax.swing.table.TableColumn; |
83 |
|
84 |
import org.cresques.cts.ICoordTrans; |
85 |
import org.cresques.cts.IProjection; |
86 |
import org.cresques.cts.ProjectionPool; |
87 |
import org.cresques.cts.gt2.CoordSys; |
88 |
import org.cresques.cts.gt2.CoordTrans; |
89 |
import org.gvsig.gps.GPSDriver; |
90 |
import org.gvsig.gps.GPSExtension; |
91 |
import org.gvsig.gps.listeners.GPSEventListener; |
92 |
|
93 |
import com.iver.andami.PluginServices; |
94 |
import com.iver.andami.ui.mdiManager.View; |
95 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
96 |
|
97 |
public class GPSControlPanel extends JPanel implements View { |
98 |
private boolean alreadyStarted; |
99 |
|
100 |
private GPSDriver gps;
|
101 |
|
102 |
private JPanel centerPanel = null; |
103 |
private JPanel northPanel = null; |
104 |
private JScrollPane jScrollPane = null; |
105 |
private JTable tblStatus = null; |
106 |
private StatusTableModel model;
|
107 |
private JButton btnStart = null; |
108 |
private JButton btnPause = null; |
109 |
private JButton btnStop = null; |
110 |
|
111 |
private JComboBox cmbPorts = null; |
112 |
|
113 |
private JLabel lblPort; |
114 |
|
115 |
private JLabel lblSampleRate; |
116 |
|
117 |
private JLabel lblPosValue; |
118 |
|
119 |
private JLabel lblPos; |
120 |
|
121 |
private JTextField txtSampleRate; |
122 |
|
123 |
|
124 |
public GPSControlPanel() {
|
125 |
super();
|
126 |
gps = GPSDriver.getInstance(); |
127 |
initialize(); |
128 |
} |
129 |
|
130 |
/**
|
131 |
* This method initializes this
|
132 |
*
|
133 |
* @return void
|
134 |
*/
|
135 |
private void initialize() { |
136 |
lblPort = new JLabel(); |
137 |
lblPort.setBounds(10, 80, 143, 20); |
138 |
lblPort.setText("Port:");
|
139 |
lblPort.setHorizontalAlignment(SwingConstants.RIGHT);
|
140 |
lblSampleRate = new JLabel(); |
141 |
lblSampleRate.setBounds(10, 52, 143, 20); |
142 |
lblSampleRate.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
143 |
lblSampleRate.setText("Frecuencia de muestreo:");
|
144 |
lblPosValue = new JLabel(); |
145 |
lblPosValue.setBounds(156, 25, 223, 20); |
146 |
lblPosValue.setFont(new java.awt.Font("MS Sans Serif", java.awt.Font.BOLD, 11)); |
147 |
lblPos = new JLabel(); |
148 |
lblPos.setText("Pos:");
|
149 |
lblPos.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
150 |
lblPos.setBounds(10, 25, 143, 20); |
151 |
this.setLayout(null); |
152 |
this.setSize(391, 433); |
153 |
this.add(getCenterPanel(), java.awt.BorderLayout.CENTER);
|
154 |
this.add(getNorthPanel(), java.awt.BorderLayout.NORTH);
|
155 |
this.add(getBtnStart(), null); |
156 |
this.add(getBtnPause(), null); |
157 |
this.add(getBtnStop(), null); |
158 |
|
159 |
} |
160 |
|
161 |
public ViewInfo getViewInfo() {
|
162 |
ViewInfo m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE |
|
163 |
ViewInfo.MAXIMIZABLE | ViewInfo.RESIZABLE); |
164 |
m_viewInfo.setTitle(PluginServices.getText(this, "GPS Control panel")); |
165 |
m_viewInfo.setWidth(this.getWidth()+8); |
166 |
m_viewInfo.setHeight(this.getHeight()+8); |
167 |
|
168 |
return m_viewInfo;
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* This method initializes southPanel
|
173 |
*
|
174 |
* @return javax.swing.JPanel
|
175 |
*/
|
176 |
private JPanel getCenterPanel() { |
177 |
if (centerPanel == null) { |
178 |
centerPanel = new JPanel(); |
179 |
centerPanel.setLayout(null);
|
180 |
centerPanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
181 |
null, PluginServices.getText(this, "gps_status"), |
182 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
183 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
184 |
centerPanel.setSize(383, 291); |
185 |
centerPanel.setLocation(5, 111); |
186 |
centerPanel.add(getJScrollPane(), java.awt.BorderLayout.NORTH); |
187 |
} |
188 |
return centerPanel;
|
189 |
} |
190 |
|
191 |
/**
|
192 |
* This method initializes northPanel
|
193 |
*
|
194 |
* @return javax.swing.JPanel
|
195 |
*/
|
196 |
private JPanel getNorthPanel() { |
197 |
if (northPanel == null) { |
198 |
northPanel = new JPanel(); |
199 |
northPanel.setLayout(null);
|
200 |
northPanel.setSize(385, 105); |
201 |
northPanel.setLocation(0, 2); |
202 |
northPanel.add(getCmbPorts(), null);
|
203 |
northPanel.add(lblPos, null);
|
204 |
northPanel.add(lblPosValue, null);
|
205 |
northPanel.add(getTxtSampleRate(), null);
|
206 |
northPanel.add(lblPort, null);
|
207 |
northPanel.add(lblSampleRate, null);
|
208 |
} |
209 |
return northPanel;
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* This method initializes jTextField
|
214 |
*
|
215 |
* @return javax.swing.JTextField
|
216 |
*/
|
217 |
private JTextField getTxtSampleRate() { |
218 |
if (txtSampleRate == null) { |
219 |
txtSampleRate = new JTextField(); |
220 |
txtSampleRate.setBounds(156, 52, 223, 20); |
221 |
txtSampleRate.addKeyListener(new java.awt.event.KeyAdapter() {
|
222 |
public void keyTyped(java.awt.event.KeyEvent e) { |
223 |
try {
|
224 |
float time = Float.parseFloat(txtSampleRate.getText()); |
225 |
gps.setSampleRate(Math.abs((int) (time * 1000))); |
226 |
|
227 |
} catch (Exception ex) { |
228 |
txtSampleRate.setText("");
|
229 |
}; |
230 |
} |
231 |
}); |
232 |
} |
233 |
return txtSampleRate;
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* This method initializes jScrollPane
|
238 |
*
|
239 |
* @return javax.swing.JScrollPane
|
240 |
*/
|
241 |
private JScrollPane getJScrollPane() { |
242 |
if (jScrollPane == null) { |
243 |
jScrollPane = new JScrollPane(); |
244 |
jScrollPane.setSize(370, 261); |
245 |
jScrollPane.setLocation(5, 25); |
246 |
jScrollPane.setViewportView(getTblStatus()); |
247 |
} |
248 |
return jScrollPane;
|
249 |
} |
250 |
|
251 |
/**
|
252 |
* This method initializes tbl
|
253 |
*
|
254 |
* @return javax.swing.JTable
|
255 |
*/
|
256 |
private JTable getTblStatus() { |
257 |
if (tblStatus == null) { |
258 |
tblStatus = new JTable(); |
259 |
TableColumn column = null; |
260 |
for (int i = 0; i < tblStatus.getColumnCount(); i++) { |
261 |
column = tblStatus.getColumnModel().getColumn(i); |
262 |
int width = (int) (tblStatus.getWidth()*0.3); |
263 |
if (i==0) { |
264 |
column.setWidth(width); |
265 |
} else {
|
266 |
column.setWidth(tblStatus.getWidth()-width); |
267 |
} |
268 |
} |
269 |
tblStatus.setTableHeader(null);
|
270 |
model = new StatusTableModel();
|
271 |
tblStatus.setModel(model); |
272 |
} |
273 |
return tblStatus;
|
274 |
} |
275 |
|
276 |
/**
|
277 |
* This method initializes jButton
|
278 |
*
|
279 |
* @return javax.swing.JButton
|
280 |
*/
|
281 |
private JButton getBtnStart() { |
282 |
if (btnStart == null) { |
283 |
btnStart = new JButton(); |
284 |
btnStart.setText("Start");
|
285 |
btnStart.setBounds(75, 405, 70, 20); |
286 |
btnStart.addActionListener(new java.awt.event.ActionListener() {
|
287 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
288 |
start(); |
289 |
} |
290 |
}); |
291 |
} |
292 |
return btnStart;
|
293 |
} |
294 |
|
295 |
/**
|
296 |
* This method initializes jButton1
|
297 |
*
|
298 |
* @return javax.swing.JButton
|
299 |
*/
|
300 |
private JButton getBtnPause() { |
301 |
if (btnPause == null) { |
302 |
btnPause = new JButton(); |
303 |
btnPause.setBounds(150, 405, 70, 20); |
304 |
btnPause.setText("Pause");
|
305 |
btnPause.addActionListener(new java.awt.event.ActionListener() {
|
306 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
307 |
gps.silence(); |
308 |
} |
309 |
}); |
310 |
} |
311 |
return btnPause;
|
312 |
} |
313 |
|
314 |
/**
|
315 |
* This method initializes jButton2
|
316 |
*
|
317 |
* @return javax.swing.JButton
|
318 |
*/
|
319 |
private JButton getBtnStop() { |
320 |
if (btnStop == null) { |
321 |
btnStop = new JButton(); |
322 |
btnStop.setBounds(270, 405, 70, 21); |
323 |
btnStop.setText("Stop");
|
324 |
btnStop.addActionListener(new java.awt.event.ActionListener() {
|
325 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
326 |
gps.closePort(); |
327 |
} |
328 |
}); |
329 |
} |
330 |
return btnStop;
|
331 |
} |
332 |
|
333 |
/**
|
334 |
* This method initializes jComboBox
|
335 |
*
|
336 |
* @return javax.swing.JComboBox
|
337 |
*/
|
338 |
private JComboBox getCmbPorts() { |
339 |
if (cmbPorts == null) { |
340 |
cmbPorts = new JComboBox(); |
341 |
cmbPorts.setBounds(156, 80, 166, 20); |
342 |
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
343 |
while (portList.hasMoreElements()) {
|
344 |
cmbPorts.addItem(((CommPortIdentifier) portList.nextElement()).getName()); |
345 |
} |
346 |
|
347 |
} |
348 |
return cmbPorts;
|
349 |
} |
350 |
|
351 |
public void start() { |
352 |
if (!alreadyStarted) {
|
353 |
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
354 |
while (portList.hasMoreElements()) {
|
355 |
CommPortIdentifier myPortId = (CommPortIdentifier) portList.nextElement(); |
356 |
if (myPortId.getName().equals(getCmbPorts().getSelectedItem().toString()))
|
357 |
try {
|
358 |
|
359 |
gps.setPort(myPortId, 4800);
|
360 |
gps.addEventListener(new GPSEventListener() {
|
361 |
|
362 |
public void unhandledMessage(String message) { |
363 |
System.out.println("unhandledMessage"+": "+message+"\n"); |
364 |
lblPosValue.setText(message); |
365 |
} |
366 |
|
367 |
public void connectionLost() { |
368 |
System.out.println("connectionLost"); |
369 |
} |
370 |
|
371 |
public void connectionEstablished() { |
372 |
System.out.println("connectionEstablished"); |
373 |
} |
374 |
|
375 |
public void newLonLatPositionReceived(double lon, double lat) { |
376 |
IProjection reqProj = ProjectionPool.get("EPSG:23030");
|
377 |
IProjection latLonProj = ProjectionPool.get("EPSG:4326");
|
378 |
ICoordTrans ct = new CoordTrans((CoordSys) latLonProj, (CoordSys) reqProj);
|
379 |
Point2D pDst = new Point2D.Double(); |
380 |
//Point2D pSrc = new Point2D.Double(lon, lat);
|
381 |
Point2D pSrc = new Point2D.Double(-0.36297333240509033, 39.463722229003906); |
382 |
pDst = ct.convert(pSrc, pDst); |
383 |
lblPosValue.setText("("+pDst.getX()+", "+pDst.getY()+")"); |
384 |
|
385 |
GPSExtension ext = (GPSExtension) PluginServices.getExtension(GPSExtension.class); |
386 |
ext.drawPoint(null, null, pDst); |
387 |
} |
388 |
|
389 |
public void signalLevelChanged(float level) { |
390 |
} |
391 |
|
392 |
public void speedChanged(float speed, short course) { |
393 |
} |
394 |
|
395 |
public void estimatedPosErrorChanged(double f) { |
396 |
} |
397 |
|
398 |
public void heightChanged() { |
399 |
} |
400 |
|
401 |
}); |
402 |
gps.start(); |
403 |
alreadyStarted = true;
|
404 |
} catch (PortInUseException e) {
|
405 |
// TODO Auto-generated catch block
|
406 |
e.printStackTrace(); |
407 |
} |
408 |
} |
409 |
} |
410 |
} |
411 |
} // @jve:decl-index=0:visual-constraint="13,3"
|
412 |
|
413 |
class StatusTableModel extends AbstractTableModel { |
414 |
private String[] keys, values; |
415 |
|
416 |
public void setTableData(String[] keys, String[] values) { |
417 |
this.keys = keys;
|
418 |
this.values = values;
|
419 |
} |
420 |
|
421 |
public int getColumnCount() { |
422 |
return 2; |
423 |
} |
424 |
|
425 |
public int getRowCount() { |
426 |
if (keys==null) return 0; |
427 |
return keys.length;
|
428 |
} |
429 |
|
430 |
public Object getValueAt(int rowIndex, int columnIndex) { |
431 |
if (columnIndex == 0) |
432 |
return values[rowIndex];
|
433 |
else if (columnIndex == 1) |
434 |
return keys[rowIndex];
|
435 |
return null; |
436 |
} |
437 |
|
438 |
|
439 |
|
440 |
} |
441 |
|