package altosui;
import java.awt.*;
+import java.awt.event.*;
import javax.swing.*;
-import org.altusmetrum.altoslib_3.*;
+import org.altusmetrum.altoslib_4.*;
+import org.altusmetrum.altosuilib_2.*;
-public class AltosAscent extends JComponent implements AltosFlightDisplay {
+public class AltosAscent extends JComponent implements AltosFlightDisplay, HierarchyListener {
GridBagLayout layout;
JLabel cur, max;
- public class AscentStatus {
+ private AltosState last_state;
+ private AltosListenerState last_listener_state;
+
+ 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;
add(label);
value = new JTextField(Altos.text_width);
+ value.setEditable(false);
value.setFont(Altos.value_font);
value.setHorizontalAlignment(SwingConstants.RIGHT);
c.gridx = 2; c.gridy = y;
}
}
- 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;
add(label);
value = new JTextField(Altos.text_width);
+ value.setEditable(false);
value.setFont(Altos.value_font);
value.setHorizontalAlignment(SwingConstants.RIGHT);
c.gridx = 2; c.gridy = y;
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) {}
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) {
+ public void units_changed(boolean imperial_units) {
+ show(v, max);
+ }
+
+ void show(double v, double max) {
+ this.v = v;
+ this.max = max;
if (v == AltosLib.MISSING) {
value.setText("Missing");
- max_value.setText("Missing");
} else {
value.setText(units.show(8, v));
- if (v > max || max == AltosLib.MISSING) {
- max_value.setText(units.show(8, v));
- max = v;
- }
}
+ if (max == AltosLib.MISSING)
+ max_value.setText("Missing");
+ else
+ max_value.setText(units.show(8, max));
}
- 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;
add(label);
value = new JTextField(Altos.text_width);
+ value.setEditable(false);
value.setFont(Altos.value_font);
value.setHorizontalAlignment(SwingConstants.RIGHT);
c.gridx = 2; c.gridy = y;
add(value);
max_value = new JTextField(Altos.text_width);
+ max_value.setEditable(false);
max_value.setFont(Altos.value_font);
max_value.setHorizontalAlignment(SwingConstants.RIGHT);
c.gridx = 3; c.gridy = y;
}
}
-
class Height extends AscentValueHold {
void show (AltosState state, AltosListenerState listener_state) {
- show(AltosConvert.height, state.height());
+ show(state.height(), state.max_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(), state.max_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(), state.max_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(), state.max_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) {
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");
}
}
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");
}
}
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) {
+ if (!isShowing()) {
+ last_state = state;
+ last_listener_state = listener_state;
+ return;
+ }
+
if (state.gps != null && state.gps.connected) {
lat.show(state, listener_state);
lon.show(state, listener_state);
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) {
return "Ascent";
}
+ public void hierarchyChanged(HierarchyEvent e) {
+ if (last_state != null && isShowing()) {
+ AltosState state = last_state;
+ AltosListenerState listener_state = last_listener_state;
+
+ last_state = null;
+ last_listener_state = null;
+ show(state, listener_state);
+ }
+ }
+
public AltosAscent() {
layout = new GridBagLayout();
* 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++);
+ addHierarchyListener(this);
}
}