2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
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.
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.
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.
20 import java.awt.Color;
21 import java.awt.Dimension;
23 import java.awt.Toolkit;
24 import java.awt.Window;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.KeyEvent;
28 import java.awt.event.MouseAdapter;
29 import java.awt.event.MouseEvent;
30 import java.awt.event.MouseListener;
31 import java.awt.event.WindowAdapter;
32 import java.awt.event.WindowEvent;
33 import javax.swing.JFrame;
34 import javax.swing.JMenu;
35 import javax.swing.JMenuBar;
36 import javax.swing.JMenuItem;
37 import javax.swing.JRadioButtonMenuItem;
38 import javax.swing.JSplitPane;
39 import javax.swing.JTable;
40 import javax.swing.KeyStroke;
41 import javax.swing.table.TableCellEditor;
42 import javax.swing.table.DefaultTableCellRenderer;
43 import altosui.AltosSerial;
44 import altosui.AltosSerialMonitor;
46 class AltosUIMonitor implements AltosSerialMonitor {
47 public void data(String data) {
48 System.out.println(data);
52 public class AltosUI extends JFrame {
53 private int channel = -1;
55 private JTable flightStatus;
56 private JTable flightInfo;
57 private AltosSerial serialLine;
61 String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" };
62 Object[][] statusData = { { "0", "pad", "-50", "0" } };
64 flightStatus = new JTable(statusData, statusNames);
66 flightStatus.setShowGrid(false);
68 this.add(flightStatus);
74 serialLine = new AltosSerial("/dev/ttyACM0");
75 serialLine.monitor(new AltosUIMonitor());
77 Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
78 size.width = size.width*9/10;
79 size.height = size.height*9/10;
82 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
83 addWindowListener(new WindowAdapter() {
85 public void windowClosing(WindowEvent e) {
91 private void createMenu() {
92 JMenuBar menubar = new JMenuBar();
95 JRadioButtonMenuItem radioitem;
99 menu = new JMenu("File");
100 menu.setMnemonic(KeyEvent.VK_F);
103 item = new JMenuItem("Quit",KeyEvent.VK_Q);
104 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
105 ActionEvent.CTRL_MASK));
106 item.addActionListener(new ActionListener() {
107 public void actionPerformed(ActionEvent e) {
116 menu = new JMenu("Device");
117 menu.setMnemonic(KeyEvent.VK_D);
120 item = new JMenuItem("Connect to Device",KeyEvent.VK_C);
121 item.addActionListener(new ActionListener() {
122 public void actionPerformed(ActionEvent e) {
127 item = new JMenuItem("Disconnect from Device",KeyEvent.VK_D);
128 item.addActionListener(new ActionListener() {
129 public void actionPerformed(ActionEvent e) {
136 item = new JMenuItem("Save Flight Data",KeyEvent.VK_S);
137 item.addActionListener(new ActionListener() {
138 public void actionPerformed(ActionEvent e) {
143 item = new JMenuItem("Replay",KeyEvent.VK_R);
144 item.addActionListener(new ActionListener() {
145 public void actionPerformed(ActionEvent e) {
152 menu = new JMenu("Log");
153 menu.setMnemonic(KeyEvent.VK_L);
156 item = new JMenuItem("New Log",KeyEvent.VK_N);
157 item.addActionListener(new ActionListener() {
158 public void actionPerformed(ActionEvent e) {
163 item = new JMenuItem("Configure Log",KeyEvent.VK_C);
164 item.addActionListener(new ActionListener() {
165 public void actionPerformed(ActionEvent e) {
172 menu = new JMenu("Voice", true);
173 menu.setMnemonic(KeyEvent.VK_V);
176 radioitem = new JRadioButtonMenuItem("Enable Voice");
177 radioitem.addActionListener(new ActionListener() {
178 public void actionPerformed(ActionEvent e) {
186 menu = new JMenu("Channel", true);
187 menu.setMnemonic(KeyEvent.VK_C);
190 for (int c = 0; c <= 9; c++) {
191 radioitem = new JRadioButtonMenuItem("Channel " + c + " (" +
192 (434.550 + c * .1) + ")",
194 radioitem.addActionListener(new ActionListener() {
195 public void actionPerformed(ActionEvent e) {
202 this.setJMenuBar(menubar);
205 public static void main(final String[] args) {
206 AltosUI altosui = new AltosUI();
207 altosui.setVisible(true);