*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
-import org.altusmetrum.altoslib_4.*;
-import org.altusmetrum.altosuilib_2.*;
+import org.altusmetrum.altoslib_11.*;
+import org.altusmetrum.altosuilib_11.*;
-public class TeleGPSState extends JComponent implements AltosFlightDisplay, HierarchyListener {
- GridBagLayout layout;
- JLabel cur, max;
+public class TeleGPSState extends AltosUIFlightTab {
- private AltosState last_state;
- private AltosListenerState last_listener_state;
+ JLabel cur, max;
abstract class Value extends AltosUIUnitsIndicator {
public Value (Container container, int y, AltosUnits units, String text) {
}
abstract class ValueHold extends DualValue {
- public void reset() {
- super.reset();
- last_values[1] = AltosLib.MISSING;
- }
public ValueHold (Container container, int y, AltosUnits units, String text) {
super(container, y, units, text);
}
class Bearing extends AltosUIIndicator {
public void show (AltosState state, AltosListenerState listener_state) {
- if (state.from_pad != null) {
+ if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) {
show( String.format("%3.0f°", state.from_pad.bearing),
state.from_pad.bearing_words(
AltosGreatCircle.BEARING_LONG));
} else {
- show("???", "???");
+ show("Missing", "Missing");
}
}
public Bearing (Container container, int y) {
class Elevation extends AltosUIIndicator {
public void show (AltosState state, AltosListenerState listener_state) {
- show("%3.0f°", state.elevation);
+ if (state.elevation == AltosLib.MISSING)
+ show("Missing");
+ else
+ show("%3.0f°", state.elevation);
}
public Elevation (Container container, int y) {
super (container, y, "Elevation", 1, false, 2);
class FlightLogMax extends AltosUIIndicator {
public void show(AltosState state, AltosListenerState listener_state) {
- if (state.flight_log_max == AltosLib.MISSING)
+ int storage = state.flight_log_max;
+ if (storage == AltosLib.MISSING)
+ storage = state.log_space >> 10;
+ if (storage == AltosLib.MISSING)
show("Missing");
else
- show(String.format("%dkB", state.flight_log_max));
+ show(String.format("%dkB", storage));
}
public FlightLogMax(Container container, int y) {
}
}
- LinkedList<AltosUIIndicator> indicators = new LinkedList<AltosUIIndicator>();
+ class ReceiverBattery extends AltosUIVoltageIndicator {
+
+ public double voltage(AltosState state) { return AltosLib.MISSING; }
+
+ public double good() { return AltosLib.ao_battery_good; }
+
+ public boolean hide(AltosState state, AltosListenerState listener_state, int i) {
+ return value(state, listener_state, i) == AltosLib.MISSING;
+ }
+
+ public double value(AltosState state, AltosListenerState listener_state, int i) {
+ if (listener_state == null)
+ return AltosLib.MISSING;
+ return listener_state.battery;
+ }
+
+ public ReceiverBattery (AltosUIFlightTab container, int y) {
+ super(container, y, "Receiver Battery", 2);
+ }
+ }
public void labels(Container container, int y) {
GridBagLayout layout = (GridBagLayout)(container.getLayout());
add(max);
}
- public void reset() {
- for (AltosUIIndicator i : indicators)
- i.reset();
- }
-
public void font_size_changed(int font_size) {
- for (AltosUIIndicator i : indicators)
- i.font_size_changed(font_size);
- }
-
- public void units_changed(boolean imperial_units) {
- for (AltosUIIndicator i : indicators)
- i.units_changed(imperial_units);
- }
-
- public void show(AltosState state, AltosListenerState listener_state) {
- if (!isShowing()) {
- last_state = state;
- last_listener_state = listener_state;
- return;
- }
-
- for (AltosUIIndicator i : indicators)
- i.show(state, listener_state);
+ cur.setFont(AltosUILib.label_font);
+ max.setFont(AltosUILib.label_font);
+ super.font_size_changed(font_size);
}
public String getName() {
return "Status";
}
- 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 TeleGPSState() {
- layout = new GridBagLayout();
-
- setLayout(layout);
-
- /* Elements in state display:
- *
- * config_version;
- * lon
- * height
- */
int y = 0;
labels(this, y++);
- indicators.add(new Height(this, y++));
- indicators.add(new Speed(this, y++));
- indicators.add(new Distance(this, y++));
- indicators.add(new Range(this, y++));
- indicators.add(new Bearing(this, y++));
- indicators.add(new Elevation(this, y++));
- indicators.add(new FirmwareVersion(this, y++));
- indicators.add(new FlightLogMax(this, y++));
- indicators.add(new BatteryVoltage(this, y++));
- addHierarchyListener(this);
+ add(new Height(this, y++));
+ add(new Speed(this, y++));
+ add(new Distance(this, y++));
+ add(new Range(this, y++));
+ add(new Bearing(this, y++));
+ add(new Elevation(this, y++));
+ add(new FirmwareVersion(this, y++));
+ add(new FlightLogMax(this, y++));
+ add(new BatteryVoltage(this, y++));
+ add(new ReceiverBattery(this, y++));
}
}