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 AltosAscent extends JComponent implements AltosFlightDisplay {
36 public class AscentValue {
39 void show(AltosState state, int crc_errors) {}
44 public AscentValue (GridBagLayout layout, int y, String text) {
45 GridBagConstraints c = new GridBagConstraints();
47 label = new JLabel(text);
48 label.setFont(label_font);
49 label.setHorizontalAlignment(SwingConstants.LEFT);
50 c.gridx = 0; c.gridy = y;
51 c.insets = new Insets(10, 10, 10, 10);
52 c.anchor = GridBagConstraints.WEST;
53 layout.setConstraints(label, c);
56 value = new JTextField(20);
57 value.setFont(label_font);
58 value.setHorizontalAlignment(SwingConstants.RIGHT);
59 c.gridx = 1; c.gridy = y;
60 c.anchor = GridBagConstraints.WEST;
61 c.fill = GridBagConstraints.HORIZONTAL;
63 layout.setConstraints(value, c);
68 public class AscentValueHold {
74 void show(AltosState state, int crc_errors) {}
78 max_value.setText("");
82 void show(String format, double v) {
83 value.setText(String.format(format, v));
85 max_value.setText(String.format(format, v));
89 public AscentValueHold (GridBagLayout layout, int y, String text) {
90 GridBagConstraints c = new GridBagConstraints();
92 label = new JLabel(text);
93 label.setFont(label_font);
94 label.setHorizontalAlignment(SwingConstants.LEFT);
95 c.gridx = 0; c.gridy = y;
96 c.insets = new Insets(10, 10, 10, 10);
97 c.anchor = GridBagConstraints.WEST;
98 layout.setConstraints(label, c);
101 value = new JTextField(10);
102 value.setFont(label_font);
103 value.setHorizontalAlignment(SwingConstants.RIGHT);
104 c.gridx = 1; c.gridy = y;
105 c.anchor = GridBagConstraints.EAST;
106 layout.setConstraints(value, c);
109 max_value = new JTextField(10);
110 max_value.setFont(label_font);
111 max_value.setHorizontalAlignment(SwingConstants.RIGHT);
112 c.gridx = 2; c.gridy = y;
113 c.anchor = GridBagConstraints.EAST;
114 layout.setConstraints(max_value, c);
120 class Height extends AscentValueHold {
121 void show (AltosState state, int crc_errors) {
122 show("%6.0f m", state.height);
124 public Height (GridBagLayout layout, int y) {
125 super (layout, y, "Height");
131 class Speed extends AscentValueHold {
132 void show (AltosState state, int crc_errors) {
133 double speed = state.speed;
135 speed = state.baro_speed;
136 show("%6.0f m/s", speed);
138 public Speed (GridBagLayout layout, int y) {
139 super (layout, y, "Speed");
145 class Accel extends AscentValueHold {
146 void show (AltosState state, int crc_errors) {
147 show("%6.0f m/s²", state.acceleration);
149 public Accel (GridBagLayout layout, int y) {
150 super (layout, y, "Acceleration");
156 String pos(double p, String pos, String neg) {
162 int deg = (int) Math.floor(p);
163 double min = (p - Math.floor(p)) * 60.0;
164 return String.format("%s %4d° %9.6f", h, deg, min);
167 class Lat extends AscentValue {
168 void show (AltosState state, int crc_errors) {
169 if (state.gps != null)
170 value.setText(pos(state.gps.lat,"N", "S"));
172 value.setText("???");
174 public Lat (GridBagLayout layout, int y) {
175 super (layout, y, "Latitude");
181 class Lon extends AscentValue {
182 void show (AltosState state, int crc_errors) {
183 if (state.gps != null)
184 value.setText(pos(state.gps.lon,"E", "W"));
186 value.setText("???");
188 public Lon (GridBagLayout layout, int y) {
189 super (layout, y, "Longitude");
195 public void reset() {
203 public void show(AltosState state, int crc_errors) {
204 lat.show(state, crc_errors);
205 lon.show(state, crc_errors);
206 height.show(state, crc_errors);
207 speed.show(state, crc_errors);
208 accel.show(state, crc_errors);
211 public void labels(GridBagLayout layout, int y) {
212 GridBagConstraints c;
215 cur = new JLabel("Current");
216 cur.setFont(label_font);
217 c = new GridBagConstraints();
218 c.gridx = 1; c.gridy = y;
219 c.insets = new Insets(10, 10, 10, 10);
220 layout.setConstraints(cur, c);
223 max = new JLabel("Maximum");
224 max.setFont(label_font);
225 c.gridx = 2; c.gridy = y;
226 layout.setConstraints(max, c);
230 public AltosAscent() {
231 layout = new GridBagLayout();
233 label_font = new Font("Dialog", Font.PLAIN, 24);
234 value_font = new Font("Monospace", Font.PLAIN, 24);
237 /* Elements in ascent display:
244 height = new Height(layout, 1);
245 speed = new Speed(layout, 2);
246 accel = new Accel(layout, 3);
247 lat = new Lat(layout, 4);
248 lon = new Lon(layout, 5);