2 * Copyright © 2010 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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.telegps;
23 import java.awt.event.*;
25 import org.altusmetrum.altoslib_13.*;
26 import org.altusmetrum.altosuilib_13.*;
28 public class TeleGPSInfo extends AltosUIFlightTab {
32 abstract class Value extends AltosUIUnitsIndicator {
33 public abstract void show(AltosState state, AltosListenerState listener_state);
35 public Value (Container container, int y, AltosUnits units, String text) {
36 super(container, y, units, text, 1, false, 2);
40 abstract class DualValue extends AltosUIUnitsIndicator {
41 public DualValue (Container container, int y, AltosUnits units, String text) {
42 super(container, y, units, text, 2, false, 1);
46 abstract class ValueHold extends DualValue {
50 public ValueHold (Container container, int y, AltosUnits units, String text) {
51 super(container, y, units, text);
55 class Altitude extends ValueHold {
56 public double value(AltosState state, int i) {
58 return state.altitude();
60 return state.max_altitude();
63 public Altitude (Container container, int y) {
64 super (container, y, AltosConvert.height, "Altitude");
68 class AscentRate extends ValueHold {
69 public double value(AltosState state, int i) {
71 return state.gps_ascent_rate();
73 return state.max_gps_ascent_rate();
75 public AscentRate (Container container, int y) {
76 super (container, y, AltosConvert.speed, "Ascent Rate");
80 class GroundSpeed extends ValueHold {
81 public double value(AltosState state, int i) {
83 return state.gps_ground_speed();
85 return state.max_gps_ground_speed();
87 public GroundSpeed (Container container, int y) {
88 super (container, y, AltosConvert.speed, "Ground Speed");
92 class Course extends AltosUIIndicator {
94 public void show (AltosState state, AltosListenerState listener_state) {
95 double course = state.gps_course();
96 if (course == AltosLib.MISSING)
97 show("Missing", "Missing");
99 show( String.format("%3.0f°", course),
100 AltosConvert.bearing_to_words(
101 AltosConvert.BEARING_LONG,
104 public Course (Container container, int y) {
105 super (container, y, "Course", 2, false, 1);
109 class Lat extends AltosUIIndicator {
111 String pos(double p, String pos, String neg) {
117 int deg = (int) Math.floor(p);
118 double min = (p - Math.floor(p)) * 60.0;
119 return String.format("%s %4d° %9.6f", h, deg, min);
122 public void show (AltosState state, AltosListenerState listener_state) {
123 if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING)
124 show(pos(state.gps.lat,"N", "S"));
128 public Lat (Container container, int y) {
129 super (container, y, "Latitude", 1, false, 2);
133 class Lon extends AltosUIIndicator {
135 String pos(double p, String pos, String neg) {
141 int deg = (int) Math.floor(p);
142 double min = (p - Math.floor(p)) * 60.0;
143 return String.format("%s %4d° %9.6f", h, deg, min);
146 public void show (AltosState state, AltosListenerState listener_state) {
147 if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING)
148 show(pos(state.gps.lon,"E", "W"));
152 public Lon (Container container, int y) {
153 super (container, y, "Longitude", 1, false, 2);
157 class GPSLocked extends AltosUIIndicator {
159 public void show (AltosState state, AltosListenerState listener_state) {
160 if (state == null || state.gps == null)
163 int soln = state.gps.nsat;
164 int nsat = state.gps.cc_gps_sat != null ? state.gps.cc_gps_sat.length : 0;
165 show("%4d in solution", soln,
166 "%4d in view", nsat);
167 set_lights(state.gps.locked && soln >= 4);
170 public GPSLocked (Container container, int y) {
171 super (container, y, "GPS Locked", 2, true, 1);
175 public void font_size_changed(int font_size) {
176 cur.setFont(AltosUILib.label_font);
177 max.setFont(AltosUILib.label_font);
178 super.font_size_changed(font_size);
181 public void labels(Container container, int y) {
182 GridBagLayout layout = (GridBagLayout)(container.getLayout());
183 GridBagConstraints c;
185 cur = new JLabel("Current");
186 cur.setFont(AltosUILib.label_font);
187 c = new GridBagConstraints();
188 c.gridx = 2; c.gridy = y;
189 c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
190 layout.setConstraints(cur, c);
193 max = new JLabel("Maximum");
194 max.setFont(AltosUILib.label_font);
195 c.gridx = 3; c.gridy = y;
196 layout.setConstraints(max, c);
200 public String getName() {
204 public TeleGPSInfo() {
207 add(new Altitude(this, y++));
208 add(new GroundSpeed(this, y++));
209 add(new AscentRate(this, y++));
210 add(new Course(this, y++));
211 add(new Lat(this, y++));
212 add(new Lon(this, y++));
213 add(new GPSLocked(this, y++));