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 AltosLanded extends JComponent implements AltosFlightDisplay {
36 public class LandedValue {
39 void show(AltosState state, int crc_errors) {}
46 label.setVisible(true);
47 value.setVisible(true);
51 label.setVisible(false);
52 value.setVisible(false);
55 void show(String format, double v) {
57 value.setText(String.format(format, v));
61 public LandedValue (GridBagLayout layout, int y, String text) {
62 GridBagConstraints c = new GridBagConstraints();
65 label = new JLabel(text);
66 label.setFont(label_font);
67 label.setHorizontalAlignment(SwingConstants.LEFT);
68 c.gridx = 0; c.gridy = y;
69 c.insets = new Insets(10, 10, 10, 10);
70 c.anchor = GridBagConstraints.WEST;
72 c.fill = GridBagConstraints.VERTICAL;
73 layout.setConstraints(label, c);
76 value = new JTextField(Altos.text_width);
77 value.setFont(value_font);
78 value.setHorizontalAlignment(SwingConstants.RIGHT);
79 c.gridx = 1; c.gridy = y;
80 c.anchor = GridBagConstraints.WEST;
82 c.fill = GridBagConstraints.BOTH;
83 layout.setConstraints(value, c);
88 String pos(double p, String pos, String neg) {
94 int deg = (int) Math.floor(p);
95 double min = (p - Math.floor(p)) * 60.0;
96 return String.format("%s %4d° %9.6f", h, deg, min);
99 class Lat extends LandedValue {
100 void show (AltosState state, int crc_errors) {
102 if (state.gps != null)
103 value.setText(pos(state.gps.lat,"N", "S"));
105 value.setText("???");
107 public Lat (GridBagLayout layout, int y) {
108 super (layout, y, "Latitude");
114 class Lon extends LandedValue {
115 void show (AltosState state, int crc_errors) {
117 if (state.gps != null)
118 value.setText(pos(state.gps.lon,"E", "W"));
120 value.setText("???");
122 public Lon (GridBagLayout layout, int y) {
123 super (layout, y, "Longitude");
129 class Bearing extends LandedValue {
130 void show (AltosState state, int crc_errors) {
132 if (state.from_pad != null)
133 show("%3.0f°", state.from_pad.bearing);
135 value.setText("???");
137 public Bearing (GridBagLayout layout, int y) {
138 super (layout, y, "Bearing");
144 class Distance extends LandedValue {
145 void show (AltosState state, int crc_errors) {
147 if (state.from_pad != null)
148 show("%6.0f m", state.from_pad.distance);
150 value.setText("???");
152 public Distance (GridBagLayout layout, int y) {
153 super (layout, y, "Distance");
159 class Height extends LandedValue {
160 void show (AltosState state, int crc_errors) {
161 show("%6.0f m", state.max_height);
163 public Height (GridBagLayout layout, int y) {
164 super (layout, y, "Maximum Height");
170 class Speed extends LandedValue {
171 void show (AltosState state, int crc_errors) {
172 show("%6.0f m/s", state.max_speed);
174 public Speed (GridBagLayout layout, int y) {
175 super (layout, y, "Maximum Speed");
181 class Accel extends LandedValue {
182 void show (AltosState state, int crc_errors) {
183 show("%6.0f m/s²", state.max_acceleration);
185 public Accel (GridBagLayout layout, int y) {
186 super (layout, y, "Maximum Acceleration");
192 public void reset() {
202 public void show(AltosState state, int crc_errors) {
203 if (state.gps != null) {
204 bearing.show(state, crc_errors);
205 distance.show(state, crc_errors);
206 lat.show(state, crc_errors);
207 lon.show(state, crc_errors);
214 height.show(state, crc_errors);
215 speed.show(state, crc_errors);
216 accel.show(state, crc_errors);
219 public AltosLanded() {
220 layout = new GridBagLayout();
222 label_font = new Font("Dialog", Font.PLAIN, 22);
223 value_font = new Font("Monospaced", Font.PLAIN, 22);
226 /* Elements in descent display */
227 bearing = new Bearing(layout, 0);
228 distance = new Distance(layout, 1);
229 lat = new Lat(layout, 2);
230 lon = new Lon(layout, 3);
231 height = new Height(layout, 4);
232 speed = new Speed(layout, 5);
233 accel = new Accel(layout, 6);