import java.awt.event.*;
import javax.swing.*;
import java.io.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_4.*;
+import org.altusmetrum.altosuilib_2.*;
public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener {
GridBagLayout layout;
- public class LandedValue {
+ public abstract class LandedValue implements AltosFontListener, AltosUnitsListener {
JLabel label;
JTextField value;
- void show(AltosState state, AltosListenerState listener_state) {}
+ AltosUnits units;
+ double v;
+
+ 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));
}
show(String.format(format, v));
}
- public void set_font() {
+ public void font_size_changed(int font_size) {
label.setFont(Altos.label_font);
value.setFont(Altos.value_font);
}
+ public void units_changed(boolean imperial_units) {
+ if (units != null)
+ show(v);
+ }
+
void hide() {
label.setVisible(false);
value.setVisible(false);
}
- public LandedValue (GridBagLayout layout, int y, String text) {
+ public LandedValue (GridBagLayout layout, int y, AltosUnits units, String text) {
+ this.units = units;
+
GridBagConstraints c = new GridBagConstraints();
c.weighty = 1;
layout.setConstraints(value, c);
add(value);
}
+
+ public LandedValue (GridBagLayout layout, int y, String text) {
+ this(layout, y, null, text);
+ }
}
String pos(double p, String pos, String neg) {
class Lat extends LandedValue {
void show (AltosState state, AltosListenerState listener_state) {
- if (state.gps != null && state.gps.connected)
+ show();
+ if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING)
show(pos(state.gps.lat,"N", "S"));
else
show("???");
class Lon extends LandedValue {
void show (AltosState state, AltosListenerState listener_state) {
show();
- if (state.gps != null && state.gps.connected)
+ if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING)
show(pos(state.gps.lon,"E", "W"));
else
show("???");
void show (AltosState state, AltosListenerState listener_state) {
show();
if (state.from_pad != null)
- show(AltosConvert.distance, state.from_pad.distance);
+ show(state.from_pad.distance);
else
show("???");
}
public Distance (GridBagLayout layout, int y) {
- super (layout, y, "Distance");
+ super (layout, y, AltosConvert.distance, "Distance");
}
}
class Height extends LandedValue {
void show (AltosState state, AltosListenerState listener_state) {
- show(AltosConvert.height, state.max_height);
+ show(state.max_height());
}
public Height (GridBagLayout layout, int y) {
- super (layout, y, "Maximum Height");
+ super (layout, y, AltosConvert.height, "Maximum Height");
}
}
class Speed extends LandedValue {
void show (AltosState state, AltosListenerState listener_state) {
- show(AltosConvert.speed, state.max_speed());
+ show(state.max_speed());
}
public Speed (GridBagLayout layout, int y) {
- super (layout, y, "Maximum Speed");
+ super (layout, y, AltosConvert.speed, "Maximum Speed");
}
}
class Accel extends LandedValue {
void show (AltosState state, AltosListenerState listener_state) {
- show(AltosConvert.accel, state.max_acceleration);
+ show(state.max_acceleration());
}
public Accel (GridBagLayout layout, int y) {
- super (layout, y, "Maximum Acceleration");
+ super (layout, y, AltosConvert.accel, "Maximum Acceleration");
}
}
accel.reset();
}
- public void set_font() {
- lat.set_font();
- lon.set_font();
- bearing.set_font();
- distance.set_font();
- height.set_font();
- speed.set_font();
- accel.set_font();
+ public void font_size_changed(int font_size) {
+ lat.font_size_changed(font_size);
+ lon.font_size_changed(font_size);
+ bearing.font_size_changed(font_size);
+ distance.font_size_changed(font_size);
+ height.font_size_changed(font_size);
+ speed.font_size_changed(font_size);
+ accel.font_size_changed(font_size);
+ }
+
+ public void units_changed(boolean imperial_units) {
+ lat.units_changed(imperial_units);
+ lon.units_changed(imperial_units);
+ bearing.units_changed(imperial_units);
+ distance.units_changed(imperial_units);
+ height.units_changed(imperial_units);
+ speed.units_changed(imperial_units);
+ accel.units_changed(imperial_units);
}
public void show(AltosState state, AltosListenerState listener_state) {
states = new AltosEepromFile(in);
} else if (filename.endsWith("telem")) {
FileInputStream in = new FileInputStream(file);
- states = null; // new AltosTelemetryIterable(in);
+ states = new AltosTelemetryFile(in);
} else {
throw new FileNotFoundException(filename);
}