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