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;
48 private AltosStatusTable flightStatus;
49 private AltosInfoTable flightInfo;
51 static final int tab_pad = 1;
52 static final int tab_ascent = 2;
53 static final int tab_descent = 3;
54 static final int tab_landed = 4;
58 int which_tab(AltosState state) {
59 if (state.state < Altos.ao_flight_boost)
61 if (state.state <= Altos.ao_flight_coast)
63 if (state.state <= Altos.ao_flight_main)
69 return flightInfo.width();
73 return flightStatus.height() + flightInfo.height();
77 if (thread != null && thread.isAlive()) {
81 } catch (InterruptedException ie) {}
98 public void show(AltosState state, int crc_errors) {
99 int tab = which_tab(state);
100 pad.show(state, crc_errors);
101 ascent.show(state, crc_errors);
102 descent.show(state, crc_errors);
103 landed.show(state, crc_errors);
104 if (tab != cur_tab) {
107 pane.setSelectedComponent(pad);
110 pane.setSelectedComponent(ascent);
113 pane.setSelectedComponent(descent);
116 pane.setSelectedComponent(landed);
120 flightStatus.set(state);
121 flightInfo.show(state, crc_errors);
124 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
125 AltosPreferences.init(this);
130 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
132 setIconImage(new ImageIcon(imgURL).getImage());
134 setTitle(String.format("AltOS %s", reader.name));
136 flightStatus = new AltosStatusTable();
138 vbox = new Box (BoxLayout.Y_AXIS);
139 vbox.add(flightStatus);
141 pane = new JTabbedPane();
143 pad = new AltosPad();
144 pane.add("Launch Pad", pad);
146 ascent = new AltosAscent();
147 pane.add("Ascent", ascent);
149 descent = new AltosDescent();
150 pane.add("Descent", descent);
152 landed = new AltosLanded();
153 pane.add("Landed", landed);
155 flightInfo = new AltosInfoTable();
156 pane.add("Table", flightInfo.box());
163 JMenuBar menubar = new JMenuBar();
167 JMenu menu = new AltosChannelMenu(AltosPreferences.channel(serial));
168 menu.addActionListener(new ActionListener() {
169 public void actionPerformed(ActionEvent e) {
170 int channel = Integer.parseInt(e.getActionCommand());
171 reader.set_channel(channel);
172 AltosPreferences.set_channel(serial, channel);
175 menu.setMnemonic(KeyEvent.VK_C);
179 this.setJMenuBar(menubar);
182 this.setSize(new Dimension (width(), height()));
185 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
186 addWindowListener(new WindowAdapter() {
188 public void windowClosing(WindowEvent e) {
195 this.setVisible(true);
197 thread = new AltosDisplayThread(this, voice, this, reader);
202 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
203 this(in_voice, in_reader, -1);