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.*;
24 import org.altusmetrum.altoslib_5.*;
25 import org.altusmetrum.altosuilib_3.*;
27 public class AltosLanded extends AltosUIFlightTab implements ActionListener {
29 class Bearing extends AltosUIIndicator {
30 public void show (AltosState state, AltosListenerState listener_state) {
31 if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) {
32 show( String.format("%3.0f°", state.from_pad.bearing),
33 state.from_pad.bearing_words(
34 AltosGreatCircle.BEARING_LONG));
36 show("Missing", "Missing");
39 public Bearing (Container container, int y) {
40 super (container, y, "Bearing", 2);
44 class Distance extends AltosUIUnitsIndicator {
45 public double value(AltosState state, int i) {
46 if (state.from_pad != null)
47 return state.from_pad.distance;
49 return AltosLib.MISSING;
52 public Distance(Container container, int y) {
53 super(container, y, AltosConvert.distance, "Ground Distance", 2);
57 class Lat extends AltosUIUnitsIndicator {
59 public boolean hide (AltosState state, int i) { return state.gps == null || !state.gps.connected; }
61 public double value(AltosState state, int i) {
62 if (state.gps == null)
63 return AltosLib.MISSING;
64 if (!state.gps.connected)
65 return AltosLib.MISSING;
69 public Lat (Container container, int y) {
70 super (container, y, AltosConvert.latitude, "Latitude", 2);
74 class Lon extends AltosUIUnitsIndicator {
75 public boolean hide (AltosState state, int i) { return state.gps == null || !state.gps.connected; }
77 public double value(AltosState state, int i) {
78 if (state.gps == null)
79 return AltosLib.MISSING;
80 if (!state.gps.connected)
81 return AltosLib.MISSING;
85 public Lon (Container container, int y) {
86 super (container, y, AltosConvert.longitude, "Longitude", 2);
90 class MaxHeight extends AltosUIUnitsIndicator {
91 public double value(AltosState state, int i) { return state.max_height(); }
93 public MaxHeight (Container container, int y) {
94 super (container, y, AltosConvert.height, "Maximum Height", 2);
98 class MaxSpeed extends AltosUIUnitsIndicator {
99 public double value(AltosState state, int i) { return state.max_speed(); }
101 public MaxSpeed (Container container, int y) {
102 super (container, y, AltosConvert.speed, "Maximum Speed", 2);
106 class MaxAccel extends AltosUIUnitsIndicator {
107 public double value(AltosState state, int i) { return state.max_acceleration(); }
109 public MaxAccel (Container container, int y) {
110 super (container, y, AltosConvert.speed, "Maximum acceleration", 2);
115 AltosFlightReader reader;
117 public void actionPerformed(ActionEvent e) {
118 String cmd = e.getActionCommand();
120 if (cmd.equals("graph")) {
121 File file = reader.backing_file();
123 String filename = file.getName();
125 AltosStateIterable states = null;
126 if (filename.endsWith("eeprom")) {
127 FileInputStream in = new FileInputStream(file);
128 states = new AltosEepromFile(in);
129 } else if (filename.endsWith("telem")) {
130 FileInputStream in = new FileInputStream(file);
131 states = new AltosTelemetryFile(in);
133 throw new FileNotFoundException(filename);
136 new AltosGraphUI(states, file);
137 } catch (InterruptedException ie) {
138 } catch (IOException ie) {
140 } catch (FileNotFoundException fe) {
141 JOptionPane.showMessageDialog(null,
144 JOptionPane.ERROR_MESSAGE);
150 public String getName() {
154 public AltosLanded(AltosFlightReader in_reader) {
157 /* Elements in descent display */
158 add(new Bearing(this, 0));
159 add(new Distance(this, 1));
160 add(new Lat(this, 2));
161 add(new Lon(this, 3));
162 add(new MaxHeight(this, 4));
163 add(new MaxSpeed(this, 5));
164 add(new MaxAccel(this, 6));
166 graph = new JButton ("Graph Flight");
167 graph.setActionCommand("graph");
168 graph.addActionListener(this);
169 graph.setEnabled(false);
171 GridBagConstraints c = new GridBagConstraints();
173 c.gridx = 1; c.gridy = 7;
174 c.insets = new Insets(10, 10, 10, 10);
175 c.anchor = GridBagConstraints.WEST;
178 c.fill = GridBagConstraints.VERTICAL;
180 addHierarchyListener(this);