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 {
34 public class AscentValue {
37 void show(AltosState state, int crc_errors) {}
42 public AscentValue (GridBagLayout layout, int y, String text) {
43 GridBagConstraints c = new GridBagConstraints();
46 label = new JLabel(text);
47 label.setFont(Altos.label_font);
48 label.setHorizontalAlignment(SwingConstants.LEFT);
49 c.gridx = 0; c.gridy = y;
50 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
51 c.anchor = GridBagConstraints.WEST;
52 c.fill = GridBagConstraints.VERTICAL;
54 layout.setConstraints(label, c);
57 value = new JTextField(30);
58 value.setFont(Altos.value_font);
59 value.setHorizontalAlignment(SwingConstants.RIGHT);
60 c.gridx = 1; c.gridy = y;
61 c.anchor = GridBagConstraints.WEST;
62 c.fill = GridBagConstraints.BOTH;
65 layout.setConstraints(value, c);
70 public class AscentValueHold {
76 void show(AltosState state, int crc_errors) {}
80 max_value.setText("");
84 void show(String format, double v) {
85 value.setText(String.format(format, v));
87 max_value.setText(String.format(format, v));
91 public AscentValueHold (GridBagLayout layout, int y, String text) {
92 GridBagConstraints c = new GridBagConstraints();
95 label = new JLabel(text);
96 label.setFont(Altos.label_font);
97 label.setHorizontalAlignment(SwingConstants.LEFT);
98 c.gridx = 0; c.gridy = y;
99 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
100 c.anchor = GridBagConstraints.WEST;
101 c.fill = GridBagConstraints.VERTICAL;
103 layout.setConstraints(label, c);
106 value = new JTextField(15);
107 value.setFont(Altos.value_font);
108 value.setHorizontalAlignment(SwingConstants.RIGHT);
109 c.gridx = 1; c.gridy = y;
110 c.anchor = GridBagConstraints.EAST;
111 c.fill = GridBagConstraints.BOTH;
113 layout.setConstraints(value, c);
116 max_value = new JTextField(15);
117 max_value.setFont(Altos.value_font);
118 max_value.setHorizontalAlignment(SwingConstants.RIGHT);
119 c.gridx = 2; c.gridy = y;
120 c.anchor = GridBagConstraints.EAST;
121 c.fill = GridBagConstraints.BOTH;
123 layout.setConstraints(max_value, c);
129 class Height extends AscentValueHold {
130 void show (AltosState state, int crc_errors) {
131 show("%6.0f m", state.height);
133 public Height (GridBagLayout layout, int y) {
134 super (layout, y, "Height");
140 class Speed extends AscentValueHold {
141 void show (AltosState state, int crc_errors) {
142 double speed = state.speed;
144 speed = state.baro_speed;
145 show("%6.0f m/s", speed);
147 public Speed (GridBagLayout layout, int y) {
148 super (layout, y, "Speed");
154 class Accel extends AscentValueHold {
155 void show (AltosState state, int crc_errors) {
156 show("%6.0f m/s²", state.acceleration);
158 public Accel (GridBagLayout layout, int y) {
159 super (layout, y, "Acceleration");
165 String pos(double p, String pos, String neg) {
171 int deg = (int) Math.floor(p);
172 double min = (p - Math.floor(p)) * 60.0;
173 return String.format("%s %4d° %9.6f", h, deg, min);
176 class Lat extends AscentValue {
177 void show (AltosState state, int crc_errors) {
178 if (state.gps != null)
179 value.setText(pos(state.gps.lat,"N", "S"));
181 value.setText("???");
183 public Lat (GridBagLayout layout, int y) {
184 super (layout, y, "Latitude");
190 class Lon extends AscentValue {
191 void show (AltosState state, int crc_errors) {
192 if (state.gps != null)
193 value.setText(pos(state.gps.lon,"E", "W"));
195 value.setText("???");
197 public Lon (GridBagLayout layout, int y) {
198 super (layout, y, "Longitude");
204 public void reset() {
212 public void show(AltosState state, int crc_errors) {
213 lat.show(state, crc_errors);
214 lon.show(state, crc_errors);
215 height.show(state, crc_errors);
216 speed.show(state, crc_errors);
217 accel.show(state, crc_errors);
220 public void labels(GridBagLayout layout, int y) {
221 GridBagConstraints c;
224 cur = new JLabel("Current");
225 cur.setFont(Altos.label_font);
226 c = new GridBagConstraints();
227 c.gridx = 1; c.gridy = y;
228 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
229 layout.setConstraints(cur, c);
232 max = new JLabel("Maximum");
233 max.setFont(Altos.label_font);
234 c.gridx = 2; c.gridy = y;
235 layout.setConstraints(max, c);
239 public AltosAscent() {
240 layout = new GridBagLayout();
244 /* Elements in ascent display:
251 height = new Height(layout, 1);
252 speed = new Speed(layout, 2);
253 accel = new Accel(layout, 3);
254 lat = new Lat(layout, 4);
255 lon = new Lon(layout, 5);