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_11.*;
24 import org.altusmetrum.altosuilib_11.*;
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 if (state.callsign != call) {
79 value.setText(state.callsign);
80 call = state.callsign;
82 if (state.callsign == null)
93 public Call (GridBagLayout layout, int x) {
94 super (layout, x, "Callsign");
100 class Serial extends Value {
102 void show(AltosState state, AltosListenerState listener_state) {
103 if (state.serial != serial) {
104 if (state.serial == AltosLib.MISSING)
105 value.setText("none");
107 value.setText(String.format("%d", state.serial));
108 serial = state.serial;
112 public void reset() {
117 public Serial (GridBagLayout layout, int x) {
118 super (layout, x, "Serial");
124 class Flight extends Value {
126 int last_flight = -1;
128 void show(AltosState state, AltosListenerState listener_state) {
129 if (state.flight != last_flight) {
130 if (state.flight == AltosLib.MISSING)
131 value.setText("none");
133 value.setText(String.format("%d", state.flight));
134 last_flight = state.flight;
138 public void reset() {
143 public Flight (GridBagLayout layout, int x) {
144 super (layout, x, "Flight");
150 class RSSI extends Value {
153 void show(AltosState state, AltosListenerState listener_state) {
154 int new_rssi = state.rssi();
156 if (new_rssi != rssi) {
157 value.setText(String.format("%d", new_rssi));
158 if (state.rssi == AltosLib.MISSING)
166 public void reset() {
171 public RSSI (GridBagLayout layout, int x) {
172 super (layout, x, "RSSI");
178 class LastPacket extends Value {
182 void show(AltosState state, AltosListenerState listener_state) {
183 if (listener_state.running) {
184 long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
186 if (secs != last_secs) {
187 value.setText(String.format("%d", secs));
191 value.setText("done");
204 public LastPacket(GridBagLayout layout, int x) {
205 super (layout, x, "Age");
209 LastPacket last_packet;
211 public void disable_receive() {
212 last_packet.disable();
215 public void reset () {
223 public void font_size_changed(int font_size) {
228 last_packet.set_font();
231 public void units_changed(boolean imperial_units) {
234 public void show (AltosState state, AltosListenerState listener_state) {
235 call.show(state, listener_state);
236 serial.show(state, listener_state);
237 flight.show(state, listener_state);
238 rssi.show(state, listener_state);
239 last_packet.show(state, listener_state);
240 if (!listener_state.running)
244 public int height() {
245 Dimension d = layout.preferredLayoutSize(this);
249 TeleGPSStatusUpdate status_update;
250 javax.swing.Timer timer;
252 public void start(TeleGPSStatusUpdate status_update) {
253 this.status_update = status_update;
254 timer = new javax.swing.Timer(100, status_update);
265 public TeleGPSStatus() {
266 layout = new GridBagLayout();
270 call = new Call(layout, 0);
271 serial = new Serial(layout, 1);
272 flight = new Flight(layout, 2);
273 rssi = new RSSI(layout, 4);
274 last_packet = new LastPacket(layout, 5);