Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[fw/altos] / altosui / AltosAscent.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_12.*;
26 import org.altusmetrum.altosuilib_12.*;
27
28 public class AltosAscent extends AltosUIFlightTab {
29         JLabel  cur, max;
30
31         class Height extends AltosUIUnitsIndicator {
32
33                 public double value(AltosState state, int i) {
34                         if (i == 0)
35                                 return state.height();
36                         else
37                                 return state.max_height();
38                 }
39
40                 public Height(Container container, int y) {
41                         super(container, y, AltosConvert.height, "Height", 2, false, 1);
42                 }
43         }
44
45         class Speed extends AltosUIUnitsIndicator {
46                 public double value(AltosState state, int i) {
47                         if (i == 0)
48                                 return state.speed();
49                         else
50                                 return state.max_speed();
51                 }
52
53                 public Speed(Container container, int y) {
54                         super(container, y, AltosConvert.speed, "Speed", 2, false, 1);
55                 }
56         }
57
58         class Accel extends AltosUIUnitsIndicator {
59                 public boolean hide(double v) { return v == AltosLib.MISSING; }
60
61                 public double value(AltosState state, int i) {
62                         if (i == 0)
63                                 return state.acceleration();
64                         else
65                                 return state.max_acceleration();
66                 }
67
68                 public Accel(Container container, int y) {
69                         super(container, y, AltosConvert.accel, "Acceleration", 2, false, 1);
70                 }
71         }
72
73         class Orient extends AltosUIUnitsIndicator {
74
75                 public boolean hide(double v) { return v == AltosLib.MISSING; }
76
77                 public double value(AltosState state, int i) {
78                         if (i == 0)
79                                 return state.orient();
80                         else
81                                 return state.max_orient();
82                 }
83
84                 public Orient(Container container, int y) {
85                         super(container, y, AltosConvert.orient, "Tilt Angle", 2, false, 1);
86                 }
87
88         }
89
90         class Apogee extends AltosUIUnitsIndicator {
91
92                 public double value(AltosState state, int i) {
93                         return state.apogee_voltage;
94                 }
95
96                 public boolean good(double v) { return v >= AltosLib.ao_igniter_good; }
97                 public boolean hide(double v) { return v == AltosLib.MISSING; }
98
99                 public Apogee (Container container, int y) {
100                         super(container, y, AltosConvert.voltage, "Apogee Igniter Voltage", 1, true, 2);
101                 }
102         }
103
104         class Main extends AltosUIUnitsIndicator {
105                 public double value(AltosState state, int i) {
106                         return state.main_voltage;
107                 }
108
109                 public boolean good(double v) { return v >= AltosLib.ao_igniter_good; }
110                 public boolean hide(double v) { return v == AltosLib.MISSING; }
111
112                 public Main (Container container, int y) {
113                         super(container, y, AltosConvert.voltage, "Main Igniter Voltage", 1, true, 2);
114                 }
115         }
116
117         class Lat extends AltosUIUnitsIndicator {
118
119                 public boolean hide(AltosState state, int i) {
120                         return state.gps == null || !state.gps.connected;
121                 }
122
123                 public double value(AltosState state, int i) {
124                         if (state.gps == null)
125                                 return AltosLib.MISSING;
126                         if (!state.gps.connected)
127                                 return AltosLib.MISSING;
128                         return state.gps.lat;
129                 }
130
131                 Lat (Container container, int y) {
132                         super (container, y, AltosConvert.latitude, "Latitude", 1, false, 2);
133                 }
134         }
135
136         class Lon extends AltosUIUnitsIndicator {
137
138                 public boolean hide(AltosState state, int i) {
139                         return state.gps == null || !state.gps.connected;
140                 }
141
142                 public double value(AltosState state, int i) {
143                         if (state.gps == null)
144                                 return AltosLib.MISSING;
145                         if (!state.gps.connected)
146                                 return AltosLib.MISSING;
147                         return state.gps.lon;
148                 }
149
150                 Lon (Container container, int y) {
151                         super (container, y, AltosConvert.longitude, "Longitude", 1, false, 2);
152                 }
153         }
154
155         public void font_size_changed(int font_size) {
156                 super.font_size_changed(font_size);
157                 cur.setFont(AltosUILib.label_font);
158                 max.setFont(AltosUILib.label_font);
159         }
160
161         public void labels(GridBagLayout layout, int y) {
162                 GridBagConstraints      c;
163
164                 cur = new JLabel("Current");
165                 cur.setFont(AltosUILib.label_font);
166                 c = new GridBagConstraints();
167                 c.gridx = 2; c.gridy = y;
168                 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
169                 layout.setConstraints(cur, c);
170                 add(cur);
171
172                 max = new JLabel("Maximum");
173                 max.setFont(AltosUILib.label_font);
174                 c.gridx = 3; c.gridy = y;
175                 layout.setConstraints(max, c);
176                 add(max);
177         }
178
179         public String getName() {
180                 return "Ascent";
181         }
182
183         public AltosAscent() {
184                 int y = 0;
185                 labels(layout, y++);
186                 add(new Height(this, y++));
187                 add(new Speed(this, y++));
188                 add(new Accel(this, y++));
189                 add(new Orient(this, y++));
190                 add(new Lat(this, y++));
191                 add(new Lon(this, y++));
192                 add(new Apogee(this, y++));
193                 add(new Main(this, y++));
194         }
195 }