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;
45 private AltosFlightStatus flightStatus;
46 private AltosInfoTable flightInfo;
48 boolean exit_on_close = false;
50 JComponent cur_tab = null;
51 JComponent which_tab(AltosState state) {
52 if (state.state < Altos.ao_flight_boost)
54 if (state.state <= Altos.ao_flight_coast)
56 if (state.state <= Altos.ao_flight_main)
62 if (thread != null && thread.isAlive()) {
66 } catch (InterruptedException ie) {}
84 public void show(AltosState state, int crc_errors) {
85 JComponent tab = which_tab(state);
87 pad.show(state, crc_errors);
88 ascent.show(state, crc_errors);
89 descent.show(state, crc_errors);
90 landed.show(state, crc_errors);
92 if (cur_tab == pane.getSelectedComponent()) {
93 pane.setSelectedComponent(tab);
97 flightStatus.show(state, crc_errors);
98 flightInfo.show(state, crc_errors);
99 if (state.gps != null) {
101 pane.add("Site Map", sitemap);
104 sitemap.show(state, crc_errors);
107 pane.remove(sitemap);
111 } catch (Exception e) {
112 System.out.print("Show exception" + e);
116 public void set_exit_on_close() {
117 exit_on_close = true;
121 AltosFreqList frequencies;
122 JComboBox telemetries;
124 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
125 AltosPreferences.set_component(this);
130 bag = getContentPane();
131 bag.setLayout(new GridBagLayout());
133 GridBagConstraints c = new GridBagConstraints();
135 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
137 setIconImage(new ImageIcon(imgURL).getImage());
139 setTitle(String.format("AltOS %s", reader.name));
141 /* Stick channel selector at top of table for telemetry monitoring */
144 frequencies = new AltosFreqList(AltosPreferences.frequency(serial));
145 frequencies.set_product("Monitor");
146 frequencies.set_serial(serial);
147 frequencies.addActionListener(new ActionListener() {
148 public void actionPerformed(ActionEvent e) {
149 double frequency = frequencies.frequency();
151 reader.set_frequency(frequency);
152 } catch (TimeoutException te) {
153 } catch (InterruptedException ie) {
155 reader.save_frequency();
160 c.insets = new Insets(3, 3, 3, 3);
161 c.anchor = GridBagConstraints.WEST;
162 bag.add (frequencies, c);
164 // Telemetry format menu
165 telemetries = new JComboBox();
166 for (int i = 1; i <= Altos.ao_telemetry_max; i++)
167 telemetries.addItem(Altos.telemetry_name(i));
168 int telemetry = AltosPreferences.telemetry(serial);
169 if (telemetry <= Altos.ao_telemetry_off ||
170 telemetry > Altos.ao_telemetry_max)
171 telemetry = Altos.ao_telemetry_standard;
172 telemetries.setSelectedIndex(telemetry - 1);
173 telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
174 telemetries.addActionListener(new ActionListener() {
175 public void actionPerformed(ActionEvent e) {
176 int telemetry = telemetries.getSelectedIndex() + 1;
177 reader.set_telemetry(telemetry);
178 reader.save_telemetry();
183 c.fill = GridBagConstraints.NONE;
184 c.anchor = GridBagConstraints.WEST;
185 bag.add (telemetries, c);
186 c.insets = new Insets(0, 0, 0, 0);
189 /* Flight status is always visible */
190 flightStatus = new AltosFlightStatus();
193 c.fill = GridBagConstraints.HORIZONTAL;
196 bag.add(flightStatus, c);
199 /* The rest of the window uses a tabbed pane to
200 * show one of the alternate data views
202 pane = new JTabbedPane();
204 pad = new AltosPad();
205 pane.add("Launch Pad", pad);
207 ascent = new AltosAscent();
208 pane.add("Ascent", ascent);
210 descent = new AltosDescent();
211 pane.add("Descent", descent);
213 landed = new AltosLanded(reader);
214 pane.add("Landed", landed);
216 flightInfo = new AltosInfoTable();
217 pane.add("Table", new JScrollPane(flightInfo));
219 sitemap = new AltosSiteMap();
222 /* Make the tabbed pane use the rest of the window space */
225 c.fill = GridBagConstraints.BOTH;
231 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
232 addWindowListener(new WindowAdapter() {
234 public void windowClosing(WindowEvent e) {
246 thread = new AltosDisplayThread(this, voice, this, reader);
251 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
252 this(in_voice, in_reader, -1);