altosui: Make teledongle callsign configurable
[fw/altos] / ao-tools / altosui / AltosUI.java
1 /*
2  * Copyright © 2010 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package altosui;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
25 import java.io.*;
26 import java.util.*;
27 import java.text.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.LinkedBlockingQueue;
30
31 import altosui.Altos;
32 import altosui.AltosSerial;
33 import altosui.AltosSerialMonitor;
34 import altosui.AltosRecord;
35 import altosui.AltosTelemetry;
36 import altosui.AltosState;
37 import altosui.AltosDeviceDialog;
38 import altosui.AltosPreferences;
39 import altosui.AltosLog;
40 import altosui.AltosVoice;
41 import altosui.AltosFlightStatusTableModel;
42 import altosui.AltosFlightInfoTableModel;
43
44 import libaltosJNI.*;
45
46 public class AltosUI extends JFrame {
47         private int channel = -1;
48
49         private AltosFlightStatusTableModel flightStatusModel;
50         private JTable flightStatus;
51
52         static final int info_columns = 3;
53
54         private AltosFlightInfoTableModel[] flightInfoModel;
55         private JTable[] flightInfo;
56         private AltosSerial serial_line;
57         private AltosLog altos_log;
58         private Box[] ibox;
59         private Box vbox;
60         private Box hbox;
61
62         private Font statusFont = new Font("SansSerif", Font.BOLD, 24);
63         private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14);
64         private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 14);
65
66         public AltosVoice voice = new AltosVoice();
67
68         public AltosUI() {
69
70                 String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" };
71                 Object[][] statusData = { { "0", "pad", "-50", "0" } };
72
73                 AltosPreferences.init(this);
74
75                 vbox = Box.createVerticalBox();
76                 this.add(vbox);
77
78                 flightStatusModel = new AltosFlightStatusTableModel();
79                 flightStatus = new JTable(flightStatusModel);
80                 flightStatus.setFont(statusFont);
81                 TableColumnModel tcm = flightStatus.getColumnModel();
82                 for (int i = 0; i < flightStatusModel.getColumnCount(); i++) {
83                         DefaultTableCellRenderer       r = new DefaultTableCellRenderer();
84                         r.setFont(statusFont);
85                         r.setHorizontalAlignment(SwingConstants.CENTER);
86                         tcm.getColumn(i).setCellRenderer(r);
87                 }
88
89                 FontMetrics     statusMetrics = flightStatus.getFontMetrics(statusFont);
90                 int statusHeight = (statusMetrics.getHeight() + statusMetrics.getLeading()) * 15 / 10;
91                 flightStatus.setRowHeight(statusHeight);
92                 flightStatus.setShowGrid(false);
93
94                 vbox.add(flightStatus);
95
96                 hbox = Box.createHorizontalBox();
97                 vbox.add(hbox);
98
99                 flightInfo = new JTable[3];
100                 flightInfoModel = new AltosFlightInfoTableModel[3];
101                 ibox = new Box[3];
102                 FontMetrics     infoValueMetrics = flightStatus.getFontMetrics(infoValueFont);
103                 int infoHeight = (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 20 / 10;
104
105                 for (int i = 0; i < info_columns; i++) {
106                         ibox[i] = Box.createVerticalBox();
107                         flightInfoModel[i] = new AltosFlightInfoTableModel();
108                         flightInfo[i] = new JTable(flightInfoModel[i]);
109                         flightInfo[i].setFont(infoValueFont);
110                         flightInfo[i].setRowHeight(infoHeight);
111                         flightInfo[i].setShowGrid(true);
112                         ibox[i].add(flightInfo[i].getTableHeader());
113                         ibox[i].add(flightInfo[i]);
114                         hbox.add(ibox[i]);
115                 }
116
117                 setTitle("AltOS");
118
119                 createMenu();
120
121                 serial_line = new AltosSerial();
122                 altos_log = new AltosLog(serial_line);
123                 int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
124                 this.setSize(new Dimension (infoValueMetrics.charWidth('0') * 6 * 20,
125                                             statusHeight * 4 + infoHeight * 17));
126                 this.validate();
127                 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
128                 addWindowListener(new WindowAdapter() {
129                         @Override
130                         public void windowClosing(WindowEvent e) {
131                                 System.exit(0);
132                         }
133                 });
134                 voice.speak("Rocket flight monitor ready.");
135         }
136
137         public void info_reset() {
138                 for (int i = 0; i < info_columns; i++)
139                         flightInfoModel[i].resetRow();
140         }
141
142         public void info_add_row(int col, String name, String value) {
143                 flightInfoModel[col].addRow(name, value);
144         }
145
146         public void info_add_row(int col, String name, String format, Object... parameters) {
147                 flightInfoModel[col].addRow(name, String.format(format, parameters));
148         }
149
150         public void info_add_deg(int col, String name, double v, int pos, int neg) {
151                 int     c = pos;
152                 if (v < 0) {
153                         c = neg;
154                         v = -v;
155                 }
156                 double  deg = Math.floor(v);
157                 double  min = (v - deg) * 60;
158
159                 flightInfoModel[col].addRow(name, String.format("%3.0f°%08.5f'", deg, min));
160         }
161
162         public void info_finish() {
163                 for (int i = 0; i < info_columns; i++)
164                         flightInfoModel[i].finish();
165         }
166
167         public void show(AltosState state) {
168                 flightStatusModel.set(state);
169
170                 info_reset();
171                 if (state.gps_ready)
172                         info_add_row(0, "Ground state", "%s", "ready");
173                 else
174                         info_add_row(0, "Ground state", "wait (%d)",
175                                      state.gps_waiting);
176                 info_add_row(0, "Rocket state", "%s", state.data.state());
177                 info_add_row(0, "Callsign", "%s", state.data.callsign);
178                 info_add_row(0, "Rocket serial", "%6d", state.data.serial);
179                 info_add_row(0, "Rocket flight", "%6d", state.data.flight);
180
181                 info_add_row(0, "RSSI", "%6d    dBm", state.data.rssi);
182                 info_add_row(0, "Height", "%6.0f    m", state.height);
183                 info_add_row(0, "Max height", "%6.0f    m", state.max_height);
184                 info_add_row(0, "Acceleration", "%8.1f  m/s²", state.acceleration);
185                 info_add_row(0, "Max acceleration", "%8.1f  m/s²", state.max_acceleration);
186                 info_add_row(0, "Speed", "%8.1f  m/s", state.ascent ? state.speed : state.baro_speed);
187                 info_add_row(0, "Max Speed", "%8.1f  m/s", state.max_speed);
188                 info_add_row(0, "Temperature", "%9.2f °C", state.temperature);
189                 info_add_row(0, "Battery", "%9.2f V", state.battery);
190                 info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense);
191                 info_add_row(0, "Main", "%9.2f V", state.main_sense);
192                 info_add_row(0, "Pad altitude", "%6.0f    m", state.ground_altitude);
193                 if (state.gps == null) {
194                         info_add_row(1, "GPS", "not available");
195                 } else {
196                         if (state.data.gps.locked)
197                                 info_add_row(1, "GPS", "   locked");
198                         else if (state.data.gps.connected)
199                                 info_add_row(1, "GPS", " unlocked");
200                         else
201                                 info_add_row(1, "GPS", "  missing");
202                         info_add_row(1, "Satellites", "%6d", state.data.gps.nsat);
203                         info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S');
204                         info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W');
205                         info_add_row(1, "GPS altitude", "%6d", state.gps.alt);
206                         info_add_row(1, "GPS height", "%6.0f", state.gps_height);
207
208                         /* The SkyTraq GPS doesn't report these values */
209                         if (false) {
210                                 info_add_row(1, "GPS ground speed", "%8.1f m/s %3d°",
211                                              state.gps.ground_speed,
212                                              state.gps.course);
213                                 info_add_row(1, "GPS climb rate", "%8.1f m/s",
214                                              state.gps.climb_rate);
215                                 info_add_row(1, "GPS error", "%6d m(h)%3d m(v)",
216                                              state.gps.h_error, state.gps.v_error);
217                         }
218                         info_add_row(1, "GPS hdop", "%8.1f", state.gps.hdop);
219
220                         if (state.npad > 0) {
221                                 if (state.from_pad != null) {
222                                         info_add_row(1, "Distance from pad", "%6.0f m", state.from_pad.distance);
223                                         info_add_row(1, "Direction from pad", "%6.0f°", state.from_pad.bearing);
224                                 } else {
225                                         info_add_row(1, "Distance from pad", "unknown");
226                                         info_add_row(1, "Direction from pad", "unknown");
227                                 }
228                                 info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S');
229                                 info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W');
230                                 info_add_row(1, "Pad GPS alt", "%6.0f m", state.pad_alt);
231                         }
232                         info_add_row(1, "GPS date", "%04d-%02d-%02d",
233                                        state.gps.year,
234                                        state.gps.month,
235                                        state.gps.day);
236                         info_add_row(1, "GPS time", "  %02d:%02d:%02d",
237                                        state.gps.hour,
238                                        state.gps.minute,
239                                        state.gps.second);
240                         int     nsat_vis = 0;
241                         int     c;
242
243                         if (state.gps.cc_gps_sat == null)
244                                 info_add_row(2, "Satellites Visible", "%4d", 0);
245                         else {
246                                 info_add_row(2, "Satellites Visible", "%4d", state.gps.cc_gps_sat.length);
247                                 for (c = 0; c < state.gps.cc_gps_sat.length; c++) {
248                                         info_add_row(2, "Satellite id,C/N0",
249                                                      "%4d, %4d",
250                                                      state.gps.cc_gps_sat[c].svid,
251                                                      state.gps.cc_gps_sat[c].c_n0);
252                                 }
253                         }
254                 }
255                 info_finish();
256         }
257
258         class IdleThread extends Thread {
259
260                 private AltosState state;
261                 int     reported_landing;
262
263                 public void report(boolean last) {
264                         if (state == null)
265                                 return;
266
267                         /* reset the landing count once we hear about a new flight */
268                         if (state.state < Altos.ao_flight_drogue)
269                                 reported_landing = 0;
270
271                         /* Shut up once the rocket is on the ground */
272                         if (reported_landing > 2) {
273                                 return;
274                         }
275
276                         /* If the rocket isn't on the pad, then report height */
277                         if (state.state > Altos.ao_flight_pad) {
278                                 voice.speak("%d meters", (int) (state.height + 0.5));
279                         } else {
280                                 reported_landing = 0;
281                         }
282
283                         /* If the rocket is coming down, check to see if it has landed;
284                          * either we've got a landed report or we haven't heard from it in
285                          * a long time
286                          */
287                         if (!state.ascent &&
288                             (last ||
289                              System.currentTimeMillis() - state.report_time >= 15000 ||
290                              state.state == Altos.ao_flight_landed))
291                         {
292                                 if (Math.abs(state.baro_speed) < 20 && state.height < 100)
293                                         voice.speak("rocket landed safely");
294                                 else
295                                         voice.speak("rocket may have crashed");
296                                 if (state.from_pad != null)
297                                         voice.speak("bearing %d degrees, range %d meters",
298                                                     (int) (state.from_pad.bearing + 0.5),
299                                                     (int) (state.from_pad.distance + 0.5));
300                                 ++reported_landing;
301                         }
302                 }
303
304                 public void run () {
305
306                         reported_landing = 0;
307                         state = null;
308                         try {
309                                 for (;;) {
310                                         Thread.sleep(10000);
311                                         report(false);
312                                 }
313                         } catch (InterruptedException ie) {
314                         }
315                 }
316
317                 public void notice(AltosState new_state) {
318                         state = new_state;
319                 }
320         }
321
322         private void tell(AltosState state, AltosState old_state) {
323                 if (old_state == null || old_state.state != state.state) {
324                         voice.speak(state.data.state());
325                         if ((old_state == null || old_state.state <= Altos.ao_flight_boost) &&
326                             state.state > Altos.ao_flight_boost) {
327                                 voice.speak("max speed: %d meters per second.",
328                                             (int) (state.max_speed + 0.5));
329                         } else if ((old_state == null || old_state.state < Altos.ao_flight_drogue) &&
330                                    state.state >= Altos.ao_flight_drogue) {
331                                 voice.speak("max height: %d meters.",
332                                             (int) (state.max_height + 0.5));
333                         }
334                 }
335                 if (old_state == null || old_state.gps_ready != state.gps_ready) {
336                         if (state.gps_ready)
337                                 voice.speak("GPS ready");
338                         else if (old_state != null)
339                                 voice.speak("GPS lost");
340                 }
341                 old_state = state;
342         }
343
344         class DisplayThread extends Thread {
345                 IdleThread      idle_thread;
346
347                 String          name;
348
349                 AltosRecord read() throws InterruptedException, ParseException { return null; }
350
351                 void close() { }
352
353                 void update(AltosState state) throws InterruptedException { }
354
355                 public void run() {
356                         String          line;
357                         AltosState      state = null;
358                         AltosState      old_state = null;
359
360                         idle_thread = new IdleThread();
361
362                         info_reset();
363                         info_finish();
364                         idle_thread.start();
365                         try {
366                                 for (;;) {
367                                         try {
368                                                 AltosRecord record = read();
369                                                 if (record == null)
370                                                         break;
371                                                 old_state = state;
372                                                 state = new AltosState(record, state);
373                                                 update(state);
374                                                 show(state);
375                                                 tell(state, old_state);
376                                                 idle_thread.notice(state);
377                                         } catch (ParseException pp) {
378                                                 System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage());
379                                         }
380                                 }
381                         } catch (InterruptedException ee) {
382                         } finally {
383                                 close();
384                                 idle_thread.interrupt();
385                         }
386                 }
387
388                 public void report() {
389                         if (idle_thread != null)
390                                 idle_thread.report(true);
391                 }
392         }
393
394         class DeviceThread extends DisplayThread {
395                 AltosSerial     serial;
396                 LinkedBlockingQueue<String> telem;
397
398                 AltosRecord read() throws InterruptedException, ParseException {
399                         return new AltosTelemetry(telem.take());
400                 }
401
402                 void close() {
403                         serial.close();
404                         serial.remove_monitor(telem);
405                 }
406
407                 public DeviceThread(AltosSerial s) {
408                         serial = s;
409                         telem = new LinkedBlockingQueue<String>();
410                         serial.add_monitor(telem);
411                         name = "telemetry";
412                 }
413         }
414
415         private void ConnectToDevice() {
416                 AltosDevice     device = AltosDeviceDialog.show(AltosUI.this, AltosDevice.BaseStation);
417
418                 if (device != null) {
419                         try {
420                                 serial_line.open(device);
421                                 DeviceThread thread = new DeviceThread(serial_line);
422                                 serial_line.set_channel(AltosPreferences.channel());
423                                 serial_line.set_callsign(AltosPreferences.callsign());
424                                 run_display(thread);
425                         } catch (FileNotFoundException ee) {
426                                 JOptionPane.showMessageDialog(AltosUI.this,
427                                                               String.format("Cannot open device \"%s\"",
428                                                                             device.getPath()),
429                                                               "Cannot open target device",
430                                                               JOptionPane.ERROR_MESSAGE);
431                         } catch (IOException ee) {
432                                 JOptionPane.showMessageDialog(AltosUI.this,
433                                                               device.getPath(),
434                                                               "Unkonwn I/O error",
435                                                               JOptionPane.ERROR_MESSAGE);
436                         }
437                 }
438         }
439
440         void DisconnectFromDevice () {
441                 stop_display();
442         }
443
444         void ConfigureCallsign() {
445                 String  result;
446                 result = JOptionPane.showInputDialog(AltosUI.this,
447                                                      "Configure Callsign",
448                                                      AltosPreferences.callsign());
449                 if (result != null) {
450                         AltosPreferences.set_callsign(result);
451                         if (serial_line != null)
452                                 serial_line.set_callsign(result);
453                 }
454         }
455
456         /*
457          * Open an existing telemetry file and replay it in realtime
458          */
459
460         class ReplayThread extends DisplayThread {
461                 AltosReader     reader;
462                 String          name;
463
464                 public AltosRecord read() {
465                         try {
466                                 return reader.read();
467                         } catch (IOException ie) {
468                                 JOptionPane.showMessageDialog(AltosUI.this,
469                                                               name,
470                                                               "error reading",
471                                                               JOptionPane.ERROR_MESSAGE);
472                         } catch (ParseException pe) {
473                         }
474                         return null;
475                 }
476
477                 public void close () {
478                         report();
479                 }
480
481                 public ReplayThread(AltosReader in_reader, String in_name) {
482                         reader = in_reader;
483                 }
484                 void update(AltosState state) throws InterruptedException {
485                         /* Make it run in realtime after the rocket leaves the pad */
486                         if (state.state > Altos.ao_flight_pad)
487                                 Thread.sleep((int) (Math.min(state.time_change,10) * 1000));
488                 }
489         }
490
491         class ReplayTelemetryThread extends ReplayThread {
492                 ReplayTelemetryThread(FileInputStream in, String in_name) {
493                         super(new AltosTelemetryReader(in), in_name);
494                 }
495
496         }
497
498         class ReplayEepromThread extends ReplayThread {
499                 ReplayEepromThread(FileInputStream in, String in_name) {
500                         super(new AltosEepromReader(in), in_name);
501                 }
502         }
503
504         Thread          display_thread;
505
506         private void stop_display() {
507                 if (display_thread != null && display_thread.isAlive())
508                         display_thread.interrupt();
509                 display_thread = null;
510         }
511
512         private void run_display(Thread thread) {
513                 stop_display();
514                 display_thread = thread;
515                 display_thread.start();
516         }
517
518         /*
519          * Replay a flight from telemetry data
520          */
521         private void Replay() {
522                 JFileChooser    logfile_chooser = new JFileChooser();
523
524                 logfile_chooser.setDialogTitle("Select Flight Record File");
525                 logfile_chooser.setFileFilter(new FileNameExtensionFilter("Flight data file", "eeprom", "telem"));
526                 logfile_chooser.setCurrentDirectory(AltosPreferences.logdir());
527                 int returnVal = logfile_chooser.showOpenDialog(AltosUI.this);
528
529                 if (returnVal == JFileChooser.APPROVE_OPTION) {
530                         File file = logfile_chooser.getSelectedFile();
531                         if (file == null)
532                                 System.out.println("No file selected?");
533                         String  filename = file.getName();
534                         try {
535                                 FileInputStream replay = new FileInputStream(file);
536                                 DisplayThread   thread;
537                                 if (filename.endsWith("eeprom"))
538                                     thread = new ReplayEepromThread(replay, filename);
539                                 else
540                                     thread = new ReplayTelemetryThread(replay, filename);
541                                 run_display(thread);
542                         } catch (FileNotFoundException ee) {
543                                 JOptionPane.showMessageDialog(AltosUI.this,
544                                                               filename,
545                                                               "Cannot open telemetry file",
546                                                               JOptionPane.ERROR_MESSAGE);
547                         }
548                 }
549         }
550
551         /* Connect to TeleMetrum, either directly or through
552          * a TeleDongle over the packet link
553          */
554         private void SaveFlightData() {
555                 new AltosEepromDownload(AltosUI.this);
556         }
557
558         /* Create the AltosUI menus
559          */
560         private void createMenu() {
561                 JMenuBar menubar = new JMenuBar();
562                 JMenu menu;
563                 JMenuItem item;
564                 JRadioButtonMenuItem radioitem;
565
566                 // File menu
567                 {
568                         menu = new JMenu("File");
569                         menu.setMnemonic(KeyEvent.VK_F);
570                         menubar.add(menu);
571
572                         item = new JMenuItem("Replay File",KeyEvent.VK_R);
573                         item.addActionListener(new ActionListener() {
574                                         public void actionPerformed(ActionEvent e) {
575                                                 Replay();
576                                         }
577                                 });
578                         menu.add(item);
579
580                         item = new JMenuItem("Save Flight Data",KeyEvent.VK_S);
581                         item.addActionListener(new ActionListener() {
582                                         public void actionPerformed(ActionEvent e) {
583                                                 SaveFlightData();
584                                         }
585                                 });
586                         menu.add(item);
587
588                         item = new JMenuItem("Quit",KeyEvent.VK_Q);
589                         item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
590                                                                    ActionEvent.CTRL_MASK));
591                         item.addActionListener(new ActionListener() {
592                                         public void actionPerformed(ActionEvent e) {
593                                                 System.exit(0);
594                                         }
595                                 });
596                         menu.add(item);
597                 }
598
599                 // Device menu
600                 {
601                         menu = new JMenu("Device");
602                         menu.setMnemonic(KeyEvent.VK_D);
603                         menubar.add(menu);
604
605                         item = new JMenuItem("Connect to Device",KeyEvent.VK_C);
606                         item.addActionListener(new ActionListener() {
607                                         public void actionPerformed(ActionEvent e) {
608                                                 ConnectToDevice();
609                                         }
610                                 });
611                         menu.add(item);
612
613                         item = new JMenuItem("Disconnect from Device",KeyEvent.VK_D);
614                         item.addActionListener(new ActionListener() {
615                                         public void actionPerformed(ActionEvent e) {
616                                                 DisconnectFromDevice();
617                                         }
618                                 });
619                         menu.add(item);
620
621                         menu.addSeparator();
622
623                         item = new JMenuItem("Set Callsign",KeyEvent.VK_S);
624                         item.addActionListener(new ActionListener() {
625                                         public void actionPerformed(ActionEvent e) {
626                                                 ConfigureCallsign();
627                                         }
628                                 });
629
630                         menu.add(item);
631                 }
632                 // Log menu
633                 {
634                         menu = new JMenu("Log");
635                         menu.setMnemonic(KeyEvent.VK_L);
636                         menubar.add(menu);
637
638                         item = new JMenuItem("New Log",KeyEvent.VK_N);
639                         item.addActionListener(new ActionListener() {
640                                         public void actionPerformed(ActionEvent e) {
641                                         }
642                                 });
643                         menu.add(item);
644
645                         item = new JMenuItem("Configure Log",KeyEvent.VK_C);
646                         item.addActionListener(new ActionListener() {
647                                         public void actionPerformed(ActionEvent e) {
648                                                 AltosPreferences.ConfigureLog();
649                                         }
650                                 });
651                         menu.add(item);
652                 }
653                 // Voice menu
654                 {
655                         menu = new JMenu("Voice", true);
656                         menu.setMnemonic(KeyEvent.VK_V);
657                         menubar.add(menu);
658
659                         radioitem = new JRadioButtonMenuItem("Enable Voice", AltosPreferences.voice());
660                         radioitem.addActionListener(new ActionListener() {
661                                         public void actionPerformed(ActionEvent e) {
662                                                 JRadioButtonMenuItem item = (JRadioButtonMenuItem) e.getSource();
663                                                 boolean enabled = item.isSelected();
664                                                 AltosPreferences.set_voice(enabled);
665                                                 if (enabled)
666                                                         voice.speak_always("Enable voice.");
667                                                 else
668                                                         voice.speak_always("Disable voice.");
669                                         }
670                                 });
671                         menu.add(radioitem);
672                         item = new JMenuItem("Test Voice",KeyEvent.VK_T);
673                         item.addActionListener(new ActionListener() {
674                                         public void actionPerformed(ActionEvent e) {
675                                                 voice.speak("That's one small step for man; one giant leap for mankind.");
676                                         }
677                                 });
678                         menu.add(item);
679                 }
680
681                 // Channel menu
682                 {
683                         menu = new JMenu("Channel", true);
684                         menu.setMnemonic(KeyEvent.VK_C);
685                         menubar.add(menu);
686                         ButtonGroup group = new ButtonGroup();
687
688                         for (int c = 0; c <= 9; c++) {
689                                 radioitem = new JRadioButtonMenuItem(String.format("Channel %1d (%7.3fMHz)", c,
690                                                                                    434.550 + c * 0.1),
691                                                                      c == AltosPreferences.channel());
692                                 radioitem.setActionCommand(String.format("%d", c));
693                                 radioitem.addActionListener(new ActionListener() {
694                                                 public void actionPerformed(ActionEvent e) {
695                                                         int new_channel = Integer.parseInt(e.getActionCommand());
696                                                         AltosPreferences.set_channel(new_channel);
697                                                         serial_line.set_channel(new_channel);
698                                                 }
699                                         });
700                                 menu.add(radioitem);
701                                 group.add(radioitem);
702                         }
703                 }
704
705                 this.setJMenuBar(menubar);
706
707         }
708         public static void main(final String[] args) {
709                 AltosUI altosui = new AltosUI();
710                 altosui.setVisible(true);
711         }
712 }