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();
53 label = new JLabel(text);
54 label.setFont(label_font);
55 label.setHorizontalAlignment(SwingConstants.LEFT);
56 c.gridx = 0; c.gridy = y;
57 c.insets = new Insets(10, 10, 10, 10);
58 c.anchor = GridBagConstraints.WEST;
60 c.fill = GridBagConstraints.VERTICAL;
61 layout.setConstraints(label, c);
64 value = new JTextField(Altos.text_width);
65 value.setFont(value_font);
66 value.setHorizontalAlignment(SwingConstants.RIGHT);
67 c.gridx = 1; c.gridy = y;
68 c.anchor = GridBagConstraints.WEST;
70 c.fill = GridBagConstraints.BOTH;
71 layout.setConstraints(value, c);
76 String pos(double p, String pos, String neg) {
82 int deg = (int) Math.floor(p);
83 double min = (p - Math.floor(p)) * 60.0;
84 return String.format("%s %4d° %9.6f", h, deg, min);
87 class Lat extends LandedValue {
88 void show (AltosState state, int crc_errors) {
89 if (state.gps != null)
90 value.setText(pos(state.gps.lat,"N", "S"));
94 public Lat (GridBagLayout layout, int y) {
95 super (layout, y, "Latitude");
101 class Lon extends LandedValue {
102 void show (AltosState state, int crc_errors) {
103 if (state.gps != null)
104 value.setText(pos(state.gps.lon,"E", "W"));
106 value.setText("???");
108 public Lon (GridBagLayout layout, int y) {
109 super (layout, y, "Longitude");
115 class Bearing extends LandedValue {
116 void show (AltosState state, int crc_errors) {
117 if (state.from_pad != null)
118 show("%3.0f°", state.from_pad.bearing);
120 value.setText("???");
122 public Bearing (GridBagLayout layout, int y) {
123 super (layout, y, "Bearing");
129 class Distance extends LandedValue {
130 void show (AltosState state, int crc_errors) {
131 if (state.from_pad != null)
132 show("%6.0f m", state.from_pad.distance);
134 value.setText("???");
136 public Distance (GridBagLayout layout, int y) {
137 super (layout, y, "Distance");
143 class Height extends LandedValue {
144 void show (AltosState state, int crc_errors) {
145 show("%6.0f m", state.max_height);
147 public Height (GridBagLayout layout, int y) {
148 super (layout, y, "Maximum Height");
154 class Speed extends LandedValue {
155 void show (AltosState state, int crc_errors) {
156 show("%6.0f m/s", state.max_speed);
158 public Speed (GridBagLayout layout, int y) {
159 super (layout, y, "Maximum Speed");
165 class Accel extends LandedValue {
166 void show (AltosState state, int crc_errors) {
167 show("%6.0f m/s²", state.max_acceleration);
169 public Accel (GridBagLayout layout, int y) {
170 super (layout, y, "Maximum Acceleration");
176 public void reset() {
186 public void show(AltosState state, int crc_errors) {
187 bearing.show(state, crc_errors);
188 distance.show(state, crc_errors);
189 lat.show(state, crc_errors);
190 lon.show(state, crc_errors);
191 height.show(state, crc_errors);
192 speed.show(state, crc_errors);
193 accel.show(state, crc_errors);
196 public AltosLanded() {
197 layout = new GridBagLayout();
199 label_font = new Font("Dialog", Font.PLAIN, 22);
200 value_font = new Font("Monospaced", Font.PLAIN, 22);
203 /* Elements in descent display */
204 bearing = new Bearing(layout, 0);
205 distance = new Distance(layout, 1);
206 lat = new Lat(layout, 2);
207 lon = new Lon(layout, 3);
208 height = new Height(layout, 4);
209 speed = new Speed(layout, 5);
210 accel = new Accel(layout, 6);