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);
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("");
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) {}
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);
+ }
+
+ 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 == AltosLib.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));
}
void hide() {
max_value.setVisible(false);
}
- public AscentValueHold (GridBagLayout layout, int y, String text) {
+ 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");
}
}
class Orient extends AscentValueHold {
void show (AltosState state, AltosListenerState listener_state) {
- show(AltosConvert.orient, state.orient());
+ show(state.orient());
}
public Orient (GridBagLayout layout, int y) {
- super (layout, y, "Tilt Angle");
+ super (layout, y, AltosConvert.orient, "Tilt Angle");
}
}
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");
}
}
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();
- orient.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) {
return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10;
}
- public void set_font() {
+ public void font_size_changed(int font_size) {
setFont(Altos.table_value_font);
setRowHeight(desired_row_height());
doLayout();
}
+ public void units_changed(boolean imperial_units) {
+ }
+
public AltosCompanionInfo() {
super(new AltosFlightInfoTableModel(info_rows, info_columns));
model = (AltosFlightInfoTableModel) getModel();
setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
setShowGrid(true);
- set_font();
+ font_size_changed(AltosUIPreferences.font_size());
}
public Dimension getPreferredScrollableViewportSize() {
public class AltosDescent extends JComponent implements AltosFlightDisplay {
GridBagLayout layout;
- public abstract class DescentStatus {
+ public abstract class DescentStatus implements AltosFontListener, AltosUnitsListener {
JLabel label;
JTextField value;
AltosLights lights;
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 void units_changed(boolean imperial_units) {
+ }
+
public DescentStatus (GridBagLayout layout, int y, String text) {
GridBagConstraints c = new GridBagConstraints();
c.weighty = 1;
}
}
- public abstract class DescentValue {
+ public abstract class DescentValue implements AltosFontListener, AltosUnitsListener {
JLabel label;
JTextField value;
+ AltosUnits units;
+ double v;
void reset() {
value.setText("");
value.setText(v);
}
- void show(AltosUnits units, double v) {
+ void show(double v) {
+ this.v = v;
show(units.show(8, v));
}
show(String.format(format, v));
}
- void set_font() {
+ public void font_size_changed(int font_size) {
label.setFont(Altos.label_font);
value.setFont(Altos.value_font);
}
- public DescentValue (GridBagLayout layout, int x, int y, String text) {
+ public void units_changed(boolean imperial_units) {
+ if (units != null)
+ show(v);
+ }
+
+ public DescentValue (GridBagLayout layout, int x, int y, AltosUnits units, String text) {
+ this.units = units;
GridBagConstraints c = new GridBagConstraints();
c.weighty = 1;
c.weightx = 1;
add(value, c);
}
+
+ public DescentValue (GridBagLayout layout, int x, int y, String text) {
+ this(layout, x, y, null, text);
+ }
}
- public abstract class DescentDualValue {
+ public abstract class DescentDualValue implements AltosFontListener, AltosUnitsListener {
JLabel label;
JTextField value1;
JTextField value2;
value2.setVisible(false);
}
- void set_font() {
+ public void font_size_changed(int font_size) {
label.setFont(Altos.label_font);
value1.setFont(Altos.value_font);
value2.setFont(Altos.value_font);
}
+ public void units_changed(boolean imperial_units) {
+ }
+
abstract void show(AltosState state, AltosListenerState listener_state);
void show(String v1, String v2) {
class Height extends DescentValue {
void show (AltosState state, AltosListenerState listener_state) {
- show(AltosConvert.height, state.height());
+ show(state.height());
}
public Height (GridBagLayout layout, int x, int y) {
- super (layout, x, y, "Height");
+ super (layout, x, y, AltosConvert.height, "Height");
}
}
class Speed extends DescentValue {
void show (AltosState state, AltosListenerState listener_state) {
- show(AltosConvert.speed, state.speed());
+ show(state.speed());
}
public Speed (GridBagLayout layout, int x, int y) {
- super (layout, x, y, "Speed");
+ super (layout, x, y, AltosConvert.speed, "Speed");
}
}
class Distance extends DescentValue {
void show(AltosState state, AltosListenerState listener_state) {
if (state.from_pad != null)
- show(AltosConvert.distance, state.from_pad.distance);
+ show(state.from_pad.distance);
else
show("???");
}
public Distance (GridBagLayout layout, int x, int y) {
- super(layout, x, y, "Ground Distance");
+ super(layout, x, y, AltosConvert.distance, "Ground Distance");
}
}
class Range extends DescentValue {
void show (AltosState state, AltosListenerState listener_state) {
- show(AltosConvert.distance, state.range);
+ show(state.range);
}
public Range (GridBagLayout layout, int x, int y) {
- super (layout, x, y, "Range");
+ super (layout, x, y, AltosConvert.distance, "Range");
}
}
apogee.reset();
}
- public void set_font() {
- lat.set_font();
- lon.set_font();
- height.set_font();
- speed.set_font();
- bearing.set_font();
- range.set_font();
- distance.set_font();
- elevation.set_font();
- main.set_font();
- apogee.set_font();
+ public void font_size_changed(int font_size) {
+ lat.font_size_changed(font_size);
+ lon.font_size_changed(font_size);
+ height.font_size_changed(font_size);
+ speed.font_size_changed(font_size);
+ bearing.font_size_changed(font_size);
+ range.font_size_changed(font_size);
+ distance.font_size_changed(font_size);
+ elevation.font_size_changed(font_size);
+ main.font_size_changed(font_size);
+ apogee.font_size_changed(font_size);
+ }
+
+ public void units_changed(boolean imperial_units) {
+ lat.units_changed(imperial_units);
+ lon.units_changed(imperial_units);
+ height.units_changed(imperial_units);
+ speed.units_changed(imperial_units);
+ bearing.units_changed(imperial_units);
+ range.units_changed(imperial_units);
+ distance.units_changed(imperial_units);
+ elevation.units_changed(imperial_units);
+ main.units_changed(imperial_units);
+ apogee.units_changed(imperial_units);
}
public void show(AltosState state, AltosListenerState listener_state) {
last_packet.reset();
}
- public void set_font () {
+ public void font_size_changed(int font_size) {
call.set_font();
serial.set_font();
flight.set_font();
last_packet.set_font();
}
+ public void units_changed(boolean imperial_units) {
+ }
+
public void show (AltosState state, AltosListenerState listener_state) {
call.show(state, listener_state);
serial.show(state, listener_state);
import org.altusmetrum.altoslib_4.*;
import org.altusmetrum.altosuilib_2.*;
-public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener {
+public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
AltosVoice voice;
AltosFlightReader reader;
AltosDisplayThread thread;
sitemap.reset();
}
- public void set_font() {
- pad.set_font();
- ignitor.set_font();
- ascent.set_font();
- descent.set_font();
- landed.set_font();
- flightStatus.set_font();
- flightInfo.set_font();
- sitemap.set_font();
- companion.set_font();
- }
-
public void font_size_changed(int font_size) {
- set_font();
+ pad.font_size_changed(font_size);
+ ignitor.font_size_changed(font_size);
+ ascent.font_size_changed(font_size);
+ descent.font_size_changed(font_size);
+ landed.font_size_changed(font_size);
+ flightStatus.font_size_changed(font_size);
+ flightInfo.font_size_changed(font_size);
+ sitemap.font_size_changed(font_size);
+ companion.font_size_changed(font_size);
}
+ public void units_changed(boolean imperial_units) {
+ pad.units_changed(imperial_units);
+ ignitor.units_changed(imperial_units);
+ ascent.units_changed(imperial_units);
+ descent.units_changed(imperial_units);
+ landed.units_changed(imperial_units);
+ flightStatus.units_changed(imperial_units);
+ flightInfo.units_changed(imperial_units);
+ sitemap.units_changed(imperial_units);
+ companion.units_changed(imperial_units);
+ }
AltosFlightStatusUpdate status_update;
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
AltosUIPreferences.register_font_listener(this);
+ AltosPreferences.register_units_listener(this);
addWindowListener(new WindowAdapter() {
@Override
setVisible(false);
dispose();
AltosUIPreferences.unregister_font_listener(AltosFlightUI.this);
+ AltosPreferences.unregister_units_listener(AltosFlightUI.this);
if (exit_on_close)
System.exit(0);
}
import org.altusmetrum.altoslib_4.*;
import org.altusmetrum.altosuilib_2.*;
-public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener, AltosIdleMonitorListener, DocumentListener {
+public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDisplay, AltosIdleMonitorListener, DocumentListener {
AltosDevice device;
JTabbedPane pane;
AltosPad pad;
flightInfo.clear();
}
- public void set_font() {
- pad.set_font();
- flightInfo.set_font();
+ public void font_size_changed(int font_size) {
+ pad.font_size_changed(font_size);
+ flightInfo.font_size_changed(font_size);
}
- public void font_size_changed(int font_size) {
- set_font();
+ public void units_changed(boolean imperial_units) {
+ pad.units_changed(imperial_units);
+ flightInfo.units_changed(imperial_units);
}
AltosFlightStatusUpdate status_update;
disconnect();
} catch (Exception ex) {
System.out.printf("Exception %s\n", ex.toString());
- for (StackTraceElement e : ex.getStackTrace())
- System.out.printf("%s\n", e.toString());
+ for (StackTraceElement el : ex.getStackTrace())
+ System.out.printf("%s\n", el.toString());
}
setVisible(false);
dispose();
public class AltosIgnitor extends JComponent implements AltosFlightDisplay {
GridBagLayout layout;
- public class LaunchStatus {
+ public class LaunchStatus implements AltosFontListener, AltosUnitsListener {
JLabel label;
JTextField value;
AltosLights lights;
hide();
}
- 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) {
+ }
+
public void set_label(String text) {
label.setText(text);
}
ignitors[i].reset();
}
- public void set_font() {
+ public void font_size_changed(int font_size) {
if (ignitors == null)
return;
for (int i = 0; i < ignitors.length; i++)
- ignitors[i].set_font();
+ ignitors[i].font_size_changed(font_size);
+ }
+
+ public void units_changed(boolean imperial_units) {
}
public void show(AltosState state, AltosListenerState listener_state) {
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("");
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) {
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) {
public class AltosPad extends JComponent implements AltosFlightDisplay {
GridBagLayout layout;
- public class LaunchStatus {
+ public class LaunchStatus implements AltosFontListener, AltosUnitsListener {
JLabel label;
JTextField value;
AltosLights lights;
lights.setVisible(false);
}
- 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) {
+ }
+
public void set_label(String text) {
label.setText(text);
}
}
}
- public class LaunchValue {
+ public abstract class LaunchValue 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 show() {
label.setVisible(true);
value.setVisible(false);
}
- 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 show(String s) {
show();
value.setText(s);
}
- void show(AltosUnits units, double v) {
+ void show(double v) {
+ this.v = v;
show(units.show(8, v));
}
value.setText("");
}
- public LaunchValue (GridBagLayout layout, int y, String text) {
+ public LaunchValue (GridBagLayout layout, int y, AltosUnits units, String text) {
+ this.units = units;
+
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
c.weighty = 1;
layout.setConstraints(value, c);
add(value);
}
+
+ public LaunchValue (GridBagLayout layout, int y, String text) {
+ this(layout, y, null, text);
+ }
}
class Battery extends LaunchStatus {
}
}
if (alt != AltosLib.MISSING) {
- show("%4.0f m", state.gps.alt);
+ show(alt);
set_label(label);
} else
hide();
}
public PadAlt (GridBagLayout layout, int y) {
- super (layout, y, "Pad Altitude");
+ super (layout, y, AltosConvert.height, "Pad Altitude");
}
}
pad_alt.reset();
}
- public void set_font() {
- battery.set_font();
- apogee.set_font();
- main.set_font();
- logging_ready.set_font();
- gps_locked.set_font();
- gps_ready.set_font();
- receiver_battery.set_font();
- pad_lat.set_font();
- pad_lon.set_font();
- pad_alt.set_font();
+ public void font_size_changed(int font_size) {
+ battery.font_size_changed(font_size);
+ apogee.font_size_changed(font_size);
+ main.font_size_changed(font_size);
+ logging_ready.font_size_changed(font_size);
+ gps_locked.font_size_changed(font_size);
+ gps_ready.font_size_changed(font_size);
+ receiver_battery.font_size_changed(font_size);
+ pad_lat.font_size_changed(font_size);
+ pad_lon.font_size_changed(font_size);
+ pad_alt.font_size_changed(font_size);
+ }
+
+ public void units_changed(boolean imperial_units) {
+ battery.units_changed(imperial_units);
+ apogee.units_changed(imperial_units);
+ main.units_changed(imperial_units);
+ logging_ready.units_changed(imperial_units);
+ gps_locked.units_changed(imperial_units);
+ gps_ready.units_changed(imperial_units);
+ receiver_battery.units_changed(imperial_units);
+ pad_lat.units_changed(imperial_units);
+ pad_lon.units_changed(imperial_units);
+ pad_alt.units_changed(imperial_units);
}
public void show(AltosState state, AltosListenerState listener_state) {
import org.altusmetrum.altoslib_4.*;
-public interface AltosFlightDisplay {
+public interface AltosFlightDisplay extends AltosUnitsListener, AltosFontListener {
void reset();
void show(AltosState state, AltosListenerState listener_state);
-
- void set_font();
}
doLayout();
}
- public void set_font() {
+ public void font_size_changed(int font_size) {
setFont(AltosUILib.table_value_font);
set_layout();
doLayout();
}
+ public void units_changed(boolean imperial_units) {
+ }
+
public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
}
// nothing
}
- public void set_font() {
+ public void font_size_changed(int font_size) {
for (AltosSiteMapTile tile : mapTiles.values())
tile.set_font(AltosUILib.value_font);
}
+ public void units_changed(boolean imperial_units) {
+ set_line();
+ }
+
static final int load_mode_cached = 1;
static final int load_mode_uncached = 2;
import org.altusmetrum.altoslib_4.*;
import org.altusmetrum.altosuilib_2.*;
-public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener, ActionListener {
+public class TeleGPS
+ extends AltosUIFrame
+ implements AltosFlightDisplay, AltosFontListener, AltosUnitsListener, ActionListener
+{
static String[] telegps_icon_names = {
"/telegps-16.png",
display.reset();
}
- public void set_font() {
+ public void font_size_changed(int font_size) {
for (AltosFlightDisplay display : displays)
- display.set_font();
+ display.font_size_changed(font_size);
}
- public void font_size_changed(int font_size) {
- set_font();
+ public void units_changed(boolean imperial_units) {
+ for (AltosFlightDisplay display : displays)
+ display.units_changed(imperial_units);
}
public void show(AltosState state, AltosListenerState listener_state) {
private void close() {
AltosUIPreferences.unregister_font_listener(this);
+ AltosPreferences.unregister_units_listener(this);
setVisible(false);
dispose();
--number_of_windows;
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
AltosUIPreferences.register_font_listener(this);
+ AltosPreferences.register_units_listener(this);
addWindowListener(new WindowAdapter() {
@Override
GridBagLayout layout;
JLabel cur, max;
- public class Info {
+ public abstract class Info implements AltosFontListener, AltosUnitsListener {
JLabel label;
JTextField value;
AltosLights lights;
+ double v;
+ AltosUnits units;
void show() {
value.setVisible(true);
label.setVisible(false);
}
- void show(AltosState state, AltosListenerState listener_state) {}
+ abstract void show(AltosState state, AltosListenerState listener_state);
void show(String s) {
show();
value.setText(s);
}
- void show(AltosUnits units, double v) {
+ void show(double v) {
+ this.v = v;
show(units.show(8, v));
}
value.setText("");
}
- void set_font() {
+ public void font_size_changed(int font_size) {
label.setFont(AltosUILib.label_font);
value.setFont(AltosUILib.value_font);
}
- public Info (GridBagLayout layout, int y, String text) {
+ public void units_changed(boolean imperial_units) {
+ if (units != null)
+ show(v);
+ }
+
+ public Info (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 Info (GridBagLayout layout, int y, String text) {
+ this(layout, y, null, text);
+ }
}
- public class Value {
+ public abstract class Value implements AltosFontListener, AltosUnitsListener {
JLabel label;
JTextField value;
- void show(AltosState state, AltosListenerState listener_state) {}
+ AltosUnits units;
+ double v = AltosLib.MISSING;
+
+ abstract void show(AltosState state, AltosListenerState listener_state);
void reset() {
value.setText("");
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(AltosUILib.label_font);
value.setFont(AltosUILib.value_font);
}
+ public void units_changed(boolean imperial_units) {
+ if (units != null)
+ show(v);
+ }
public Value (GridBagLayout layout, int y, String text) {
GridBagConstraints c = new GridBagConstraints();
}
}
- public abstract class DualValue {
+ public abstract class DualValue implements AltosFontListener, AltosUnitsListener {
+ AltosLights lights;
JLabel label;
JTextField value1;
JTextField value2;
void reset() {
+ if (lights != null)
+ lights.set(false);
value1.setText("");
value2.setText("");
}
void show() {
+ if (lights != null)
+ lights.setVisible(true);
label.setVisible(true);
value1.setVisible(true);
value2.setVisible(true);
}
void hide() {
+ if (lights != null)
+ lights.setVisible(false);
label.setVisible(false);
value1.setVisible(false);
value2.setVisible(false);
}
- void set_font() {
+ public void font_size_changed(int font_size) {
label.setFont(AltosUILib.label_font);
value1.setFont(AltosUILib.value_font);
value2.setFont(AltosUILib.value_font);
}
+ public void units_changed(boolean imperial_units) {
+ }
+
abstract void show(AltosState state, AltosListenerState listener_state);
void show(String v1, String v2) {
value1.setText(v1);
value2.setText(v2);
}
+
void show(String f1, double v1, String f2, double v2) {
show();
value1.setText(String.format(f1, v1));
value2.setText(String.format(f2, v2));
}
- public DualValue (GridBagLayout layout, int x, int y, String text) {
+ void show(String f1, int v1, String f2, int v2) {
+ show();
+ value1.setText(String.format(f1, v1));
+ value2.setText(String.format(f2, v2));
+ }
+
+ public DualValue (GridBagLayout layout, int y, String text, boolean want_lights) {
GridBagConstraints c = new GridBagConstraints();
c.weighty = 1;
+ if (want_lights) {
+ lights = new AltosLights();
+ c.gridx = 0; c.gridy = y;
+ c.anchor = GridBagConstraints.CENTER;
+ c.fill = GridBagConstraints.VERTICAL;
+ c.weightx = 0;
+ layout.setConstraints(lights, c);
+ add(lights);
+ }
+
label = new JLabel(text);
label.setFont(AltosUILib.label_font);
label.setHorizontalAlignment(SwingConstants.LEFT);
- c.gridx = x + 1; c.gridy = y;
+ c.gridx = 1; c.gridy = y;
c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
c.anchor = GridBagConstraints.WEST;
c.fill = GridBagConstraints.VERTICAL;
value1 = new JTextField(AltosUILib.text_width);
value1.setFont(AltosUILib.value_font);
value1.setHorizontalAlignment(SwingConstants.RIGHT);
- c.gridx = x + 2; c.gridy = y;
+ c.gridx = 2; c.gridy = y;
c.anchor = GridBagConstraints.WEST;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
value2 = new JTextField(AltosUILib.text_width);
value2.setFont(AltosUILib.value_font);
value2.setHorizontalAlignment(SwingConstants.RIGHT);
- c.gridx = x + 3; c.gridy = y;
+ c.gridx = 3; c.gridy = y;
c.anchor = GridBagConstraints.WEST;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
}
}
- public class ValueHold {
+ abstract public class ValueHold implements AltosFontListener, AltosUnitsListener {
JLabel label;
JTextField value;
JTextField max_value;
+ double v;
double max;
+ AltosUnits units;
- void show(AltosState state, AltosListenerState listener_state) {}
+ abstract void show(AltosState state, AltosListenerState listener_state);
void reset() {
value.setText("");
max = AltosLib.MISSING;
}
- void set_font() {
+ public void font_size_changed(int font_size) {
label.setFont(AltosUILib.label_font);
value.setFont(AltosUILib.value_font);
max_value.setFont(AltosUILib.value_font);
}
- void show(AltosUnits units, double v) {
+ 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 == AltosLib.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, max));
}
void hide() {
max_value.setVisible(false);
}
- public ValueHold (GridBagLayout layout, int y, String text) {
+ public ValueHold (GridBagLayout layout, int y, AltosUnits units, String text) {
+ this.units = units;
GridBagConstraints c = new GridBagConstraints();
c.weighty = 1;
class Altitude extends ValueHold {
void show (AltosState state, AltosListenerState listener_state) {
- show(AltosConvert.height, state.altitude());
+ show(state.altitude());
}
public Altitude (GridBagLayout layout, int y) {
- super (layout, y, "Altitude");
+ super (layout, y, AltosConvert.height, "Altitude");
}
}
class AscentRate extends ValueHold {
void show (AltosState state, AltosListenerState listener_state) {
- show(AltosConvert.speed, state.gps_ascent_rate());
+ show(state.gps_ascent_rate());
}
public AscentRate (GridBagLayout layout, int y) {
- super (layout, y, "Ascent Rate");
+ super (layout, y, AltosConvert.speed, "Ascent Rate");
}
}
class GroundSpeed extends ValueHold {
void show (AltosState state, AltosListenerState listener_state) {
- show(AltosConvert.speed, state.gps_ground_speed());
+ show(state.gps_ground_speed());
}
public GroundSpeed (GridBagLayout layout, int y) {
- super (layout, y, "Ground Speed");
+ super (layout, y, AltosConvert.speed, "Ground Speed");
}
}
course));
}
public Course (GridBagLayout layout, int y) {
- super (layout, 0, y, "Course");
+ super (layout, y, "Course", false);
}
}
Lon lon;
- class GPSLocked extends Info {
+ class GPSLocked extends DualValue {
void show (AltosState state, AltosListenerState listener_state) {
if (state == null || state.gps == null)
hide();
else {
- show("%4d sats", state.gps.nsat);
- lights.set(state.gps.locked && state.gps.nsat >= 4);
+ int soln = state.gps.nsat;
+ int nsat = state.gps.cc_gps_sat != null ? state.gps.cc_gps_sat.length : 0;
+ show("%4d in solution", soln,
+ "%4d in view", nsat);
+ lights.set(state.gps.locked && soln >= 4);
}
}
public GPSLocked (GridBagLayout layout, int y) {
- super (layout, y, "GPS Locked");
+ super (layout, y, "GPS Locked", true);
}
}
gps_locked.reset();
}
- public void set_font() {
+ public void font_size_changed(int font_size) {
cur.setFont(AltosUILib.label_font);
max.setFont(AltosUILib.label_font);
- lat.set_font();
- lon.set_font();
- altitude.set_font();
- ground_speed.set_font();
- ascent_rate.set_font();
- course.set_font();
- gps_locked.set_font();
+ lat.font_size_changed(font_size);
+ lon.font_size_changed(font_size);
+ altitude.font_size_changed(font_size);
+ ground_speed.font_size_changed(font_size);
+ ascent_rate.font_size_changed(font_size);
+ course.font_size_changed(font_size);
+ gps_locked.font_size_changed(font_size);
+ }
+
+ public void units_changed(boolean imperial_units) {
+ lat.units_changed(imperial_units);
+ lon.units_changed(imperial_units);
+ altitude.units_changed(imperial_units);
+ ground_speed.units_changed(imperial_units);
+ ascent_rate.units_changed(imperial_units);
+ course.units_changed(imperial_units);
+ gps_locked.units_changed(imperial_units);
}
public void show(AltosState state, AltosListenerState listener_state) {
public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
GridBagLayout layout;
- public class FlightValue {
+ public class Value {
JLabel label;
JTextField value;
value.setVisible(visible);
}
- public FlightValue (GridBagLayout layout, int x, String text) {
+ public Value (GridBagLayout layout, int x, String text) {
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(5, 5, 5, 5);
c.anchor = GridBagConstraints.CENTER;
}
}
- class Call extends FlightValue {
+ class Call extends Value {
void show(AltosState state, AltosListenerState listener_state) {
value.setText(state.callsign);
if (state.callsign == null)
Call call;
- class Serial extends FlightValue {
+ class Serial extends Value {
void show(AltosState state, AltosListenerState listener_state) {
if (state.serial == AltosLib.MISSING)
value.setText("none");
Serial serial;
- class RSSI extends FlightValue {
+ class RSSI extends Value {
void show(AltosState state, AltosListenerState listener_state) {
value.setText(String.format("%d", state.rssi()));
if (state.rssi == AltosLib.MISSING)
RSSI rssi;
- class LastPacket extends FlightValue {
+ class LastPacket extends Value {
void show(AltosState state, AltosListenerState listener_state) {
long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
value.setText(String.format("%d", secs));
last_packet.reset();
}
- public void set_font () {
+ public void font_size_changed(int font_size) {
call.set_font();
serial.set_font();
rssi.set_font();
last_packet.set_font();
}
+ public void units_changed(boolean imperial_units) {
+ }
+
public void show (AltosState state, AltosListenerState listener_state) {
call.show(state, listener_state);
serial.show(state, listener_state);