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;
46 private AltosFlightStatus flightStatus;
47 private JScrollPane flightInfoPane;
48 private AltosInfoTable flightInfo;
50 static final int tab_pad = 1;
51 static final int tab_ascent = 2;
52 static final int tab_descent = 3;
53 static final int tab_landed = 4;
57 boolean exit_on_close = false;
59 int which_tab(AltosState state) {
60 if (state.state < Altos.ao_flight_boost)
62 if (state.state <= Altos.ao_flight_coast)
64 if (state.state <= Altos.ao_flight_main)
70 return flightInfo.width();
74 return flightStatus.height() + flightInfo.height();
78 if (thread != null && thread.isAlive()) {
82 } catch (InterruptedException ie) {}
99 public void show(AltosState state, int crc_errors) {
100 int tab = which_tab(state);
101 pad.show(state, crc_errors);
102 ascent.show(state, crc_errors);
103 descent.show(state, crc_errors);
104 landed.show(state, crc_errors);
105 if (tab != cur_tab) {
108 pane.setSelectedComponent(pad);
111 pane.setSelectedComponent(ascent);
114 pane.setSelectedComponent(descent);
117 pane.setSelectedComponent(landed);
121 flightStatus.show(state, crc_errors);
122 flightInfo.show(state, crc_errors);
125 public void set_exit_on_close() {
126 exit_on_close = true;
132 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
133 AltosPreferences.init(this);
138 bag = getContentPane();
139 bag.setLayout(new GridBagLayout());
141 GridBagConstraints c = new GridBagConstraints();
143 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
145 setIconImage(new ImageIcon(imgURL).getImage());
147 setTitle(String.format("AltOS %s", reader.name));
151 channels = new AltosChannelMenu(AltosPreferences.channel(serial));
152 channels.addActionListener(new ActionListener() {
153 public void actionPerformed(ActionEvent e) {
154 int channel = channels.getSelectedIndex();
155 reader.set_channel(channel);
156 AltosPreferences.set_channel(serial, channel);
161 c.anchor = GridBagConstraints.WEST;
162 bag.add (channels, c);
165 flightStatus = new AltosFlightStatus();
168 c.fill = GridBagConstraints.HORIZONTAL;
170 bag.add(flightStatus, c);
172 pane = new JTabbedPane();
174 pad = new AltosPad();
175 pane.add("Launch Pad", pad);
177 ascent = new AltosAscent();
178 pane.add("Ascent", ascent);
180 descent = new AltosDescent();
181 pane.add("Descent", descent);
183 landed = new AltosLanded();
184 pane.add("Landed", landed);
186 flightInfo = new AltosInfoTable();
187 flightInfoPane = new JScrollPane(flightInfo.box());
188 pane.add("Table", flightInfoPane);
192 c.fill = GridBagConstraints.BOTH;
197 this.setSize(this.getPreferredSize());
200 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
201 addWindowListener(new WindowAdapter() {
203 public void windowClosing(WindowEvent e) {
212 this.setVisible(true);
214 thread = new AltosDisplayThread(this, voice, this, reader);
219 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
220 this(in_voice, in_reader, -1);