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;
48 private AltosFlightStatus flightStatus;
49 private JScrollPane flightInfoPane;
50 private AltosInfoTable flightInfo;
52 static final int tab_pad = 1;
53 static final int tab_ascent = 2;
54 static final int tab_descent = 3;
55 static final int tab_landed = 4;
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 AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
126 AltosPreferences.init(this);
131 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
133 setIconImage(new ImageIcon(imgURL).getImage());
135 setTitle(String.format("AltOS %s", reader.name));
137 flightStatus = new AltosFlightStatus();
139 vbox = new Box (BoxLayout.Y_AXIS);
140 vbox.add(flightStatus);
142 pane = new JTabbedPane();
144 pad = new AltosPad();
145 pane.add("Launch Pad", pad);
147 ascent = new AltosAscent();
148 pane.add("Ascent", ascent);
150 descent = new AltosDescent();
151 pane.add("Descent", descent);
153 landed = new AltosLanded();
154 pane.add("Landed", landed);
156 flightInfo = new AltosInfoTable();
157 flightInfoPane = new JScrollPane(flightInfo.box());
158 pane.add("Table", flightInfoPane);
165 JMenuBar menubar = new JMenuBar();
169 JMenu menu = new AltosChannelMenu(AltosPreferences.channel(serial));
170 menu.addActionListener(new ActionListener() {
171 public void actionPerformed(ActionEvent e) {
172 int channel = Integer.parseInt(e.getActionCommand());
173 reader.set_channel(channel);
174 AltosPreferences.set_channel(serial, channel);
177 menu.setMnemonic(KeyEvent.VK_C);
181 this.setJMenuBar(menubar);
184 this.setSize(new Dimension (width(), height()));
187 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
188 addWindowListener(new WindowAdapter() {
190 public void windowClosing(WindowEvent e) {
197 this.setVisible(true);
199 thread = new AltosDisplayThread(this, voice, this, reader);
204 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
205 this(in_voice, in_reader, -1);