ao-tools/ao-dump-up: Document --wait flag
[fw/altos] / altosui / AltosDescent.java
1 /*
2  * Copyright © 2010 Keith Packard <keithp@keithp.com>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 package altosui;
20
21 import java.util.*;
22 import java.awt.*;
23 import java.awt.event.*;
24 import javax.swing.*;
25 import org.altusmetrum.altoslib_13.*;
26 import org.altusmetrum.altosuilib_13.*;
27
28 public class AltosDescent extends AltosUIFlightTab {
29
30         class Height extends AltosUIUnitsIndicator {
31                 public double value(AltosState state, int i) { return state.height(); }
32
33                 public Height (Container container, int x, int y) {
34                         super (container, x, y, AltosConvert.height, "Height");
35                 }
36         }
37
38         class Speed extends AltosUIUnitsIndicator {
39                 public double value(AltosState state, int i) { return state.speed(); }
40
41                 public Speed (Container container, int x, int y) {
42                         super (container, x, y, AltosConvert.speed, "Speed");
43                 }
44         }
45
46         class Lat extends AltosUIUnitsIndicator {
47
48                 public boolean hide (AltosState state, int i) { return state.gps == null || !state.gps.connected; }
49
50                 public double value(AltosState state, int i) {
51                         if (state.gps == null)
52                                 return AltosLib.MISSING;
53                         if (!state.gps.connected)
54                                 return AltosLib.MISSING;
55                         return state.gps.lat;
56                 }
57
58                 public Lat (Container container, int x, int y) {
59                         super (container, x, y, AltosConvert.latitude, "Latitude");
60                 }
61         }
62
63         class Lon extends AltosUIUnitsIndicator {
64                 public boolean hide (AltosState state, int i) { return state.gps == null || !state.gps.connected; }
65
66                 public double value(AltosState state, int i) {
67                         if (state.gps == null)
68                                 return AltosLib.MISSING;
69                         if (!state.gps.connected)
70                                 return AltosLib.MISSING;
71                         return state.gps.lon;
72                 }
73
74                 public Lon (Container container, int x, int y) {
75                         super (container, x, y, AltosConvert.longitude, "Longitude");
76                 }
77         }
78
79         class Apogee extends AltosUIUnitsIndicator {
80                 public boolean hide(double v) { return v == AltosLib.MISSING; }
81                 public double value(AltosState state, int i) { return state.apogee_voltage; }
82                 public double good() { return AltosLib.ao_igniter_good; }
83
84                 public Apogee (Container container, int y) {
85                         super(container, 0, y, 3, AltosConvert.voltage, "Apogee Igniter Voltage", 1, true, 3);
86                 }
87         }
88
89         class Main extends AltosUIUnitsIndicator {
90                 public boolean hide(double v) { return v == AltosLib.MISSING; }
91                 public double value(AltosState state, int i) { return state.main_voltage; }
92                 public double good() { return AltosLib.ao_igniter_good; }
93
94                 public Main (Container container, int y) {
95                         super(container, 0, y, 3, AltosConvert.voltage, "Main Igniter Voltage", 1, true, 3);
96                 }
97         }
98
99         class Distance extends AltosUIUnitsIndicator {
100                 public double value(AltosState state, int i) {
101                         if (state.from_pad != null)
102                                 return state.from_pad.distance;
103                         else
104                                 return AltosLib.MISSING;
105                 }
106
107                 public Distance(Container container, int x, int y) {
108                         super(container, x, y, AltosConvert.distance, "Ground Distance");
109                 }
110         }
111
112         class Range extends AltosUIUnitsIndicator {
113                 public double value(AltosState state, int i) {
114                         return state.range;
115                 }
116                 public Range (Container container, int x, int y) {
117                         super (container, x, y, AltosConvert.distance, "Range");
118                 }
119         }
120
121         class Bearing extends AltosUIIndicator {
122                 public void show (AltosState state, AltosListenerState listener_state) {
123                         if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) {
124                                 show( String.format("%3.0f°", state.from_pad.bearing),
125                                       state.from_pad.bearing_words(
126                                               AltosGreatCircle.BEARING_LONG));
127                         } else {
128                                 show("Missing", "Missing");
129                         }
130                 }
131                 public Bearing (Container container, int x, int y) {
132                         super (container, x, y, 1, "Bearing", 2, false, 1, 2);
133                 }
134         }
135
136         class Elevation extends AltosUIIndicator {
137                 public void show (AltosState state, AltosListenerState listener_state) {
138                         if (state.elevation == AltosLib.MISSING)
139                                 show("Missing");
140                         else
141                                 show("%3.0f°", state.elevation);
142                 }
143                 public Elevation (Container container, int x, int y) {
144                         super (container, x, y, "Elevation", 1, false, 1);
145                 }
146         }
147
148         public String getName() {
149                 return "Descent";
150         }
151
152         public AltosDescent() {
153                 /* Elements in descent display */
154                 add(new Speed(this, 0, 0));
155                 add(new Height(this, 2, 0));
156                 add(new Elevation(this, 0, 1));
157                 add(new Range(this, 2, 1));
158                 add(new Bearing(this, 0, 2));
159                 add(new Distance(this, 0, 3));
160                 add(new Lat(this, 0, 4));
161                 add(new Lon(this, 2, 4));
162                 add(new Apogee(this, 5));
163                 add(new Main(this, 6));
164         }
165 }