2 * Copyright © 2014 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.telegps;
22 import java.awt.event.*;
24 import org.altusmetrum.altoslib_5.*;
25 import org.altusmetrum.altosuilib_3.*;
27 public class TeleGPSState extends AltosUIFlightTab {
31 abstract class Value extends AltosUIUnitsIndicator {
32 public Value (Container container, int y, AltosUnits units, String text) {
33 super(container, y, units, text, 1, false, 2);
37 abstract class DualValue extends AltosUIUnitsIndicator {
38 public DualValue (Container container, int y, AltosUnits units, String text) {
39 super(container, y, units, text, 2, false, 1);
43 abstract class ValueHold extends DualValue {
44 public ValueHold (Container container, int y, AltosUnits units, String text) {
45 super(container, y, units, text);
49 class Height extends ValueHold {
50 public double value(AltosState state, int i) {
52 return state.height();
54 return state.max_height();
57 public Height(Container container, int y) {
58 super(container, y, AltosConvert.height, "Height");
62 class Speed extends ValueHold {
63 public double value(AltosState state, int i) {
65 return state.gps_speed();
67 return state.max_gps_speed();
70 public Speed(Container container, int y) {
71 super(container, y, AltosConvert.speed, "Speed");
75 class Distance extends Value {
76 public double value(AltosState state, int i) {
77 if (state.from_pad != null)
78 return state.from_pad.distance;
80 return AltosLib.MISSING;
83 public Distance(Container container, int y) {
84 super(container, y, AltosConvert.distance, "Distance");
88 class Range extends Value {
89 public double value(AltosState state, int i) {
92 public Range (Container container, int y) {
93 super (container, y, AltosConvert.distance, "Range");
97 class Bearing extends AltosUIIndicator {
98 public void show (AltosState state, AltosListenerState listener_state) {
99 if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) {
100 show( String.format("%3.0f°", state.from_pad.bearing),
101 state.from_pad.bearing_words(
102 AltosGreatCircle.BEARING_LONG));
104 show("Missing", "Missing");
107 public Bearing (Container container, int y) {
108 super (container, y, "Bearing", 2, false, 1);
112 class Elevation extends AltosUIIndicator {
113 public void show (AltosState state, AltosListenerState listener_state) {
114 if (state.elevation == AltosLib.MISSING)
117 show("%3.0f°", state.elevation);
119 public Elevation (Container container, int y) {
120 super (container, y, "Elevation", 1, false, 2);
124 class FirmwareVersion extends AltosUIIndicator {
125 public void show(AltosState state, AltosListenerState listener_state) {
126 if (state.firmware_version == null)
129 show(state.firmware_version);
132 public FirmwareVersion(Container container, int y) {
133 super(container, y, "Firmware Version", 1, false, 2);
137 class FlightLogMax extends AltosUIIndicator {
138 public void show(AltosState state, AltosListenerState listener_state) {
139 if (state.flight_log_max == AltosLib.MISSING)
142 show(String.format("%dkB", state.flight_log_max));
145 public FlightLogMax(Container container, int y) {
146 super(container, y, "Flight Log Storage", 1, false, 2);
150 class BatteryVoltage extends AltosUIVoltageIndicator {
151 public double voltage(AltosState state) {
152 return state.battery_voltage;
155 public double good() {
156 return AltosLib.ao_battery_good;
159 public BatteryVoltage(Container container, int y) {
160 super(container, y, "Battery Voltage", 2);
165 public void labels(Container container, int y) {
166 GridBagLayout layout = (GridBagLayout)(container.getLayout());
167 GridBagConstraints c;
169 cur = new JLabel("Current");
170 cur.setFont(AltosUILib.label_font);
171 c = new GridBagConstraints();
172 c.gridx = 2; c.gridy = y;
173 c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
174 layout.setConstraints(cur, c);
177 max = new JLabel("Maximum");
178 max.setFont(AltosUILib.label_font);
179 c.gridx = 3; c.gridy = y;
180 layout.setConstraints(max, c);
184 public void font_size_changed(int font_size) {
185 cur.setFont(AltosUILib.label_font);
186 max.setFont(AltosUILib.label_font);
187 super.font_size_changed(font_size);
190 public String getName() {
194 public TeleGPSState() {
197 add(new Height(this, y++));
198 add(new Speed(this, y++));
199 add(new Distance(this, y++));
200 add(new Range(this, y++));
201 add(new Bearing(this, y++));
202 add(new Elevation(this, y++));
203 add(new FirmwareVersion(this, y++));
204 add(new FlightLogMax(this, y++));
205 add(new BatteryVoltage(this, y++));