altosui/telegps: Expose configurable APRS SSID
[fw/altos] / telegps / TeleGPSState.java
1 /*
2  * Copyright © 2014 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 package org.altusmetrum.telegps;
19
20 import java.util.*;
21 import java.awt.*;
22 import java.awt.event.*;
23 import javax.swing.*;
24 import org.altusmetrum.altoslib_5.*;
25 import org.altusmetrum.altosuilib_3.*;
26
27 public class TeleGPSState extends AltosUIFlightTab {
28
29         JLabel  cur, max;
30
31         abstract class Value extends AltosUIUnitsIndicator {
32                 public Value (Container container, int y, AltosUnits units, String text) {
33                         super(container, y, units, text, 1, false, 2);
34                 }
35         }
36
37         abstract class DualValue extends AltosUIUnitsIndicator {
38                 public DualValue (Container container, int y, AltosUnits units, String text) {
39                         super(container, y, units, text, 2, false, 1);
40                 }
41         }
42
43         abstract class ValueHold extends DualValue {
44                 public ValueHold (Container container, int y, AltosUnits units, String text) {
45                         super(container, y, units, text);
46                 }
47         }
48
49         class Height extends ValueHold {
50                 public double value(AltosState state, int i) {
51                         if (i == 0)
52                                 return state.height();
53                         else
54                                 return state.max_height();
55                 }
56
57                 public Height(Container container, int y) {
58                         super(container, y, AltosConvert.height, "Height");
59                 }
60         }
61
62         class Speed extends ValueHold {
63                 public double value(AltosState state, int i) {
64                         if (i == 0)
65                                 return state.gps_speed();
66                         else
67                                 return state.max_gps_speed();
68                 }
69
70                 public Speed(Container container, int y) {
71                         super(container, y, AltosConvert.speed, "Speed");
72                 }
73         }
74
75         class Distance extends Value {
76                 public double value(AltosState state, int i) {
77                         if (state.from_pad != null)
78                                 return state.from_pad.distance;
79                         else
80                                 return AltosLib.MISSING;
81                 }
82
83                 public Distance(Container container, int y) {
84                         super(container, y, AltosConvert.distance, "Distance");
85                 }
86         }
87
88         class Range extends Value {
89                 public double value(AltosState state, int i) {
90                         return state.range;
91                 }
92                 public Range (Container container, int y) {
93                         super (container, y, AltosConvert.distance, "Range");
94                 }
95         }
96
97         class Bearing extends AltosUIIndicator {
98                 public void show (AltosState state, AltosListenerState listener_state) {
99                         if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) {
100                                 show( String.format("%3.0f°", state.from_pad.bearing),
101                                       state.from_pad.bearing_words(
102                                               AltosGreatCircle.BEARING_LONG));
103                         } else {
104                                 show("Missing", "Missing");
105                         }
106                 }
107                 public Bearing (Container container, int y) {
108                         super (container, y, "Bearing", 2, false, 1);
109                 }
110         }
111
112         class Elevation extends AltosUIIndicator {
113                 public void show (AltosState state, AltosListenerState listener_state) {
114                         if (state.elevation == AltosLib.MISSING)
115                                 show("Missing");
116                         else
117                                 show("%3.0f°", state.elevation);
118                 }
119                 public Elevation (Container container, int y) {
120                         super (container, y, "Elevation", 1, false, 2);
121                 }
122         }
123
124         class FirmwareVersion extends AltosUIIndicator {
125                 public void show(AltosState state, AltosListenerState listener_state) {
126                         if (state.firmware_version == null)
127                                 show("Missing");
128                         else
129                                 show(state.firmware_version);
130                 }
131
132                 public FirmwareVersion(Container container, int y) {
133                         super(container, y, "Firmware Version", 1, false, 2);
134                 }
135         }
136
137         class FlightLogMax extends AltosUIIndicator {
138                 public void show(AltosState state, AltosListenerState listener_state) {
139                         if (state.flight_log_max == AltosLib.MISSING)
140                                 show("Missing");
141                         else
142                                 show(String.format("%dkB", state.flight_log_max));
143                 }
144
145                 public FlightLogMax(Container container, int y) {
146                         super(container, y, "Flight Log Storage", 1, false, 2);
147                 }
148         }
149
150         class BatteryVoltage extends AltosUIVoltageIndicator {
151                 public double voltage(AltosState state) {
152                         return state.battery_voltage;
153                 }
154
155                 public double good() {
156                         return AltosLib.ao_battery_good;
157                 }
158
159                 public BatteryVoltage(Container container, int y) {
160                         super(container, y, "Battery Voltage", 2);
161                 }
162         }
163
164
165         public void labels(Container container, int y) {
166                 GridBagLayout           layout = (GridBagLayout)(container.getLayout());
167                 GridBagConstraints      c;
168
169                 cur = new JLabel("Current");
170                 cur.setFont(AltosUILib.label_font);
171                 c = new GridBagConstraints();
172                 c.gridx = 2; c.gridy = y;
173                 c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
174                 layout.setConstraints(cur, c);
175                 add(cur);
176
177                 max = new JLabel("Maximum");
178                 max.setFont(AltosUILib.label_font);
179                 c.gridx = 3; c.gridy = y;
180                 layout.setConstraints(max, c);
181                 add(max);
182         }
183
184         public void font_size_changed(int font_size) {
185                 cur.setFont(AltosUILib.label_font);
186                 max.setFont(AltosUILib.label_font);
187                 super.font_size_changed(font_size);
188         }
189
190         public String getName() {
191                 return "Status";
192         }
193
194         public TeleGPSState() {
195                 int y = 0;
196                 labels(this, y++);
197                 add(new Height(this, y++));
198                 add(new Speed(this, y++));
199                 add(new Distance(this, y++));
200                 add(new Range(this, y++));
201                 add(new Bearing(this, y++));
202                 add(new Elevation(this, y++));
203                 add(new FirmwareVersion(this, y++));
204                 add(new FlightLogMax(this, y++));
205                 add(new BatteryVoltage(this, y++));
206         }
207 }