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