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.
21 import java.awt.event.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.LinkedBlockingQueue;
31 public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
32 String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" };
33 Object[][] statusData = { { "0", "pad", "-50", "0" } };
36 AltosFlightReader reader;
37 AltosDisplayThread thread;
40 private AltosStatusTable flightStatus;
41 private AltosInfoTable flightInfo;
44 return flightInfo.width();
48 return flightStatus.height() + flightInfo.height();
52 if (thread != null && thread.isAlive()) {
56 } catch (InterruptedException ie) {}
69 public void show(AltosState state, int crc_errors) {
70 flightStatus.set(state);
71 flightInfo.show(state, crc_errors);
74 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
78 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
80 setIconImage(new ImageIcon(imgURL).getImage());
82 setTitle(String.format("AltOS %s", reader.name));
84 flightStatus = new AltosStatusTable();
86 vbox = new Box (BoxLayout.Y_AXIS);
87 vbox.add(flightStatus);
89 flightInfo = new AltosInfoTable();
90 vbox.add(flightInfo.box());
95 JMenuBar menubar = new JMenuBar();
99 JMenu menu = new AltosChannelMenu(AltosPreferences.channel(serial));
100 menu.addActionListener(new ActionListener() {
101 public void actionPerformed(ActionEvent e) {
102 int channel = Integer.parseInt(e.getActionCommand());
103 reader.set_channel(channel);
104 AltosPreferences.set_channel(serial, channel);
107 menu.setMnemonic(KeyEvent.VK_C);
111 this.setJMenuBar(menubar);
114 this.setSize(new Dimension (width(), height()));
117 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
118 addWindowListener(new WindowAdapter() {
120 public void windowClosing(WindowEvent e) {
127 this.setVisible(true);
129 thread = new AltosDisplayThread(this, voice, this, reader);
134 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
135 this(in_voice, in_reader, -1);