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;
47 private AltosFlightStatus flightStatus;
48 private AltosInfoTable flightInfo;
50 static final int tab_pad = 1;
51 static final int tab_ascent = 2;
52 static final int tab_descent = 3;
53 static final int tab_landed = 4;
57 boolean exit_on_close = false;
59 int which_tab(AltosState state) {
60 if (state.state < Altos.ao_flight_boost)
62 if (state.state <= Altos.ao_flight_coast)
64 if (state.state <= Altos.ao_flight_main)
70 if (thread != null && thread.isAlive()) {
74 } catch (InterruptedException ie) {}
92 public void show(AltosState state, int crc_errors) {
93 int tab = which_tab(state);
94 pad.show(state, crc_errors);
95 ascent.show(state, crc_errors);
96 descent.show(state, crc_errors);
97 landed.show(state, crc_errors);
101 pane.setSelectedComponent(pad);
104 pane.setSelectedComponent(ascent);
107 pane.setSelectedComponent(descent);
110 pane.setSelectedComponent(landed);
114 flightStatus.show(state, crc_errors);
115 flightInfo.show(state, crc_errors);
116 sitemap.show(state, crc_errors);
119 public void set_exit_on_close() {
120 exit_on_close = true;
126 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
127 AltosPreferences.init(this);
132 bag = getContentPane();
133 bag.setLayout(new GridBagLayout());
135 GridBagConstraints c = new GridBagConstraints();
137 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
139 setIconImage(new ImageIcon(imgURL).getImage());
141 setTitle(String.format("AltOS %s", reader.name));
143 /* Stick channel selector at top of table for telemetry monitoring */
146 channels = new AltosChannelMenu(AltosPreferences.channel(serial));
147 channels.addActionListener(new ActionListener() {
148 public void actionPerformed(ActionEvent e) {
149 int channel = channels.getSelectedIndex();
150 reader.set_channel(channel);
151 AltosPreferences.set_channel(serial, channel);
156 c.anchor = GridBagConstraints.WEST;
157 bag.add (channels, c);
160 /* Flight status is always visible */
161 flightStatus = new AltosFlightStatus();
164 c.fill = GridBagConstraints.HORIZONTAL;
166 bag.add(flightStatus, c);
168 /* The rest of the window uses a tabbed pane to
169 * show one of the alternate data views
171 pane = new JTabbedPane();
173 pad = new AltosPad();
174 pane.add("Launch Pad", pad);
176 ascent = new AltosAscent();
177 pane.add("Ascent", ascent);
179 descent = new AltosDescent();
180 pane.add("Descent", descent);
182 landed = new AltosLanded();
183 pane.add("Landed", landed);
185 flightInfo = new AltosInfoTable();
186 pane.add("Table", new JScrollPane(flightInfo));
188 sitemap = new AltosSiteMap();
189 pane.add("Site Map", sitemap);
191 /* Make the tabbed pane use the rest of the window space */
194 c.fill = GridBagConstraints.BOTH;
199 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
200 addWindowListener(new WindowAdapter() {
202 public void windowClosing(WindowEvent e) {
214 thread = new AltosDisplayThread(this, voice, this, reader);
219 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
220 this(in_voice, in_reader, -1);