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;
46 private AltosFlightStatus flightStatus;
47 private AltosInfoTable flightInfo;
49 static final int tab_pad = 1;
50 static final int tab_ascent = 2;
51 static final int tab_descent = 3;
52 static final int tab_landed = 4;
56 boolean exit_on_close = false;
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 if (thread != null && thread.isAlive()) {
73 } catch (InterruptedException ie) {}
90 public void show(AltosState state, int crc_errors) {
91 int tab = which_tab(state);
92 pad.show(state, crc_errors);
93 ascent.show(state, crc_errors);
94 descent.show(state, crc_errors);
95 landed.show(state, crc_errors);
99 pane.setSelectedComponent(pad);
102 pane.setSelectedComponent(ascent);
105 pane.setSelectedComponent(descent);
108 pane.setSelectedComponent(landed);
112 flightStatus.show(state, crc_errors);
113 flightInfo.show(state, crc_errors);
116 public void set_exit_on_close() {
117 exit_on_close = true;
123 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
124 AltosPreferences.init(this);
129 bag = getContentPane();
130 bag.setLayout(new GridBagLayout());
132 GridBagConstraints c = new GridBagConstraints();
134 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
136 setIconImage(new ImageIcon(imgURL).getImage());
138 setTitle(String.format("AltOS %s", reader.name));
140 /* Stick channel selector at top of table for telemetry monitoring */
143 channels = new AltosChannelMenu(AltosPreferences.channel(serial));
144 channels.addActionListener(new ActionListener() {
145 public void actionPerformed(ActionEvent e) {
146 int channel = channels.getSelectedIndex();
147 reader.set_channel(channel);
148 AltosPreferences.set_channel(serial, channel);
153 c.anchor = GridBagConstraints.WEST;
154 bag.add (channels, c);
157 /* Flight status is always visible */
158 flightStatus = new AltosFlightStatus();
161 c.fill = GridBagConstraints.HORIZONTAL;
163 bag.add(flightStatus, c);
165 /* The rest of the window uses a tabbed pane to
166 * show one of the alternate data views
168 pane = new JTabbedPane();
170 pad = new AltosPad();
171 pane.add("Launch Pad", pad);
173 ascent = new AltosAscent();
174 pane.add("Ascent", ascent);
176 descent = new AltosDescent();
177 pane.add("Descent", descent);
179 landed = new AltosLanded();
180 pane.add("Landed", landed);
182 flightInfo = new AltosInfoTable();
183 pane.add("Table", new JScrollPane(flightInfo));
185 /* Make the tabbed pane use the rest of the window space */
188 c.fill = GridBagConstraints.BOTH;
193 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
194 addWindowListener(new WindowAdapter() {
196 public void windowClosing(WindowEvent e) {
208 thread = new AltosDisplayThread(this, voice, this, reader);
213 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
214 this(in_voice, in_reader, -1);