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