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 {
34 public class DescentValue {
37 void show(AltosState state, int crc_errors) {}
43 void show(String format, double v) {
44 value.setText(String.format(format, v));
47 public DescentValue (GridBagLayout layout, int y, String text) {
48 GridBagConstraints c = new GridBagConstraints();
51 label = new JLabel(text);
52 label.setFont(Altos.label_font);
53 label.setHorizontalAlignment(SwingConstants.LEFT);
54 c.gridx = 0; c.gridy = y;
55 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
56 c.anchor = GridBagConstraints.WEST;
57 c.fill = GridBagConstraints.VERTICAL;
59 layout.setConstraints(label, c);
62 value = new JTextField(30);
63 value.setFont(Altos.value_font);
64 value.setHorizontalAlignment(SwingConstants.RIGHT);
65 c.gridx = 1; c.gridy = y;
67 c.anchor = GridBagConstraints.WEST;
68 c.fill = GridBagConstraints.BOTH;
70 layout.setConstraints(value, c);
75 class Height extends DescentValue {
76 void show (AltosState state, int crc_errors) {
77 show("%6.0f m", state.height);
79 public Height (GridBagLayout layout, int y) {
80 super (layout, y, "Height");
86 class Speed extends DescentValue {
87 void show (AltosState state, int crc_errors) {
88 double speed = state.speed;
90 speed = state.baro_speed;
91 show("%6.0f m/s", speed);
93 public Speed (GridBagLayout layout, int y) {
94 super (layout, y, "Speed");
100 String pos(double p, String pos, String neg) {
106 int deg = (int) Math.floor(p);
107 double min = (p - Math.floor(p)) * 60.0;
108 return String.format("%s %4d° %9.6f", h, deg, min);
111 class Lat extends DescentValue {
112 void show (AltosState state, int crc_errors) {
113 if (state.gps != null)
114 value.setText(pos(state.gps.lat,"N", "S"));
116 value.setText("???");
118 public Lat (GridBagLayout layout, int y) {
119 super (layout, y, "Latitude");
125 class Lon extends DescentValue {
126 void show (AltosState state, int crc_errors) {
127 if (state.gps != null)
128 value.setText(pos(state.gps.lon,"E", "W"));
130 value.setText("???");
132 public Lon (GridBagLayout layout, int y) {
133 super (layout, y, "Longitude");
142 JTextField value_deg;
145 value_deg.setText("");
147 void show (AltosState state, int crc_errors) {
148 if (state.from_pad != null) {
149 value.setText(state.from_pad.bearing_words(
150 AltosGreatCircle.BEARING_LONG));
151 value_deg.setText(String.format("%3.0f°", state.from_pad.bearing));
153 value.setText("???");
154 value_deg.setText("???");
157 public Bearing (GridBagLayout layout, int y) {
158 GridBagConstraints c = new GridBagConstraints();
161 label = new JLabel("Bearing");
162 label.setFont(Altos.label_font);
163 label.setHorizontalAlignment(SwingConstants.LEFT);
164 c.gridx = 0; c.gridy = y;
165 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
166 c.anchor = GridBagConstraints.WEST;
168 c.fill = GridBagConstraints.VERTICAL;
169 layout.setConstraints(label, c);
172 value = new JTextField(30);
173 value.setFont(Altos.value_font);
174 value.setHorizontalAlignment(SwingConstants.RIGHT);
175 c.gridx = 1; c.gridy = y;
176 c.anchor = GridBagConstraints.EAST;
178 c.fill = GridBagConstraints.BOTH;
179 layout.setConstraints(value, c);
182 value_deg = new JTextField(5);
183 value_deg.setFont(Altos.value_font);
184 value_deg.setHorizontalAlignment(SwingConstants.RIGHT);
185 c.gridx = 2; c.gridy = y;
186 c.anchor = GridBagConstraints.EAST;
188 c.fill = GridBagConstraints.BOTH;
189 layout.setConstraints(value_deg, c);
196 class Elevation extends DescentValue {
197 void show (AltosState state, int crc_errors) {
198 if (state.from_pad != null)
199 show("%3.0f°", state.elevation);
201 value.setText("???");
203 public Elevation (GridBagLayout layout, int y) {
204 super (layout, y, "Elevation");
210 class Range extends DescentValue {
211 void show (AltosState state, int crc_errors) {
212 show("%6.0f m", state.range);
214 public Range (GridBagLayout layout, int y) {
215 super (layout, y, "Range");
221 public void reset() {
231 public void show(AltosState state, int crc_errors) {
232 height.show(state, crc_errors);
233 speed.show(state, crc_errors);
234 bearing.show(state, crc_errors);
235 elevation.show(state, crc_errors);
236 range.show(state, crc_errors);
237 lat.show(state, crc_errors);
238 lon.show(state, crc_errors);
241 public AltosDescent() {
242 layout = new GridBagLayout();
246 /* Elements in descent display */
247 speed = new Speed(layout, 0);
248 height = new Height(layout, 1);
249 bearing = new Bearing(layout, 2);
250 elevation = new Elevation(layout, 3);
251 range = new Range(layout, 4);
252 lat = new Lat(layout, 5);
253 lon = new Lon(layout, 6);