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;
66 c.anchor = GridBagConstraints.WEST;
67 c.fill = GridBagConstraints.HORIZONTAL;
68 layout.setConstraints(value, c);
73 class Height extends DescentValue {
74 void show (AltosState state, int crc_errors) {
75 show("%6.0f m", state.height);
77 public Height (GridBagLayout layout, int y) {
78 super (layout, y, "Height");
84 class Speed extends DescentValue {
85 void show (AltosState state, int crc_errors) {
86 double speed = state.speed;
88 speed = state.baro_speed;
89 show("%6.0f m/s", speed);
91 public Speed (GridBagLayout layout, int y) {
92 super (layout, y, "Speed");
98 String pos(double p, String pos, String neg) {
104 int deg = (int) Math.floor(p);
105 double min = (p - Math.floor(p)) * 60.0;
106 return String.format("%s %4d° %9.6f", h, deg, min);
109 class Lat extends DescentValue {
110 void show (AltosState state, int crc_errors) {
111 if (state.gps != null)
112 value.setText(pos(state.gps.lat,"N", "S"));
114 value.setText("???");
116 public Lat (GridBagLayout layout, int y) {
117 super (layout, y, "Latitude");
123 class Lon extends DescentValue {
124 void show (AltosState state, int crc_errors) {
125 if (state.gps != null)
126 value.setText(pos(state.gps.lon,"E", "W"));
128 value.setText("???");
130 public Lon (GridBagLayout layout, int y) {
131 super (layout, y, "Longitude");
140 JTextField value_deg;
143 value_deg.setText("");
145 void show (AltosState state, int crc_errors) {
146 if (state.from_pad != null) {
147 value.setText(state.from_pad.bearing_words(
148 AltosGreatCircle.BEARING_LONG));
149 value_deg.setText(String.format("%3.0f°", state.from_pad.bearing));
151 value.setText("???");
152 value_deg.setText("???");
155 public Bearing (GridBagLayout layout, int y) {
156 GridBagConstraints c = new GridBagConstraints();
158 label = new JLabel("Bearing");
159 label.setFont(label_font);
160 label.setHorizontalAlignment(SwingConstants.LEFT);
161 c.gridx = 0; c.gridy = y;
162 c.insets = new Insets(10, 10, 10, 10);
163 c.anchor = GridBagConstraints.WEST;
164 layout.setConstraints(label, c);
167 value = new JTextField(30);
168 value.setFont(value_font);
169 value.setHorizontalAlignment(SwingConstants.RIGHT);
170 c.gridx = 1; c.gridy = y;
171 c.anchor = GridBagConstraints.EAST;
172 c.fill = GridBagConstraints.HORIZONTAL;
173 layout.setConstraints(value, c);
176 value_deg = new JTextField(5);
177 value_deg.setFont(value_font);
178 value_deg.setHorizontalAlignment(SwingConstants.RIGHT);
179 c.gridx = 2; c.gridy = y;
180 c.anchor = GridBagConstraints.EAST;
181 c.fill = GridBagConstraints.HORIZONTAL;
183 layout.setConstraints(value_deg, c);
190 class Elevation extends DescentValue {
191 void show (AltosState state, int crc_errors) {
192 if (state.from_pad != null)
193 show("%3.0f°", state.elevation);
195 value.setText("???");
197 public Elevation (GridBagLayout layout, int y) {
198 super (layout, y, "Elevation");
204 class Range extends DescentValue {
205 void show (AltosState state, int crc_errors) {
206 show("%6.0f m", state.range);
208 public Range (GridBagLayout layout, int y) {
209 super (layout, y, "Range");
215 public void reset() {
225 public void show(AltosState state, int crc_errors) {
226 height.show(state, crc_errors);
227 speed.show(state, crc_errors);
228 bearing.show(state, crc_errors);
229 elevation.show(state, crc_errors);
230 range.show(state, crc_errors);
231 lat.show(state, crc_errors);
232 lon.show(state, crc_errors);
235 public AltosDescent() {
236 layout = new GridBagLayout();
238 label_font = new Font("Dialog", Font.PLAIN, 24);
239 value_font = new Font("Monospaced", Font.PLAIN, 24);
242 /* Elements in descent display */
243 speed = new Speed(layout, 0);
244 height = new Height(layout, 1);
245 bearing = new Bearing(layout, 2);
246 elevation = new Elevation(layout, 3);
247 range = new Range(layout, 4);
248 lat = new Lat(layout, 5);
249 lon = new Lon(layout, 6);