svn-gvsig-desktop / trunk / extensions / extGPS / src / org / gvsig / gps / panel / GPSControlPanel.java @ 4829
History | View | Annotate | Download (17.8 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 | 4829 | jaume | * Revision 1.17 2006-04-12 10:03:32 jaume
|
47 | 4720 | jaume | * *** empty log message ***
|
48 | *
|
||
49 | 4829 | jaume | * Revision 1.16 2006/04/12 06:51:56 jaume
|
50 | * *** empty log message ***
|
||
51 | *
|
||
52 | 4826 | jaume | * Revision 1.14 2006/04/11 13:19:51 jaume
|
53 | * *** empty log message ***
|
||
54 | *
|
||
55 | 4805 | jaume | * Revision 1.13 2006/04/10 17:13:28 jaume
|
56 | * *** empty log message ***
|
||
57 | *
|
||
58 | 4788 | jaume | * Revision 1.12 2006/04/10 14:09:46 jaume
|
59 | * *** empty log message ***
|
||
60 | *
|
||
61 | 4787 | jaume | * Revision 1.11 2006/04/10 11:21:52 jaume
|
62 | * *** empty log message ***
|
||
63 | *
|
||
64 | 4784 | jaume | * Revision 1.10 2006/04/07 12:45:55 jaume
|
65 | * *** empty log message ***
|
||
66 | *
|
||
67 | 4768 | jaume | * Revision 1.9 2006/04/07 11:10:26 jaume
|
68 | * *** empty log message ***
|
||
69 | *
|
||
70 | 4763 | jaume | * Revision 1.8 2006/04/07 08:27:48 jaume
|
71 | * *** empty log message ***
|
||
72 | *
|
||
73 | 4753 | jaume | * Revision 1.7 2006/04/06 10:35:48 jaume
|
74 | * *** empty log message ***
|
||
75 | *
|
||
76 | 4751 | jaume | * Revision 1.5 2006/04/05 17:08:18 jaume
|
77 | * *** empty log message ***
|
||
78 | *
|
||
79 | 4749 | jaume | * Revision 1.4 2006/04/05 16:02:09 jaume
|
80 | * *** empty log message ***
|
||
81 | *
|
||
82 | 4747 | jaume | * Revision 1.3 2006/04/05 14:50:37 jaume
|
83 | * *** empty log message ***
|
||
84 | *
|
||
85 | 4746 | jaume | * Revision 1.2 2006/04/03 17:10:03 jaume
|
86 | * *** empty log message ***
|
||
87 | *
|
||
88 | 4721 | jaume | * Revision 1.1 2006/04/03 16:10:27 jaume
|
89 | * *** empty log message ***
|
||
90 | 4720 | jaume | *
|
91 | 4721 | jaume | *
|
92 | 4720 | jaume | */
|
93 | package org.gvsig.gps.panel; |
||
94 | |||
95 | 4749 | jaume | import gnu.io.CommPortIdentifier; |
96 | import gnu.io.PortInUseException; |
||
97 | 4752 | jaume | import gnu.io.SerialPort; |
98 | 4720 | jaume | |
99 | 4749 | jaume | import java.awt.geom.Point2D; |
100 | 4753 | jaume | import java.util.ArrayList; |
101 | 4749 | jaume | import java.util.Enumeration; |
102 | 4753 | jaume | import java.util.Hashtable; |
103 | 4749 | jaume | |
104 | 4747 | jaume | import javax.swing.JButton; |
105 | 4749 | jaume | import javax.swing.JLabel; |
106 | 4752 | jaume | import javax.swing.JOptionPane; |
107 | 4720 | jaume | import javax.swing.JPanel; |
108 | import javax.swing.JScrollPane; |
||
109 | import javax.swing.JTable; |
||
110 | 4753 | jaume | import javax.swing.event.TableModelEvent; |
111 | 4721 | jaume | import javax.swing.table.AbstractTableModel; |
112 | 4720 | jaume | |
113 | 4749 | jaume | import org.gvsig.gps.GPSDriver; |
114 | import org.gvsig.gps.GPSExtension; |
||
115 | import org.gvsig.gps.listeners.GPSEventListener; |
||
116 | |||
117 | 4720 | jaume | import com.iver.andami.PluginServices; |
118 | 4753 | jaume | import com.iver.andami.plugins.Extension; |
119 | import com.iver.andami.ui.mdiManager.SingletonView; |
||
120 | 4720 | jaume | import com.iver.andami.ui.mdiManager.ViewInfo; |
121 | 4752 | jaume | import com.iver.utiles.XMLEntity; |
122 | 4829 | jaume | import com.sun.media.jai.util.Rational; |
123 | 4753 | jaume | /**
|
124 | * Singleton view that allows the user to monitorize and configure the
|
||
125 | * status of the GPS.
|
||
126 | *
|
||
127 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
128 | */
|
||
129 | public class GPSControlPanel extends JPanel implements SingletonView { |
||
130 | 4749 | jaume | private boolean alreadyStarted; |
131 | private GPSDriver gps;
|
||
132 | 4721 | jaume | private JPanel centerPanel = null; |
133 | private JPanel northPanel = null; |
||
134 | private JScrollPane jScrollPane = null; |
||
135 | private JTable tblStatus = null; |
||
136 | 4752 | jaume | private StatusTableModel model;
|
137 | 4749 | jaume | private JButton btnStart = null; |
138 | private JButton btnPause = null; |
||
139 | private JButton btnStop = null; |
||
140 | 4752 | jaume | private JButton btnConfig = null; |
141 | private CommPortIdentifier port;
|
||
142 | private int portSpeed; |
||
143 | private int dataBits; |
||
144 | private int stopBits; |
||
145 | private int parity; |
||
146 | 4829 | jaume | private boolean paused; |
147 | 4749 | jaume | |
148 | 4753 | jaume | private final static Extension thisExtension = PluginServices.getExtension(GPSExtension.class); |
149 | 4788 | jaume | private final static String kPos = PluginServices.getText(thisExtension, "GEO_position"); |
150 | 4784 | jaume | private final static String kPort = PluginServices.getText(thisExtension, "port"); |
151 | 4788 | jaume | private final static String kPortSpeed = PluginServices.getText(thisExtension, "port_speed"); |
152 | 4753 | jaume | private final static String kMsg = PluginServices.getText(thisExtension, "unknown_message"); |
153 | private final static String kSignalLevel = PluginServices.getText(thisExtension, "signal_stregth"); |
||
154 | private final static String kStatus = PluginServices.getText(thisExtension, "status"); |
||
155 | private final static String kSpeed = PluginServices.getText(thisExtension, "speed"); |
||
156 | private final static String kCourse = PluginServices.getText(thisExtension, "course"); |
||
157 | private final static String kEstErr = PluginServices.getText(thisExtension, "estimated_error"); |
||
158 | 4787 | jaume | private final static String kAltitude = PluginServices.getText(thisExtension, "altitude"); |
159 | 4753 | jaume | private final static String kPosPrecision = PluginServices.getText(thisExtension, "position_precision"); |
160 | private final static String kHorPrecision = PluginServices.getText(thisExtension, "horizontal_precision"); |
||
161 | private final static String kVerPrecision = PluginServices.getText(thisExtension, "vertical_precision"); |
||
162 | 4784 | jaume | private final static String kSatellitesInView = PluginServices.getText(thisExtension, "satellites_in_view"); |
163 | 4753 | jaume | |
164 | private static GPSControlPanel instance; |
||
165 | |||
166 | 4749 | jaume | |
167 | 4753 | jaume | private GPSControlPanel() {
|
168 | 4720 | jaume | super();
|
169 | 4749 | jaume | gps = GPSDriver.getInstance(); |
170 | 4753 | jaume | |
171 | initialize(); |
||
172 | refreshTable(); |
||
173 | 4788 | jaume | setUp(); |
174 | 4753 | jaume | } |
175 | |||
176 | private void refreshTable() { |
||
177 | model.putValue(kPos , PluginServices.getText(this, "unknown")); |
||
178 | 4784 | jaume | model.putValue(kPort, (port!=null) ? port.getName() : PluginServices.getText(this, "not_yet_set")); |
179 | 4788 | jaume | model.putValue(kPortSpeed, portSpeed+"");
|
180 | 4753 | jaume | |
181 | } |
||
182 | |||
183 | private void setUp() { |
||
184 | 4752 | jaume | XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
|
185 | // Try to restore last port used
|
||
186 | String portName = null; |
||
187 | 4753 | jaume | if (xml.contains("gps-serialPortName")) { |
188 | portName = xml.getStringProperty("gps-serialPortName");
|
||
189 | 4752 | jaume | } |
190 | Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
||
191 | while (portName!=null && portList.hasMoreElements()) { |
||
192 | CommPortIdentifier myPort = (CommPortIdentifier) portList.nextElement(); |
||
193 | if (portName.equals(myPort.getName())) {
|
||
194 | setPort(myPort); |
||
195 | } |
||
196 | } |
||
197 | if (!xml.contains("gps-serialPortSpeed")) |
||
198 | xml.putProperty("gps-serialPortSpeed", 4800); |
||
199 | if (!xml.contains("gps-serialPortDataBits")) |
||
200 | xml.putProperty("gps-serialPortDataBits" , "8"); |
||
201 | if (!xml.contains("gps-serialPortStopBits")) |
||
202 | 4753 | jaume | xml.putProperty("gps-serialPortStopBits", "1"); |
203 | 4752 | jaume | if (!xml.contains("gps-serialPortParities")) |
204 | xml.putProperty("gps-serialPortParities", "none"); |
||
205 | |||
206 | 4753 | jaume | setPortSpeed(xml.getIntProperty("gps-serialPortSpeed"));
|
207 | setPortDataBits(xml.getIntProperty("gps-serialPortDataBits"));
|
||
208 | 4752 | jaume | setPortStopBits(xml.getStringProperty("gps-serialPortStopBits"));
|
209 | setPortParity(xml.getStringProperty("gps-serialPortParities"));
|
||
210 | 4720 | jaume | } |
211 | |||
212 | 4805 | jaume | |
213 | |||
214 | 4753 | jaume | public static GPSControlPanel getInstance() { |
215 | if (instance == null) |
||
216 | instance = new GPSControlPanel();
|
||
217 | return instance;
|
||
218 | } |
||
219 | |||
220 | 4720 | jaume | /**
|
221 | * This method initializes this
|
||
222 | *
|
||
223 | * @return void
|
||
224 | */
|
||
225 | private void initialize() { |
||
226 | 4749 | jaume | this.setLayout(null); |
227 | 4753 | jaume | this.setSize(572, 433); |
228 | 4746 | jaume | this.add(getCenterPanel(), java.awt.BorderLayout.CENTER);
|
229 | 4721 | jaume | this.add(getNorthPanel(), java.awt.BorderLayout.NORTH);
|
230 | 4749 | jaume | this.add(getBtnStart(), null); |
231 | this.add(getBtnPause(), null); |
||
232 | this.add(getBtnStop(), null); |
||
233 | |||
234 | 4720 | jaume | } |
235 | |||
236 | public ViewInfo getViewInfo() {
|
||
237 | 4753 | jaume | ViewInfo m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE);
|
238 | 4752 | jaume | m_viewInfo.setTitle(PluginServices.getText(this, "gps_control_panel")); |
239 | 4749 | jaume | m_viewInfo.setWidth(this.getWidth()+8); |
240 | m_viewInfo.setHeight(this.getHeight()+8); |
||
241 | 4720 | jaume | |
242 | return m_viewInfo;
|
||
243 | } |
||
244 | |||
245 | 4721 | jaume | /**
|
246 | * This method initializes southPanel
|
||
247 | *
|
||
248 | * @return javax.swing.JPanel
|
||
249 | */
|
||
250 | private JPanel getCenterPanel() { |
||
251 | if (centerPanel == null) { |
||
252 | centerPanel = new JPanel(); |
||
253 | 4749 | jaume | centerPanel.setLayout(null);
|
254 | 4721 | jaume | centerPanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
255 | null, PluginServices.getText(this, "gps_status"), |
||
256 | javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
||
257 | javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
||
258 | 4768 | jaume | centerPanel.setSize(572, 261); |
259 | centerPanel.setLocation(0, 141); |
||
260 | 4721 | jaume | centerPanel.add(getJScrollPane(), java.awt.BorderLayout.NORTH); |
261 | 4752 | jaume | centerPanel.add(getBtnConfig(), null);
|
262 | 4721 | jaume | } |
263 | return centerPanel;
|
||
264 | } |
||
265 | |||
266 | /**
|
||
267 | * This method initializes northPanel
|
||
268 | *
|
||
269 | * @return javax.swing.JPanel
|
||
270 | */
|
||
271 | private JPanel getNorthPanel() { |
||
272 | if (northPanel == null) { |
||
273 | northPanel = new JPanel(); |
||
274 | 4749 | jaume | northPanel.setLayout(null);
|
275 | 4768 | jaume | northPanel.setSize(572, 142); |
276 | 4753 | jaume | northPanel.setLocation(0, 0); |
277 | 4721 | jaume | } |
278 | return northPanel;
|
||
279 | 4784 | jaume | } |
280 | 4721 | jaume | |
281 | /**
|
||
282 | * This method initializes jScrollPane
|
||
283 | *
|
||
284 | * @return javax.swing.JScrollPane
|
||
285 | */
|
||
286 | private JScrollPane getJScrollPane() { |
||
287 | if (jScrollPane == null) { |
||
288 | jScrollPane = new JScrollPane(); |
||
289 | 4788 | jaume | jScrollPane.setSize(560, 212); |
290 | jScrollPane.setLocation(5, 19); |
||
291 | 4721 | jaume | jScrollPane.setViewportView(getTblStatus()); |
292 | } |
||
293 | return jScrollPane;
|
||
294 | } |
||
295 | |||
296 | /**
|
||
297 | 4752 | jaume | * This method initializes tblStatus
|
298 | 4721 | jaume | *
|
299 | * @return javax.swing.JTable
|
||
300 | */
|
||
301 | private JTable getTblStatus() { |
||
302 | if (tblStatus == null) { |
||
303 | tblStatus = new JTable(); |
||
304 | 4753 | jaume | tblStatus.setShowHorizontalLines(false);
|
305 | |||
306 | 4721 | jaume | model = new StatusTableModel();
|
307 | tblStatus.setModel(model); |
||
308 | } |
||
309 | return tblStatus;
|
||
310 | } |
||
311 | |||
312 | /**
|
||
313 | 4752 | jaume | * This method initializes btnStart
|
314 | 4721 | jaume | *
|
315 | * @return javax.swing.JButton
|
||
316 | */
|
||
317 | 4749 | jaume | private JButton getBtnStart() { |
318 | if (btnStart == null) { |
||
319 | btnStart = new JButton(); |
||
320 | 4752 | jaume | btnStart.setText("start");
|
321 | 4768 | jaume | btnStart.setBounds(214, 405, 70, 25); |
322 | 4749 | jaume | btnStart.addActionListener(new java.awt.event.ActionListener() {
|
323 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
324 | start(); |
||
325 | } |
||
326 | }); |
||
327 | 4721 | jaume | } |
328 | 4749 | jaume | return btnStart;
|
329 | 4721 | jaume | } |
330 | |||
331 | 4749 | jaume | /**
|
332 | 4752 | jaume | * This method initializes btnPause
|
333 | 4749 | jaume | *
|
334 | * @return javax.swing.JButton
|
||
335 | */
|
||
336 | private JButton getBtnPause() { |
||
337 | if (btnPause == null) { |
||
338 | btnPause = new JButton(); |
||
339 | 4768 | jaume | btnPause.setBounds(289, 405, 70, 25); |
340 | 4753 | jaume | btnPause.setText("pause");
|
341 | 4829 | jaume | paused = false;
|
342 | 4749 | jaume | btnPause.addActionListener(new java.awt.event.ActionListener() {
|
343 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
344 | 4829 | jaume | pause(); |
345 | 4749 | jaume | } |
346 | }); |
||
347 | } |
||
348 | return btnPause;
|
||
349 | } |
||
350 | |||
351 | 4829 | jaume | private void pause() { |
352 | getBtnPause().setText((paused) ? PluginServices.getText(this, "pause") : PluginServices.getText(this, "resume") ); |
||
353 | if (paused)
|
||
354 | gps.connect(); |
||
355 | else
|
||
356 | gps.silence(); |
||
357 | paused = !paused; |
||
358 | } |
||
359 | |||
360 | 4749 | jaume | /**
|
361 | 4752 | jaume | * This method initializes btnStop
|
362 | 4749 | jaume | *
|
363 | * @return javax.swing.JButton
|
||
364 | */
|
||
365 | private JButton getBtnStop() { |
||
366 | if (btnStop == null) { |
||
367 | btnStop = new JButton(); |
||
368 | 4768 | jaume | btnStop.setBounds(409, 405, 70, 25); |
369 | 4752 | jaume | btnStop.setText("stop");
|
370 | 4749 | jaume | btnStop.addActionListener(new java.awt.event.ActionListener() {
|
371 | 4829 | jaume | public void actionPerformed(java.awt.event.ActionEvent e) { |
372 | stop(); |
||
373 | |||
374 | 4749 | jaume | } |
375 | }); |
||
376 | 4753 | jaume | alreadyStarted = false;
|
377 | 4749 | jaume | } |
378 | return btnStop;
|
||
379 | } |
||
380 | 4753 | jaume | |
381 | 4829 | jaume | private void stop() { |
382 | alreadyStarted = false;
|
||
383 | getBtnPause().setEnabled(false);
|
||
384 | getBtnPause().setText(PluginServices.getText(this, "pause")); |
||
385 | getBtnStart().setEnabled(true);
|
||
386 | gps.close(); |
||
387 | } |
||
388 | |||
389 | 4753 | jaume | protected void refresh() { |
390 | this.repaint();
|
||
391 | } |
||
392 | 4752 | jaume | |
393 | public void start() { |
||
394 | if (!alreadyStarted && port!=null) { |
||
395 | try {
|
||
396 | |||
397 | gps.setPort(port, portSpeed, dataBits, stopBits, parity); |
||
398 | 4829 | jaume | model.clear(); |
399 | refreshTable(); |
||
400 | paused = false;
|
||
401 | getBtnPause().setText(PluginServices.getText(this, "pause")); |
||
402 | getBtnPause().setEnabled(true);
|
||
403 | getBtnStart().setEnabled(false);
|
||
404 | 4752 | jaume | gps.addEventListener(new GPSEventListener() {
|
405 | 4753 | jaume | private TableModelEvent e = new TableModelEvent(model); |
406 | 4752 | jaume | public void unhandledMessage(String message) { |
407 | 4753 | jaume | model.putValue(kMsg, message); |
408 | tblStatus.tableChanged(e); |
||
409 | 4752 | jaume | } |
410 | |||
411 | public void connectionLost() { |
||
412 | 4753 | jaume | model.putValue(kStatus, PluginServices.getText(this, "off")); |
413 | tblStatus.tableChanged(e); |
||
414 | 4752 | jaume | } |
415 | |||
416 | public void connectionEstablished() { |
||
417 | 4753 | jaume | model.putValue(kStatus, PluginServices.getText(this, "on")); |
418 | tblStatus.tableChanged(e); |
||
419 | 4752 | jaume | } |
420 | |||
421 | public void newLonLatPositionReceived(double lon, double lat) { |
||
422 | 4753 | jaume | Point2D p = new Point2D.Double(lon, lat); |
423 | 4788 | jaume | char cLon = (lon>=0D) ? 'E' : 'W'; |
424 | char cLat = (lat>=0D) ? 'N' : 'S'; |
||
425 | 4805 | jaume | model.putValue(kPos, Math.abs(lat)+""+cLat+", "+Math.abs(lon)+cLon); |
426 | 4753 | jaume | tblStatus.tableChanged(e); |
427 | // esto igual ho hauria de canviar.
|
||
428 | 4827 | jaume | ((GPSExtension) thisExtension).drawSymbol(null, null, p, false); |
429 | 4752 | jaume | } |
430 | |||
431 | 4784 | jaume | public void signalQualityChanged(float level, int satellites, String qualityStatus) { |
432 | 4753 | jaume | model.putValue(kSignalLevel , level+"");
|
433 | 4784 | jaume | model.putValue(kSatellitesInView, satellites+"");
|
434 | 4753 | jaume | tblStatus.tableChanged(e); |
435 | 4752 | jaume | } |
436 | |||
437 | public void speedChanged(float speed, short course) { |
||
438 | 4753 | jaume | model.putValue(kSpeed, speed+"");
|
439 | model.putValue(kCourse, course+"?");
|
||
440 | tblStatus.tableChanged(e); |
||
441 | 4752 | jaume | } |
442 | |||
443 | 4753 | jaume | public void estimatedPosErrorChanged(double err) { |
444 | model.putValue(kEstErr, err+"");
|
||
445 | tblStatus.tableChanged(e); |
||
446 | 4752 | jaume | } |
447 | |||
448 | 4784 | jaume | public void altitudeChanged(float height) { |
449 | 4787 | jaume | model.putValue(kAltitude, height+"");
|
450 | 4753 | jaume | tblStatus.tableChanged(e); |
451 | 4752 | jaume | } |
452 | |||
453 | public void precisionChanged(float pDop, float hDop, float vDop) { |
||
454 | 4753 | jaume | model.putValue(kPosPrecision, pDop+"");
|
455 | model.putValue(kHorPrecision, hDop+"");
|
||
456 | model.putValue(kVerPrecision, vDop+"");
|
||
457 | tblStatus.tableChanged(e); |
||
458 | 4752 | jaume | } |
459 | |||
460 | }); |
||
461 | 4829 | jaume | gps.connect(); |
462 | 4752 | jaume | alreadyStarted = true;
|
463 | } catch (PortInUseException e) {
|
||
464 | JOptionPane.showMessageDialog(this, PluginServices.getText(this, "port_in_use")); |
||
465 | } |
||
466 | } |
||
467 | } |
||
468 | 4749 | jaume | |
469 | /**
|
||
470 | 4752 | jaume | * This method initializes jButton
|
471 | 4749 | jaume | *
|
472 | 4752 | jaume | * @return javax.swing.JButton
|
473 | 4749 | jaume | */
|
474 | 4752 | jaume | private JButton getBtnConfig() { |
475 | if (btnConfig == null) { |
||
476 | btnConfig = new JButton(); |
||
477 | 4788 | jaume | btnConfig.setBounds(479, 234, 86, 20); |
478 | 4753 | jaume | btnConfig.addActionListener(new java.awt.event.ActionListener() {
|
479 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
480 | config(); |
||
481 | } |
||
482 | }); |
||
483 | 4752 | jaume | btnConfig.setText(PluginServices.getText(this, "config")); |
484 | 4749 | jaume | } |
485 | 4752 | jaume | return btnConfig;
|
486 | 4749 | jaume | } |
487 | 4752 | jaume | |
488 | /**
|
||
489 | 4753 | jaume | * Opens the config dialog.
|
490 | */
|
||
491 | protected void config() { |
||
492 | PluginServices.getMDIManager().addView(new GPSConfigPanel(this)); |
||
493 | } |
||
494 | |||
495 | /**
|
||
496 | 4752 | jaume | * Sets the port to be monitorized.
|
497 | * @param port
|
||
498 | */
|
||
499 | public void setPort(CommPortIdentifier port) { |
||
500 | 4753 | jaume | XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
|
501 | xml.putProperty("gps-serialPortName", port.getName());
|
||
502 | 4784 | jaume | model.putValue(kPort, port.getName()); |
503 | 4752 | jaume | this.port = port;
|
504 | } |
||
505 | |||
506 | /**
|
||
507 | * Sets the speed in bps of the port that is being monitorized.
|
||
508 | * @param portSpeed
|
||
509 | */
|
||
510 | public void setPortSpeed(int portSpeed) { |
||
511 | 4788 | jaume | XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
|
512 | xml.putProperty("gps-serialPortSpeed", portSpeed);
|
||
513 | model.putValue(kPortSpeed, portSpeed+"");
|
||
514 | |||
515 | 4752 | jaume | this.portSpeed = portSpeed;
|
516 | } |
||
517 | |||
518 | 4805 | jaume | |
519 | 4752 | jaume | /**
|
520 | * Sets the amount of data bits of the port that is being monitorized.
|
||
521 | * @param int, one of 5, 6, 7, or 8
|
||
522 | */
|
||
523 | public void setPortDataBits(int dataBits) { |
||
524 | switch (dataBits) {
|
||
525 | case 5: |
||
526 | this.dataBits = SerialPort.DATABITS_5;
|
||
527 | break;
|
||
528 | case 6: |
||
529 | this.dataBits = SerialPort.DATABITS_6;
|
||
530 | break;
|
||
531 | case 7: |
||
532 | this.dataBits = SerialPort.DATABITS_7;
|
||
533 | break;
|
||
534 | case 8: |
||
535 | this.dataBits = SerialPort.DATABITS_8;
|
||
536 | break;
|
||
537 | } |
||
538 | 4788 | jaume | if (dataBits != 0){ |
539 | XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
|
||
540 | xml.putProperty("gps-serialPortDataBits", dataBits);
|
||
541 | } |
||
542 | 4752 | jaume | } |
543 | 4749 | jaume | |
544 | 4752 | jaume | /**
|
545 | * Sets the port's stop bits
|
||
546 | * @param stopBIts, one of "1", "1.5", or "2"
|
||
547 | */
|
||
548 | public void setPortStopBits(String stopBits) { |
||
549 | if (stopBits.equals("1")) { |
||
550 | this.stopBits = SerialPort.STOPBITS_1;
|
||
551 | } else if (stopBits.equals("1.5")) { |
||
552 | this.stopBits = SerialPort.STOPBITS_1_5;
|
||
553 | } else if (stopBits.equals("2")) { |
||
554 | this.stopBits = SerialPort.STOPBITS_2;
|
||
555 | 4749 | jaume | } |
556 | } |
||
557 | |||
558 | 4752 | jaume | /**
|
559 | 4784 | jaume | * Sets the frequency of the receiver sampling.
|
560 | * @param millis, the amount of milliseconds between samples
|
||
561 | */
|
||
562 | public void setSampleRate(int millis) { |
||
563 | gps.setSampleRate(millis); |
||
564 | } |
||
565 | |||
566 | /**
|
||
567 | 4752 | jaume | * Sets the parity of the port that is being monitorized
|
568 | * @param string: one of "even", "mark", "none", "odd", or "space"
|
||
569 | */
|
||
570 | public void setPortParity(String parity) { |
||
571 | if (parity.equals("even")) { |
||
572 | this.parity = SerialPort.PARITY_EVEN;
|
||
573 | } else if (parity.equals("mark")) { |
||
574 | this.parity = SerialPort.PARITY_MARK;
|
||
575 | } else if (parity.equals("none")) { |
||
576 | this.parity = SerialPort.PARITY_NONE;
|
||
577 | } else if (parity.equals("odd")) { |
||
578 | this.parity = SerialPort.PARITY_ODD;
|
||
579 | } else if (parity.equals("space")) { |
||
580 | this.parity = SerialPort.PARITY_SPACE;
|
||
581 | } |
||
582 | } |
||
583 | |||
584 | 4753 | jaume | public Object getViewModel() { |
585 | return "GPS Control Panel"; |
||
586 | } |
||
587 | 4784 | jaume | |
588 | 4829 | jaume | public int getSampleRate() { |
589 | return gps.getSampleRate();
|
||
590 | } |
||
591 | |||
592 | 4753 | jaume | } // @jve:decl-index=0:visual-constraint="10,10"
|
593 | |||
594 | |||
595 | 4721 | jaume | class StatusTableModel extends AbstractTableModel { |
596 | 4753 | jaume | private ArrayList keys = new ArrayList(); |
597 | private ArrayList values = new ArrayList(); |
||
598 | private Hashtable index = new Hashtable(); |
||
599 | 4749 | jaume | |
600 | 4753 | jaume | public void putRow(int rowIndex, String[] cellValues) { |
601 | keys.set(rowIndex, cellValues[0]);
|
||
602 | values.set(rowIndex, cellValues[1]);
|
||
603 | 4721 | jaume | } |
604 | |||
605 | 4753 | jaume | public int putValue(String key, String value) { |
606 | if (index.containsKey(key)) {
|
||
607 | int i = ((Integer)index.get(key)).intValue(); |
||
608 | values.set(i, value); |
||
609 | return i;
|
||
610 | } |
||
611 | return addRow(new String[] {key, value}); |
||
612 | } |
||
613 | |||
614 | |||
615 | public void clear() { |
||
616 | index.clear(); |
||
617 | keys.clear(); |
||
618 | values.clear(); |
||
619 | } |
||
620 | |||
621 | public int addRow(String[] cellValues) { |
||
622 | index.put(cellValues[0], new Integer(keys.size())); |
||
623 | keys.add(cellValues[0]);
|
||
624 | values.add(cellValues[1]);
|
||
625 | return keys.size()-1; |
||
626 | } |
||
627 | |||
628 | 4721 | jaume | public int getColumnCount() { |
629 | return 2; |
||
630 | } |
||
631 | |||
632 | public int getRowCount() { |
||
633 | if (keys==null) return 0; |
||
634 | 4753 | jaume | return keys.size();
|
635 | 4721 | jaume | } |
636 | |||
637 | public Object getValueAt(int rowIndex, int columnIndex) { |
||
638 | if (columnIndex == 0) |
||
639 | 4753 | jaume | return keys.get(rowIndex);
|
640 | 4721 | jaume | else if (columnIndex == 1) |
641 | 4753 | jaume | return values.get(rowIndex);
|
642 | 4721 | jaume | return null; |
643 | } |
||
644 | 4749 | jaume | |
645 | |||
646 | |||
647 | 4721 | jaume | } |