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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.telegps;
23 import org.altusmetrum.altoslib_14.*;
24 import org.altusmetrum.altosuilib_14.*;
26 public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
33 void show(AltosState state, AltosListenerState listener_state) {}
40 label.setFont(AltosUILib.status_font);
41 value.setFont(AltosUILib.status_font);
44 void setVisible(boolean visible) {
45 label.setVisible(visible);
46 value.setVisible(visible);
49 public Value (GridBagLayout layout, int x, String text) {
50 GridBagConstraints c = new GridBagConstraints();
51 c.insets = new Insets(5, 5, 5, 5);
52 c.anchor = GridBagConstraints.CENTER;
53 c.fill = GridBagConstraints.BOTH;
57 label = new JLabel(text);
58 label.setFont(AltosUILib.status_font);
59 label.setHorizontalAlignment(SwingConstants.CENTER);
60 c.gridx = x; c.gridy = 0;
61 layout.setConstraints(label, c);
64 value = new JTextField("");
65 value.setEditable(false);
66 value.setFont(AltosUILib.status_font);
67 value.setHorizontalAlignment(SwingConstants.CENTER);
68 c.gridx = x; c.gridy = 1;
69 layout.setConstraints(value, c);
74 class Call extends Value {
77 void show(AltosState state, AltosListenerState listener_state) {
78 AltosCalData cal_data = state.cal_data();
80 System.out.printf("null cal data?\n");
81 if (cal_data.callsign != call) {
82 value.setText(cal_data.callsign);
83 call = cal_data.callsign;
85 if (cal_data.callsign == null)
96 public Call (GridBagLayout layout, int x) {
97 super (layout, x, "Callsign");
103 class Serial extends Value {
105 void show(AltosState state, AltosListenerState listener_state) {
106 AltosCalData cal_data = state.cal_data();
107 if (cal_data.serial != serial) {
108 if (cal_data.serial == AltosLib.MISSING)
109 value.setText("none");
111 value.setText(String.format("%d", cal_data.serial));
112 serial = cal_data.serial;
116 public void reset() {
121 public Serial (GridBagLayout layout, int x) {
122 super (layout, x, "Serial");
128 class Flight extends Value {
130 int last_flight = -1;
132 void show(AltosState state, AltosListenerState listener_state) {
133 AltosCalData cal_data = state.cal_data();
134 if (cal_data.flight != last_flight) {
135 if (cal_data.flight == AltosLib.MISSING)
136 value.setText("none");
138 value.setText(String.format("%d", cal_data.flight));
139 last_flight = cal_data.flight;
143 public void reset() {
148 public Flight (GridBagLayout layout, int x) {
149 super (layout, x, "Flight");
155 class RSSI extends Value {
158 void show(AltosState state, AltosListenerState listener_state) {
159 int new_rssi = state.rssi();
161 if (new_rssi != rssi) {
162 value.setText(String.format("%d", new_rssi));
163 if (state.rssi == AltosLib.MISSING)
171 public void reset() {
176 public RSSI (GridBagLayout layout, int x) {
177 super (layout, x, "RSSI");
183 class LastPacket extends Value {
187 void show(AltosState state, AltosListenerState listener_state) {
188 if (listener_state.running) {
189 long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
191 if (secs != last_secs) {
192 value.setText(String.format("%d", secs));
196 value.setText("done");
209 public LastPacket(GridBagLayout layout, int x) {
210 super (layout, x, "Age");
214 LastPacket last_packet;
216 public void disable_receive() {
217 last_packet.disable();
220 public void reset () {
228 public void font_size_changed(int font_size) {
233 last_packet.set_font();
236 public void units_changed(boolean imperial_units) {
239 public void show (AltosState state, AltosListenerState listener_state) {
240 call.show(state, listener_state);
241 serial.show(state, listener_state);
242 flight.show(state, listener_state);
243 rssi.show(state, listener_state);
244 last_packet.show(state, listener_state);
245 if (!listener_state.running)
249 public int height() {
250 Dimension d = layout.preferredLayoutSize(this);
254 TeleGPSStatusUpdate status_update;
255 javax.swing.Timer timer;
257 public void start(TeleGPSStatusUpdate status_update) {
258 this.status_update = status_update;
259 timer = new javax.swing.Timer(100, status_update);
270 public TeleGPSStatus() {
271 layout = new GridBagLayout();
275 call = new Call(layout, 0);
276 serial = new Serial(layout, 1);
277 flight = new Flight(layout, 2);
278 rssi = new RSSI(layout, 4);
279 last_packet = new LastPacket(layout, 5);