import java.awt.*;
import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_4.*;
+import org.altusmetrum.altosuilib_2.*;
public class AltosAscent extends JComponent implements AltosFlightDisplay {
GridBagLayout layout;
JLabel cur, max;
- public class AscentStatus {
+ public class AscentStatus implements AltosFontListener, AltosUnitsListener {
JLabel label;
JTextField value;
AltosLights lights;
+ double v;
+ AltosUnits units;
void show() {
value.setVisible(true);
show();
value.setText(s);
}
-
- void show(AltosUnits units, double v) {
+
+ void show(double v) {
+ this.v = v;
show(units.show(8, v));
}
lights.set(false);
}
- void set_font() {
+ public void font_size_changed(int font_size) {
label.setFont(Altos.label_font);
value.setFont(Altos.value_font);
}
- public AscentStatus (GridBagLayout layout, int y, String text) {
+ public void units_changed(boolean imperial_units) {
+ if (units != null)
+ show(v);
+ }
+
+ public AscentStatus (GridBagLayout layout, int y, AltosUnits units, String text) {
+ this.units = units;
GridBagConstraints c = new GridBagConstraints();
c.weighty = 1;
}
}
- public class AscentValue {
+ public abstract class AscentValue implements AltosFontListener, AltosUnitsListener {
JLabel label;
JTextField value;
- void show(AltosState state, AltosListenerState listener_state) {}
+ double v;
+ AltosUnits units;
+
+ abstract void show(AltosState state, AltosListenerState listener_state);
void reset() {
value.setText("");
show();
value.setText(s);
}
-
- void show(AltosUnits units, double v) {
+
+ void show(double v) {
+ this.v = v;
show(units.show(8, v));
}
label.setVisible(false);
value.setVisible(false);
}
- void set_font() {
+
+ public void font_size_changed(int font_size) {
label.setFont(Altos.label_font);
value.setFont(Altos.value_font);
}
- public AscentValue (GridBagLayout layout, int y, String text) {
+ public void units_changed(boolean imperial_units) {
+ if (units != null)
+ show(v);
+ }
+
+ public AscentValue (GridBagLayout layout, int y, AltosUnits units, String text) {
GridBagConstraints c = new GridBagConstraints();
c.weighty = 1;
layout.setConstraints(value, c);
add(value);
}
+
+ public AscentValue (GridBagLayout layout, int y, String text) {
+ this(layout, y, null, text);
+ }
}
- public class AscentValueHold {
+ public class AscentValueHold implements AltosFontListener, AltosUnitsListener {
JLabel label;
JTextField value;
JTextField max_value;
double max;
+ AltosUnits units;
+ double v;
void show(AltosState state, AltosListenerState listener_state) {}
void reset() {
value.setText("");
max_value.setText("");
- max = AltosRecord.MISSING;
+ max = AltosLib.MISSING;
}
- void set_font() {
+ public void font_size_changed(int font_size) {
label.setFont(Altos.label_font);
value.setFont(Altos.value_font);
max_value.setFont(Altos.value_font);
}
- void show(AltosUnits units, double v) {
- if (v == AltosRecord.MISSING) {
+ public void units_changed(boolean imperial_units) {
+ show(v);
+ }
+
+ void show(double v) {
+ this.v = v;
+ if (v == AltosLib.MISSING) {
value.setText("Missing");
- max_value.setText("Missing");
} else {
value.setText(units.show(8, v));
- if (v > max || max == AltosRecord.MISSING) {
- max_value.setText(units.show(8, v));
+ if (v > max || max == AltosLib.MISSING)
max = v;
- }
}
+ if (max == AltosLib.MISSING)
+ max_value.setText("Missing");
+ else
+ max_value.setText(units.show(8, v));
}
- public AscentValueHold (GridBagLayout layout, int y, String text) {
+
+ void hide() {
+ label.setVisible(false);
+ value.setVisible(false);
+ max_value.setVisible(false);
+ }
+
+ public AscentValueHold (GridBagLayout layout, int y, AltosUnits units, String text) {
+ this.units = units;
GridBagConstraints c = new GridBagConstraints();
c.weighty = 1;
}
}
-
class Height extends AscentValueHold {
void show (AltosState state, AltosListenerState listener_state) {
- show(AltosConvert.height, state.height);
+ show(state.height());
}
public Height (GridBagLayout layout, int y) {
- super (layout, y, "Height");
+ super (layout, y, AltosConvert.height, "Height");
}
}
class Speed extends AscentValueHold {
void show (AltosState state, AltosListenerState listener_state) {
- show(AltosConvert.speed, state.speed);
+ show(state.speed());
}
public Speed (GridBagLayout layout, int y) {
- super (layout, y, "Speed");
+ super (layout, y, AltosConvert.speed, "Speed");
}
}
class Accel extends AscentValueHold {
void show (AltosState state, AltosListenerState listener_state) {
- show(AltosConvert.accel, state.acceleration);
+ show(state.acceleration());
}
public Accel (GridBagLayout layout, int y) {
- super (layout, y, "Acceleration");
+ super (layout, y, AltosConvert.accel, "Acceleration");
}
}
Accel accel;
+ class Orient extends AscentValueHold {
+ void show (AltosState state, AltosListenerState listener_state) {
+ show(state.orient());
+ }
+ public Orient (GridBagLayout layout, int y) {
+ super (layout, y, AltosConvert.orient, "Tilt Angle");
+ }
+ }
+
+ Orient orient;
+
String pos(double p, String pos, String neg) {
String h = pos;
if (p < 0) {
class Apogee extends AscentStatus {
void show (AltosState state, AltosListenerState listener_state) {
show("%4.2f V", state.apogee_voltage);
- lights.set(state.apogee_voltage > 3.7);
+ lights.set(state.apogee_voltage >= AltosLib.ao_igniter_good);
}
public Apogee (GridBagLayout layout, int y) {
- super(layout, y, "Apogee Igniter Voltage");
+ super(layout, y, null, "Apogee Igniter Voltage");
}
}
class Main extends AscentStatus {
void show (AltosState state, AltosListenerState listener_state) {
show("%4.2f V", state.main_voltage);
- lights.set(state.main_voltage > 3.7);
+ lights.set(state.main_voltage >= AltosLib.ao_igniter_good);
}
public Main (GridBagLayout layout, int y) {
- super(layout, y, "Main Igniter Voltage");
+ super(layout, y, null, "Main Igniter Voltage");
}
}
class Lat extends AscentValue {
void show (AltosState state, AltosListenerState listener_state) {
- if (state.gps != null)
+ if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING)
show(pos(state.gps.lat,"N", "S"));
else
show("???");
class Lon extends AscentValue {
void show (AltosState state, AltosListenerState listener_state) {
- if (state.gps != null)
+ if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING)
show(pos(state.gps.lon,"E", "W"));
else
show("???");
height.reset();
speed.reset();
accel.reset();
+ orient.reset();
}
- public void set_font() {
+ public void font_size_changed(int font_size) {
cur.setFont(Altos.label_font);
max.setFont(Altos.label_font);
- lat.set_font();
- lon.set_font();
- main.set_font();
- apogee.set_font();
- height.set_font();
- speed.set_font();
- accel.set_font();
+ lat.font_size_changed(font_size);
+ lon.font_size_changed(font_size);
+ main.font_size_changed(font_size);
+ apogee.font_size_changed(font_size);
+ height.font_size_changed(font_size);
+ speed.font_size_changed(font_size);
+ accel.font_size_changed(font_size);
+ orient.font_size_changed(font_size);
+ }
+
+ public void units_changed(boolean imperial_units) {
+ lat.units_changed(imperial_units);
+ lon.units_changed(imperial_units);
+ main.units_changed(imperial_units);
+ apogee.units_changed(imperial_units);
+ height.units_changed(imperial_units);
+ speed.units_changed(imperial_units);
+ accel.units_changed(imperial_units);
+ orient.units_changed(imperial_units);
}
public void show(AltosState state, AltosListenerState listener_state) {
lon.hide();
}
height.show(state, listener_state);
- if (state.main_voltage != AltosRecord.MISSING)
+ if (state.main_voltage != AltosLib.MISSING)
main.show(state, listener_state);
else
main.hide();
- if (state.apogee_voltage != AltosRecord.MISSING)
+ if (state.apogee_voltage != AltosLib.MISSING)
apogee.show(state, listener_state);
else
apogee.hide();
speed.show(state, listener_state);
accel.show(state, listener_state);
+ if (state.orient() != AltosLib.MISSING)
+ orient.show(state, listener_state);
+ else
+ orient.hide();
}
public void labels(GridBagLayout layout, int y) {
* lon
* height
*/
- labels(layout, 0);
- height = new Height(layout, 1);
- speed = new Speed(layout, 2);
- accel = new Accel(layout, 3);
- lat = new Lat(layout, 4);
- lon = new Lon(layout, 5);
- apogee = new Apogee(layout, 6);
- main = new Main(layout, 7);
+ int y = 0;
+ labels(layout, y++);
+ height = new Height(layout, y++);
+ speed = new Speed(layout, y++);
+ accel = new Accel(layout, y++);
+ orient = new Orient(layout, y++);
+ lat = new Lat(layout, y++);
+ lon = new Lon(layout, y++);
+ apogee = new Apogee(layout, y++);
+ main = new Main(layout, y++);
}
}