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; 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_7.*;
25 import org.altusmetrum.altosuilib_7.*;
27 public class TeleGPSInfo extends AltosUIFlightTab {
31 abstract class Value extends AltosUIUnitsIndicator {
32 public abstract void show(AltosState state, AltosListenerState listener_state);
34 public Value (Container container, int y, AltosUnits units, String text) {
35 super(container, y, units, text, 1, false, 2);
39 abstract class DualValue extends AltosUIUnitsIndicator {
40 public DualValue (Container container, int y, AltosUnits units, String text) {
41 super(container, y, units, text, 2, false, 1);
45 abstract class ValueHold extends DualValue {
49 public ValueHold (Container container, int y, AltosUnits units, String text) {
50 super(container, y, units, text);
54 class Altitude extends ValueHold {
55 public double value(AltosState state, int i) {
57 return state.altitude();
59 return state.max_altitude();
62 public Altitude (Container container, int y) {
63 super (container, y, AltosConvert.height, "Altitude");
67 class AscentRate extends ValueHold {
68 public double value(AltosState state, int i) {
70 return state.gps_ascent_rate();
72 return state.max_gps_ascent_rate();
74 public AscentRate (Container container, int y) {
75 super (container, y, AltosConvert.speed, "Ascent Rate");
79 class GroundSpeed extends ValueHold {
80 public double value(AltosState state, int i) {
82 return state.gps_ground_speed();
84 return state.max_gps_ground_speed();
86 public GroundSpeed (Container container, int y) {
87 super (container, y, AltosConvert.speed, "Ground Speed");
91 class Course extends AltosUIIndicator {
93 public void show (AltosState state, AltosListenerState listener_state) {
94 double course = state.gps_course();
95 if (course == AltosLib.MISSING)
96 show("Missing", "Missing");
98 show( String.format("%3.0f°", course),
99 AltosConvert.bearing_to_words(
100 AltosConvert.BEARING_LONG,
103 public Course (Container container, int y) {
104 super (container, y, "Course", 2, false, 1);
108 class Lat extends AltosUIIndicator {
110 String pos(double p, String pos, String neg) {
116 int deg = (int) Math.floor(p);
117 double min = (p - Math.floor(p)) * 60.0;
118 return String.format("%s %4d° %9.6f", h, deg, min);
121 public void show (AltosState state, AltosListenerState listener_state) {
122 if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING)
123 show(pos(state.gps.lat,"N", "S"));
127 public Lat (Container container, int y) {
128 super (container, y, "Latitude", 1, false, 2);
132 class Lon extends AltosUIIndicator {
134 String pos(double p, String pos, String neg) {
140 int deg = (int) Math.floor(p);
141 double min = (p - Math.floor(p)) * 60.0;
142 return String.format("%s %4d° %9.6f", h, deg, min);
145 public void show (AltosState state, AltosListenerState listener_state) {
146 if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING)
147 show(pos(state.gps.lon,"E", "W"));
151 public Lon (Container container, int y) {
152 super (container, y, "Longitude", 1, false, 2);
156 class GPSLocked extends AltosUIIndicator {
158 public void show (AltosState state, AltosListenerState listener_state) {
159 if (state == null || state.gps == null)
162 int soln = state.gps.nsat;
163 int nsat = state.gps.cc_gps_sat != null ? state.gps.cc_gps_sat.length : 0;
164 show("%4d in solution", soln,
165 "%4d in view", nsat);
166 set_lights(state.gps.locked && soln >= 4);
169 public GPSLocked (Container container, int y) {
170 super (container, y, "GPS Locked", 2, true, 1);
174 public void font_size_changed(int font_size) {
175 cur.setFont(AltosUILib.label_font);
176 max.setFont(AltosUILib.label_font);
177 super.font_size_changed(font_size);
180 public void labels(Container container, int y) {
181 GridBagLayout layout = (GridBagLayout)(container.getLayout());
182 GridBagConstraints c;
184 cur = new JLabel("Current");
185 cur.setFont(AltosUILib.label_font);
186 c = new GridBagConstraints();
187 c.gridx = 2; c.gridy = y;
188 c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
189 layout.setConstraints(cur, c);
192 max = new JLabel("Maximum");
193 max.setFont(AltosUILib.label_font);
194 c.gridx = 3; c.gridy = y;
195 layout.setConstraints(max, c);
199 public String getName() {
203 public TeleGPSInfo() {
206 add(new Altitude(this, y++));
207 add(new GroundSpeed(this, y++));
208 add(new AscentRate(this, y++));
209 add(new Course(this, y++));
210 add(new Lat(this, y++));
211 add(new Lon(this, y++));
212 add(new GPSLocked(this, y++));