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 {
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) {}
65 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
69 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
71 setIconImage(new ImageIcon(imgURL).getImage());
73 setTitle(String.format("AltOS %s", reader.name));
75 flightStatus = new AltosStatusTable();
77 vbox = new Box (BoxLayout.Y_AXIS);
78 vbox.add(flightStatus);
80 flightInfo = new AltosInfoTable();
81 vbox.add(flightInfo.box());
86 JMenuBar menubar = new JMenuBar();
90 JMenu menu = new AltosChannelMenu(AltosPreferences.channel(serial));
91 menu.addActionListener(new ActionListener() {
92 public void actionPerformed(ActionEvent e) {
93 int channel = Integer.parseInt(e.getActionCommand());
94 reader.set_channel(channel);
95 AltosPreferences.set_channel(serial, channel);
98 menu.setMnemonic(KeyEvent.VK_C);
102 this.setJMenuBar(menubar);
105 this.setSize(new Dimension (width(), height()));
108 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
109 addWindowListener(new WindowAdapter() {
111 public void windowClosing(WindowEvent e) {
118 this.setVisible(true);
120 thread = new AltosDisplayThread(this, voice, flightStatus, flightInfo, reader);
125 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
126 this(in_voice, in_reader, -1);