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) {}
45 void show(String format, double v) {
46 value.setText(String.format(format, v));
49 public LandedValue (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 String pos(double p, String pos, String neg) {
78 int deg = (int) Math.floor(p);
79 double min = (p - Math.floor(p)) * 60.0;
80 return String.format("%s %4d° %9.6f", h, deg, min);
83 class Lat extends LandedValue {
84 void show (AltosState state, int crc_errors) {
85 if (state.gps != null)
86 value.setText(pos(state.gps.lat,"N", "S"));
90 public Lat (GridBagLayout layout, int y) {
91 super (layout, y, "Latitude");
97 class Lon extends LandedValue {
98 void show (AltosState state, int crc_errors) {
99 if (state.gps != null)
100 value.setText(pos(state.gps.lon,"E", "W"));
102 value.setText("???");
104 public Lon (GridBagLayout layout, int y) {
105 super (layout, y, "Longitude");
111 class Bearing extends LandedValue {
112 void show (AltosState state, int crc_errors) {
113 if (state.from_pad != null)
114 show("%3.0f°", state.from_pad.bearing);
116 value.setText("???");
118 public Bearing (GridBagLayout layout, int y) {
119 super (layout, y, "Bearing");
125 class Distance extends LandedValue {
126 void show (AltosState state, int crc_errors) {
127 if (state.from_pad != null)
128 show("%6.0f m", state.from_pad.distance);
130 value.setText("???");
132 public Distance (GridBagLayout layout, int y) {
133 super (layout, y, "Distance");
139 class Height extends LandedValue {
140 void show (AltosState state, int crc_errors) {
141 show("%6.0f m", state.max_height);
143 public Height (GridBagLayout layout, int y) {
144 super (layout, y, "Maximum Height");
150 class Speed extends LandedValue {
151 void show (AltosState state, int crc_errors) {
152 show("%6.0f m/s", state.max_speed);
154 public Speed (GridBagLayout layout, int y) {
155 super (layout, y, "Maximum Speed");
161 class Accel extends LandedValue {
162 void show (AltosState state, int crc_errors) {
163 show("%6.0f m/s²", state.max_acceleration);
165 public Accel (GridBagLayout layout, int y) {
166 super (layout, y, "Maximum Acceleration");
172 public void reset() {
182 public void show(AltosState state, int crc_errors) {
183 bearing.show(state, crc_errors);
184 distance.show(state, crc_errors);
185 lat.show(state, crc_errors);
186 lon.show(state, crc_errors);
187 height.show(state, crc_errors);
188 speed.show(state, crc_errors);
189 accel.show(state, crc_errors);
192 public AltosLanded() {
193 layout = new GridBagLayout();
195 label_font = new Font("Dialog", Font.PLAIN, 24);
196 value_font = new Font("Monospaced", Font.PLAIN, 24);
199 /* Elements in descent display */
200 bearing = new Bearing(layout, 0);
201 distance = new Distance(layout, 1);
202 lat = new Lat(layout, 2);
203 lon = new Lon(layout, 3);
204 height = new Height(layout, 4);
205 speed = new Speed(layout, 5);
206 accel = new Accel(layout, 6);