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