summaryrefslogtreecommitdiff
path: root/altosui/AltosLanded.java
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2014-05-29 14:03:58 -0700
committerKeith Packard <keithp@keithp.com>2014-05-29 14:03:58 -0700
commitf80075be4ebb9c5fe00c24b8c7638fad23267424 (patch)
treea8badb211c002391b881109a9b7c0992e3099eaf /altosui/AltosLanded.java
parent71715337eb532a1fbe1a753240e7417d5223489f (diff)
java: Refactor AltosFlightDisplay units and font update handling
Make AltosFlightDisplay explicitly implement AltosFontListener and AltosUnitsListener interfaces to make everyone use the same API. Then, actually go implement units listeners so that changing units updates all of the active displays immediately Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosui/AltosLanded.java')
-rw-r--r--altosui/AltosLanded.java67
1 files changed, 46 insertions, 21 deletions
diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java
index 707d8fcc..bb52fe2b 100644
--- a/altosui/AltosLanded.java
+++ b/altosui/AltosLanded.java
@@ -27,10 +27,13 @@ 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("");
@@ -46,7 +49,8 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
value.setText(s);
}
- void show(AltosUnits units, double v) {
+ void show(double v) {
+ this.v = v;
show(units.show(8, v));
}
@@ -54,17 +58,24 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
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;
@@ -89,6 +100,10 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
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) {
@@ -151,12 +166,12 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
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");
}
}
@@ -164,10 +179,10 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
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");
}
}
@@ -175,10 +190,10 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
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");
}
}
@@ -186,10 +201,10 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
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");
}
}
@@ -205,14 +220,24 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
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) {