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.*;
31 public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
33 AltosFlightReader reader;
34 AltosDisplayThread thread;
42 AltosCompanionInfo companion;
45 boolean has_companion;
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);
89 pad.show(state, crc_errors);
90 ascent.show(state, crc_errors);
91 descent.show(state, crc_errors);
92 landed.show(state, crc_errors);
94 if (cur_tab == pane.getSelectedComponent()) {
95 pane.setSelectedComponent(tab);
99 flightStatus.show(state, crc_errors);
100 flightInfo.show(state, crc_errors);
102 if (state.data.companion != null) {
103 if (!has_companion) {
104 pane.add("Companion", companion);
107 companion.show(state, crc_errors);
110 pane.remove(companion);
111 has_companion = false;
114 if (state.gps != null && state.gps.connected) {
116 pane.add("Site Map", sitemap);
119 sitemap.show(state, crc_errors);
122 pane.remove(sitemap);
126 } catch (Exception e) {
127 System.out.print("Show exception" + e);
131 public void set_exit_on_close() {
132 exit_on_close = true;
136 AltosFreqList frequencies;
137 JComboBox telemetries;
139 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
140 AltosPreferences.set_component(this);
145 bag = getContentPane();
146 bag.setLayout(new GridBagLayout());
148 GridBagConstraints c = new GridBagConstraints();
150 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
152 setIconImage(new ImageIcon(imgURL).getImage());
154 setTitle(String.format("AltOS %s", reader.name));
156 /* Stick channel selector at top of table for telemetry monitoring */
159 frequencies = new AltosFreqList(AltosPreferences.frequency(serial));
160 frequencies.set_product("Monitor");
161 frequencies.set_serial(serial);
162 frequencies.addActionListener(new ActionListener() {
163 public void actionPerformed(ActionEvent e) {
164 double frequency = frequencies.frequency();
166 reader.set_frequency(frequency);
167 } catch (TimeoutException te) {
168 } catch (InterruptedException ie) {
170 reader.save_frequency();
175 c.insets = new Insets(3, 3, 3, 3);
176 c.anchor = GridBagConstraints.WEST;
177 bag.add (frequencies, c);
179 // Telemetry format menu
180 telemetries = new JComboBox();
181 for (int i = 1; i <= Altos.ao_telemetry_max; i++)
182 telemetries.addItem(Altos.telemetry_name(i));
183 int telemetry = AltosPreferences.telemetry(serial);
184 if (telemetry <= Altos.ao_telemetry_off ||
185 telemetry > Altos.ao_telemetry_max)
186 telemetry = Altos.ao_telemetry_standard;
187 telemetries.setSelectedIndex(telemetry - 1);
188 telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
189 telemetries.addActionListener(new ActionListener() {
190 public void actionPerformed(ActionEvent e) {
191 int telemetry = telemetries.getSelectedIndex() + 1;
192 reader.set_telemetry(telemetry);
193 reader.save_telemetry();
198 c.fill = GridBagConstraints.NONE;
199 c.anchor = GridBagConstraints.WEST;
200 bag.add (telemetries, c);
201 c.insets = new Insets(0, 0, 0, 0);
204 /* Flight status is always visible */
205 flightStatus = new AltosFlightStatus();
208 c.fill = GridBagConstraints.HORIZONTAL;
211 bag.add(flightStatus, c);
214 /* The rest of the window uses a tabbed pane to
215 * show one of the alternate data views
217 pane = new JTabbedPane();
219 pad = new AltosPad();
220 pane.add("Launch Pad", pad);
222 ascent = new AltosAscent();
223 pane.add("Ascent", ascent);
225 descent = new AltosDescent();
226 pane.add("Descent", descent);
228 landed = new AltosLanded(reader);
229 pane.add("Landed", landed);
231 flightInfo = new AltosInfoTable();
232 pane.add("Table", new JScrollPane(flightInfo));
234 companion = new AltosCompanionInfo();
235 has_companion = false;
237 sitemap = new AltosSiteMap();
240 /* Make the tabbed pane use the rest of the window space */
243 c.fill = GridBagConstraints.BOTH;
249 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
250 addWindowListener(new WindowAdapter() {
252 public void windowClosing(WindowEvent e) {
264 thread = new AltosDisplayThread(this, voice, this, reader);
269 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
270 this(in_voice, in_reader, -1);