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 boolean exit_on_close = false;
52 JComponent cur_tab = null;
53 JComponent which_tab(AltosState state) {
54 if (state.state < Altos.ao_flight_boost)
56 if (state.state <= Altos.ao_flight_coast)
58 if (state.state <= Altos.ao_flight_main)
64 if (thread != null && thread.isAlive()) {
68 } catch (InterruptedException ie) {}
86 public void show(AltosState state, int crc_errors) {
87 JComponent tab = which_tab(state);
88 pad.show(state, crc_errors);
89 ascent.show(state, crc_errors);
90 descent.show(state, crc_errors);
91 landed.show(state, crc_errors);
93 if (cur_tab == pane.getSelectedComponent()) {
94 pane.setSelectedComponent(tab);
98 flightStatus.show(state, crc_errors);
99 flightInfo.show(state, crc_errors);
100 sitemap.show(state, crc_errors);
103 public void set_exit_on_close() {
104 exit_on_close = true;
110 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
111 AltosPreferences.init(this);
116 bag = getContentPane();
117 bag.setLayout(new GridBagLayout());
119 GridBagConstraints c = new GridBagConstraints();
121 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
123 setIconImage(new ImageIcon(imgURL).getImage());
125 setTitle(String.format("AltOS %s", reader.name));
127 /* Stick channel selector at top of table for telemetry monitoring */
130 channels = new AltosChannelMenu(AltosPreferences.channel(serial));
131 channels.addActionListener(new ActionListener() {
132 public void actionPerformed(ActionEvent e) {
133 int channel = channels.getSelectedIndex();
134 reader.set_channel(channel);
139 c.anchor = GridBagConstraints.WEST;
140 bag.add (channels, c);
143 /* Flight status is always visible */
144 flightStatus = new AltosFlightStatus();
147 c.fill = GridBagConstraints.HORIZONTAL;
149 bag.add(flightStatus, c);
151 /* The rest of the window uses a tabbed pane to
152 * show one of the alternate data views
154 pane = new JTabbedPane();
156 pad = new AltosPad();
157 pane.add("Launch Pad", pad);
159 ascent = new AltosAscent();
160 pane.add("Ascent", ascent);
162 descent = new AltosDescent();
163 pane.add("Descent", descent);
165 landed = new AltosLanded();
166 pane.add("Landed", landed);
168 flightInfo = new AltosInfoTable();
169 pane.add("Table", new JScrollPane(flightInfo));
171 sitemap = new AltosSiteMap();
172 pane.add("Site Map", sitemap);
174 /* Make the tabbed pane use the rest of the window space */
177 c.fill = GridBagConstraints.BOTH;
182 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
183 addWindowListener(new WindowAdapter() {
185 public void windowClosing(WindowEvent e) {
197 thread = new AltosDisplayThread(this, voice, this, reader);
202 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
203 this(in_voice, in_reader, -1);