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