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();
177 c.insets = new Insets(3, 3, 3, 3);
178 c.fill = GridBagConstraints.NONE;
179 c.anchor = GridBagConstraints.WEST;
180 bag.add (frequencies, c);
182 // Telemetry format menu
183 telemetries = new JComboBox();
184 for (int i = 1; i <= Altos.ao_telemetry_max; i++)
185 telemetries.addItem(Altos.telemetry_name(i));
186 int telemetry = AltosPreferences.telemetry(serial);
187 if (telemetry <= Altos.ao_telemetry_off ||
188 telemetry > Altos.ao_telemetry_max)
189 telemetry = Altos.ao_telemetry_standard;
190 telemetries.setSelectedIndex(telemetry - 1);
191 telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
192 telemetries.setPreferredSize(null);
193 telemetries.revalidate();
194 telemetries.addActionListener(new ActionListener() {
195 public void actionPerformed(ActionEvent e) {
196 int telemetry = telemetries.getSelectedIndex() + 1;
197 reader.set_telemetry(telemetry);
198 reader.save_telemetry();
205 c.fill = GridBagConstraints.NONE;
206 c.anchor = GridBagConstraints.WEST;
207 bag.add (telemetries, c);
208 c.insets = new Insets(0, 0, 0, 0);
211 /* Flight status is always visible */
212 flightStatus = new AltosFlightStatus();
215 c.fill = GridBagConstraints.HORIZONTAL;
218 bag.add(flightStatus, c);
221 /* The rest of the window uses a tabbed pane to
222 * show one of the alternate data views
224 pane = new JTabbedPane();
226 pad = new AltosPad();
227 pane.add("Launch Pad", pad);
229 ascent = new AltosAscent();
230 pane.add("Ascent", ascent);
232 descent = new AltosDescent();
233 pane.add("Descent", descent);
235 landed = new AltosLanded(reader);
236 pane.add("Landed", landed);
238 flightInfo = new AltosInfoTable();
239 pane.add("Table", new JScrollPane(flightInfo));
241 companion = new AltosCompanionInfo();
242 has_companion = false;
244 sitemap = new AltosSiteMap();
247 /* Make the tabbed pane use the rest of the window space */
250 c.fill = GridBagConstraints.BOTH;
256 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
257 addWindowListener(new WindowAdapter() {
259 public void windowClosing(WindowEvent e) {
271 thread = new AltosDisplayThread(this, voice, this, reader);
276 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
277 this(in_voice, in_reader, -1);