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;
45 private AltosStatusTable flightStatus;
46 private AltosInfoTable flightInfo;
49 return flightInfo.width();
53 return flightStatus.height() + flightInfo.height();
57 if (thread != null && thread.isAlive()) {
61 } catch (InterruptedException ie) {}
75 public void show(AltosState state, int crc_errors) {
76 pad.show(state, crc_errors);
77 flightStatus.set(state);
78 flightInfo.show(state, crc_errors);
81 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
85 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
87 setIconImage(new ImageIcon(imgURL).getImage());
89 setTitle(String.format("AltOS %s", reader.name));
91 flightStatus = new AltosStatusTable();
93 vbox = new Box (BoxLayout.Y_AXIS);
94 vbox.add(flightStatus);
96 pane = new JTabbedPane();
99 pane.add("Launch Pad", pad);
101 flightInfo = new AltosInfoTable();
102 pane.add("Table", flightInfo.box());
109 JMenuBar menubar = new JMenuBar();
113 JMenu menu = new AltosChannelMenu(AltosPreferences.channel(serial));
114 menu.addActionListener(new ActionListener() {
115 public void actionPerformed(ActionEvent e) {
116 int channel = Integer.parseInt(e.getActionCommand());
117 reader.set_channel(channel);
118 AltosPreferences.set_channel(serial, channel);
121 menu.setMnemonic(KeyEvent.VK_C);
125 this.setJMenuBar(menubar);
128 this.setSize(new Dimension (width(), height()));
131 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
132 addWindowListener(new WindowAdapter() {
134 public void windowClosing(WindowEvent e) {
141 this.setVisible(true);
143 thread = new AltosDisplayThread(this, voice, this, reader);
148 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
149 this(in_voice, in_reader, -1);