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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 import java.awt.event.*;
25 import org.altusmetrum.altoslib_14.*;
26 import org.altusmetrum.altosuilib_14.*;
28 public class AltosLanded extends AltosUIFlightTab implements ActionListener {
30 class Bearing extends AltosUIIndicator {
31 public void show (AltosState state, AltosListenerState listener_state) {
32 if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) {
33 show( String.format("%3.0f°", state.from_pad.bearing),
34 state.from_pad.bearing_words(
35 AltosGreatCircle.BEARING_LONG));
37 show("Missing", "Missing");
40 public Bearing (Container container, int y) {
41 super (container, y, "Bearing", 2);
45 class Distance extends AltosUIUnitsIndicator {
46 public double value(AltosState state, int i) {
47 if (state.from_pad != null)
48 return state.from_pad.distance;
50 return AltosLib.MISSING;
53 public Distance(Container container, int y) {
54 super(container, y, AltosConvert.distance, "Ground Distance", 2);
58 class Lat extends AltosUIUnitsIndicator {
60 public boolean hide (AltosState state, int i) { return state.gps == null || !state.gps.connected; }
62 public double value(AltosState state, int i) {
63 if (state.gps == null)
64 return AltosLib.MISSING;
65 if (!state.gps.connected)
66 return AltosLib.MISSING;
70 public Lat (Container container, int y) {
71 super (container, y, AltosConvert.latitude, "Latitude", 2);
75 class Lon extends AltosUIUnitsIndicator {
76 public boolean hide (AltosState state, int i) { return state.gps == null || !state.gps.connected; }
78 public double value(AltosState state, int i) {
79 if (state.gps == null)
80 return AltosLib.MISSING;
81 if (!state.gps.connected)
82 return AltosLib.MISSING;
86 public Lon (Container container, int y) {
87 super (container, y, AltosConvert.longitude, "Longitude", 2);
91 class MaxHeight extends AltosUIUnitsIndicator {
92 public double value(AltosState state, int i) { return state.max_height(); }
94 public MaxHeight (Container container, int y) {
95 super (container, y, AltosConvert.height, "Maximum Height", 2);
99 class MaxSpeed extends AltosUIUnitsIndicator {
100 public double value(AltosState state, int i) { return state.max_speed(); }
102 public MaxSpeed (Container container, int y) {
103 super (container, y, AltosConvert.speed, "Maximum Speed", 2);
107 class MaxAccel extends AltosUIUnitsIndicator {
108 public double value(AltosState state, int i) { return state.max_acceleration(); }
110 public MaxAccel (Container container, int y) {
111 super (container, y, AltosConvert.speed, "Maximum acceleration", 2);
116 AltosFlightReader reader;
118 public void actionPerformed(ActionEvent e) {
119 String cmd = e.getActionCommand();
121 if (cmd.equals("graph")) {
122 File file = reader.backing_file();
124 String filename = file.getName();
126 AltosRecordSet record_set = null;
127 FileInputStream in = new FileInputStream(file);
128 if (filename.endsWith("eeprom")) {
129 record_set = new AltosEepromRecordSet(in);
130 } else if (filename.endsWith("telem")) {
131 record_set = new AltosTelemetryFile(in);
133 throw new FileNotFoundException(filename);
136 new AltosGraphUI(record_set, file);
137 } catch (InterruptedException ie) {
138 } catch (IOException ie) {
140 } catch (FileNotFoundException fe) {
141 JOptionPane.showMessageDialog(null,
144 JOptionPane.ERROR_MESSAGE);
145 } catch (IOException ie) {
146 JOptionPane.showMessageDialog(null,
148 "Error reading file file",
149 JOptionPane.ERROR_MESSAGE);
155 public String getName() {
159 public void show(AltosState state, AltosListenerState listener_state) {
160 super.show(state, listener_state);
161 if (reader.backing_file() != null)
162 graph.setEnabled(true);
165 public AltosLanded(AltosFlightReader in_reader) {
168 /* Elements in descent display */
169 add(new Bearing(this, 0));
170 add(new Distance(this, 1));
171 add(new Lat(this, 2));
172 add(new Lon(this, 3));
173 add(new MaxHeight(this, 4));
174 add(new MaxSpeed(this, 5));
175 add(new MaxAccel(this, 6));
177 graph = new JButton ("Graph Flight");
178 graph.setActionCommand("graph");
179 graph.addActionListener(this);
180 graph.setEnabled(false);
182 GridBagConstraints c = new GridBagConstraints();
184 c.gridx = 1; c.gridy = 7;
185 c.insets = new Insets(10, 10, 10, 10);
186 c.anchor = GridBagConstraints.WEST;
189 c.fill = GridBagConstraints.VERTICAL;
191 addHierarchyListener(this);