Start adding java-based UI
[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.Color;
21 import java.awt.Dimension;
22 import java.awt.Font;
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;
45
46 class AltosUIMonitor implements AltosSerialMonitor {
47         public void data(String data) {
48                 System.out.println(data);
49         }
50 }
51
52 public class AltosUI extends JFrame {
53         private int channel = -1;
54
55         private JTable flightStatus;
56         private JTable flightInfo;
57         private AltosSerial serialLine;
58
59         public AltosUI() {
60
61                 String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" };
62                 Object[][] statusData = { { "0", "pad", "-50", "0" } };
63
64                 flightStatus = new JTable(statusData, statusNames);
65
66                 flightStatus.setShowGrid(false);
67
68                 this.add(flightStatus);
69
70                 setTitle("AltOS");
71
72                 createMenu();
73
74                 serialLine = new AltosSerial("/dev/ttyACM0");
75                 serialLine.monitor(new AltosUIMonitor());
76                 serialLine.start();
77                 Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
78                 size.width = size.width*9/10;
79                 size.height = size.height*9/10;
80                 this.setSize(size);
81                 this.validate();
82                 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
83                 addWindowListener(new WindowAdapter() {
84                         @Override
85                         public void windowClosing(WindowEvent e) {
86                                 System.exit(0);
87                         }
88                 });
89         }
90
91         private void createMenu() {
92                 JMenuBar menubar = new JMenuBar();
93                 JMenu menu;
94                 JMenuItem item;
95                 JRadioButtonMenuItem radioitem;
96
97                 // File menu
98                 {
99                         menu = new JMenu("File");
100                         menu.setMnemonic(KeyEvent.VK_F);
101                         menubar.add(menu);
102
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) {
108                                                 System.exit(0);
109                                         }
110                                 });
111                         menu.add(item);
112                 }
113
114                 // Device menu
115                 {
116                         menu = new JMenu("Device");
117                         menu.setMnemonic(KeyEvent.VK_D);
118                         menubar.add(menu);
119
120                         item = new JMenuItem("Connect to Device",KeyEvent.VK_C);
121                         item.addActionListener(new ActionListener() {
122                                         public void actionPerformed(ActionEvent e) {
123                                         }
124                                 });
125                         menu.add(item);
126
127                         item = new JMenuItem("Disconnect from Device",KeyEvent.VK_D);
128                         item.addActionListener(new ActionListener() {
129                                         public void actionPerformed(ActionEvent e) {
130                                         }
131                                 });
132                         menu.add(item);
133
134                         menu.addSeparator();
135
136                         item = new JMenuItem("Save Flight Data",KeyEvent.VK_S);
137                         item.addActionListener(new ActionListener() {
138                                         public void actionPerformed(ActionEvent e) {
139                                         }
140                                 });
141                         menu.add(item);
142
143                         item = new JMenuItem("Replay",KeyEvent.VK_R);
144                         item.addActionListener(new ActionListener() {
145                                         public void actionPerformed(ActionEvent e) {
146                                         }
147                                 });
148                         menu.add(item);
149                 }
150                 // Log menu
151                 {
152                         menu = new JMenu("Log");
153                         menu.setMnemonic(KeyEvent.VK_L);
154                         menubar.add(menu);
155
156                         item = new JMenuItem("New Log",KeyEvent.VK_N);
157                         item.addActionListener(new ActionListener() {
158                                         public void actionPerformed(ActionEvent e) {
159                                         }
160                                 });
161                         menu.add(item);
162
163                         item = new JMenuItem("Configure Log",KeyEvent.VK_C);
164                         item.addActionListener(new ActionListener() {
165                                         public void actionPerformed(ActionEvent e) {
166                                         }
167                                 });
168                         menu.add(item);
169                 }
170                 // Voice menu
171                 {
172                         menu = new JMenu("Voice", true);
173                         menu.setMnemonic(KeyEvent.VK_V);
174                         menubar.add(menu);
175
176                         radioitem = new JRadioButtonMenuItem("Enable Voice");
177                         radioitem.addActionListener(new ActionListener() {
178                                         public void actionPerformed(ActionEvent e) {
179                                         }
180                                 });
181                         menu.add(radioitem);
182                 }
183
184                 // Channel menu
185                 {
186                         menu = new JMenu("Channel", true);
187                         menu.setMnemonic(KeyEvent.VK_C);
188                         menubar.add(menu);
189
190                         for (int c = 0; c <= 9; c++) {
191                                 radioitem = new JRadioButtonMenuItem("Channel " + c + " (" +
192                                                                 (434.550 + c * .1) + ")",
193                                                                 c == 0);
194                                 radioitem.addActionListener(new ActionListener() {
195                                                 public void actionPerformed(ActionEvent e) {
196                                                 }
197                                         });
198                                 menu.add(radioitem);
199                         }
200                 }
201
202                 this.setJMenuBar(menubar);
203
204         }
205         public static void main(final String[] args) {
206                 AltosUI altosui = new AltosUI();
207                 altosui.setVisible(true);
208         }
209 }