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.
21 import java.awt.event.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.LinkedBlockingQueue;
31 public class AltosDescent extends JComponent implements AltosFlightDisplay {
36 public class DescentValue {
39 void show(AltosState state, int crc_errors) {}
45 void show(String format, double v) {
46 value.setText(String.format(format, v));
49 public DescentValue (GridBagLayout layout, int y, String text) {
50 GridBagConstraints c = new GridBagConstraints();
52 label = new JLabel(text);
53 label.setFont(label_font);
54 label.setHorizontalAlignment(SwingConstants.LEFT);
55 c.gridx = 0; c.gridy = y;
56 c.insets = new Insets(10, 10, 10, 10);
57 c.anchor = GridBagConstraints.WEST;
58 layout.setConstraints(label, c);
61 value = new JTextField(30);
62 value.setFont(value_font);
63 value.setHorizontalAlignment(SwingConstants.RIGHT);
64 c.gridx = 1; c.gridy = y;
65 c.anchor = GridBagConstraints.WEST;
66 c.fill = GridBagConstraints.HORIZONTAL;
67 layout.setConstraints(value, c);
72 class Height extends DescentValue {
73 void show (AltosState state, int crc_errors) {
74 show("%6.0f m", state.height);
76 public Height (GridBagLayout layout, int y) {
77 super (layout, y, "Height");
83 class Speed extends DescentValue {
84 void show (AltosState state, int crc_errors) {
85 double speed = state.speed;
87 speed = state.baro_speed;
88 show("%6.0f m/s", speed);
90 public Speed (GridBagLayout layout, int y) {
91 super (layout, y, "Speed");
97 String pos(double p, String pos, String neg) {
103 int deg = (int) Math.floor(p);
104 double min = (p - Math.floor(p)) * 60.0;
105 return String.format("%s %4d° %9.6f", h, deg, min);
108 class Lat extends DescentValue {
109 void show (AltosState state, int crc_errors) {
110 if (state.gps != null)
111 value.setText(pos(state.gps.lat,"N", "S"));
113 value.setText("???");
115 public Lat (GridBagLayout layout, int y) {
116 super (layout, y, "Latitude");
122 class Lon extends DescentValue {
123 void show (AltosState state, int crc_errors) {
124 if (state.gps != null)
125 value.setText(pos(state.gps.lon,"E", "W"));
127 value.setText("???");
129 public Lon (GridBagLayout layout, int y) {
130 super (layout, y, "Longitude");
136 class Bearing extends DescentValue {
137 void show (AltosState state, int crc_errors) {
138 if (state.from_pad != null)
139 show("%3.0f°", state.from_pad.bearing);
141 value.setText("???");
143 public Bearing (GridBagLayout layout, int y) {
144 super (layout, y, "Bearing");
150 class Elevation extends DescentValue {
151 void show (AltosState state, int crc_errors) {
152 if (state.from_pad != null)
153 show("%3.0f°", state.elevation);
155 value.setText("???");
157 public Elevation (GridBagLayout layout, int y) {
158 super (layout, y, "Elevation");
164 class Range extends DescentValue {
165 void show (AltosState state, int crc_errors) {
166 show("%6.0f m", state.range);
168 public Range (GridBagLayout layout, int y) {
169 super (layout, y, "Range");
175 public void reset() {
185 public void show(AltosState state, int crc_errors) {
186 height.show(state, crc_errors);
187 speed.show(state, crc_errors);
188 bearing.show(state, crc_errors);
189 elevation.show(state, crc_errors);
190 range.show(state, crc_errors);
191 lat.show(state, crc_errors);
192 lon.show(state, crc_errors);
195 public AltosDescent() {
196 layout = new GridBagLayout();
198 label_font = new Font("Dialog", Font.PLAIN, 24);
199 value_font = new Font("Monospaced", Font.PLAIN, 24);
202 /* Elements in descent display */
203 speed = new Speed(layout, 0);
204 height = new Height(layout, 1);
205 bearing = new Bearing(layout, 2);
206 elevation = new Elevation(layout, 3);
207 range = new Range(layout, 4);
208 lat = new Lat(layout, 5);
209 lon = new Lon(layout, 6);