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.*;
30 import org.altusmetrum.AltosLib.*;
32 public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, AltosFontListener {
34 AltosFlightReader reader;
35 AltosDisplayThread thread;
43 AltosCompanionInfo companion;
46 boolean has_companion;
48 private AltosFlightStatus flightStatus;
49 private AltosInfoTable flightInfo;
51 boolean exit_on_close = false;
53 JComponent cur_tab = null;
54 JComponent which_tab(AltosState state) {
55 if (state.state < Altos.ao_flight_boost)
57 if (state.state <= Altos.ao_flight_coast)
59 if (state.state <= Altos.ao_flight_main)
65 if (thread != null && thread.isAlive()) {
69 } catch (InterruptedException ie) {}
87 public void set_font() {
92 flightStatus.set_font();
93 flightInfo.set_font();
98 public void font_size_changed(int font_size) {
102 public void show(AltosState state, int crc_errors) {
103 JComponent tab = which_tab(state);
105 pad.show(state, crc_errors);
106 ascent.show(state, crc_errors);
107 descent.show(state, crc_errors);
108 landed.show(state, crc_errors);
109 if (tab != cur_tab) {
110 if (cur_tab == pane.getSelectedComponent()) {
111 pane.setSelectedComponent(tab);
115 flightStatus.show(state, crc_errors);
116 flightInfo.show(state, crc_errors);
118 if (state.data.companion != null) {
119 if (!has_companion) {
120 pane.add("Companion", companion);
123 companion.show(state, crc_errors);
126 pane.remove(companion);
127 has_companion = false;
130 if (state.gps != null && state.gps.connected) {
132 pane.add("Site Map", sitemap);
135 sitemap.show(state, crc_errors);
138 pane.remove(sitemap);
142 } catch (Exception e) {
143 System.out.print("Show exception" + e);
147 public void set_exit_on_close() {
148 exit_on_close = true;
152 AltosFreqList frequencies;
153 JComboBox telemetries;
155 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
156 AltosUIPreferences.set_component(this);
161 bag = getContentPane();
162 bag.setLayout(new GridBagLayout());
164 GridBagConstraints c = new GridBagConstraints();
166 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
168 setIconImage(new ImageIcon(imgURL).getImage());
170 setTitle(String.format("AltOS %s", reader.name));
172 /* Stick channel selector at top of table for telemetry monitoring */
175 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
176 frequencies.set_product("Monitor");
177 frequencies.set_serial(serial);
178 frequencies.addActionListener(new ActionListener() {
179 public void actionPerformed(ActionEvent e) {
180 double frequency = frequencies.frequency();
182 reader.set_frequency(frequency);
183 } catch (TimeoutException te) {
184 } catch (InterruptedException ie) {
186 reader.save_frequency();
193 c.insets = new Insets(3, 3, 3, 3);
194 c.fill = GridBagConstraints.NONE;
195 c.anchor = GridBagConstraints.WEST;
196 bag.add (frequencies, c);
198 // Telemetry format menu
199 telemetries = new JComboBox();
200 for (int i = 1; i <= Altos.ao_telemetry_max; i++)
201 telemetries.addItem(Altos.telemetry_name(i));
202 int telemetry = AltosUIPreferences.telemetry(serial);
203 if (telemetry <= Altos.ao_telemetry_off ||
204 telemetry > Altos.ao_telemetry_max)
205 telemetry = Altos.ao_telemetry_standard;
206 telemetries.setSelectedIndex(telemetry - 1);
207 telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
208 telemetries.setPreferredSize(null);
209 telemetries.revalidate();
210 telemetries.addActionListener(new ActionListener() {
211 public void actionPerformed(ActionEvent e) {
212 int telemetry = telemetries.getSelectedIndex() + 1;
213 reader.set_telemetry(telemetry);
214 reader.save_telemetry();
221 c.fill = GridBagConstraints.NONE;
222 c.anchor = GridBagConstraints.WEST;
223 bag.add (telemetries, c);
224 c.insets = new Insets(0, 0, 0, 0);
227 /* Flight status is always visible */
228 flightStatus = new AltosFlightStatus();
231 c.fill = GridBagConstraints.HORIZONTAL;
234 bag.add(flightStatus, c);
237 /* The rest of the window uses a tabbed pane to
238 * show one of the alternate data views
240 pane = new JTabbedPane();
242 pad = new AltosPad();
243 pane.add("Launch Pad", pad);
245 ascent = new AltosAscent();
246 pane.add("Ascent", ascent);
248 descent = new AltosDescent();
249 pane.add("Descent", descent);
251 landed = new AltosLanded(reader);
252 pane.add("Landed", landed);
254 flightInfo = new AltosInfoTable();
255 pane.add("Table", new JScrollPane(flightInfo));
257 companion = new AltosCompanionInfo();
258 has_companion = false;
260 sitemap = new AltosSiteMap();
263 /* Make the tabbed pane use the rest of the window space */
266 c.fill = GridBagConstraints.BOTH;
272 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
274 AltosUIPreferences.register_font_listener(this);
276 addWindowListener(new WindowAdapter() {
278 public void windowClosing(WindowEvent e) {
282 AltosUIPreferences.unregister_font_listener(AltosFlightUI.this);
291 thread = new AltosDisplayThread(this, voice, this, reader);
296 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
297 this(in_voice, in_reader, -1);