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.cal_data == null)
79 System.out.printf("null cal data?\n");
80 if (state.cal_data.callsign != call) {
81 value.setText(state.cal_data.callsign);
82 call = state.cal_data.callsign;
84 if (state.cal_data.callsign == null)
95 public Call (GridBagLayout layout, int x) {
96 super (layout, x, "Callsign");
102 class Serial extends Value {
104 void show(AltosState state, AltosListenerState listener_state) {
105 if (state.cal_data.serial != serial) {
106 if (state.cal_data.serial == AltosLib.MISSING)
107 value.setText("none");
109 value.setText(String.format("%d", state.cal_data.serial));
110 serial = state.cal_data.serial;
114 public void reset() {
119 public Serial (GridBagLayout layout, int x) {
120 super (layout, x, "Serial");
126 class Flight extends Value {
128 int last_flight = -1;
130 void show(AltosState state, AltosListenerState listener_state) {
131 if (state.cal_data.flight != last_flight) {
132 if (state.cal_data.flight == AltosLib.MISSING)
133 value.setText("none");
135 value.setText(String.format("%d", state.cal_data.flight));
136 last_flight = state.cal_data.flight;
140 public void reset() {
145 public Flight (GridBagLayout layout, int x) {
146 super (layout, x, "Flight");
152 class RSSI extends Value {
155 void show(AltosState state, AltosListenerState listener_state) {
156 int new_rssi = state.rssi();
158 if (new_rssi != rssi) {
159 value.setText(String.format("%d", new_rssi));
160 if (state.rssi == AltosLib.MISSING)
168 public void reset() {
173 public RSSI (GridBagLayout layout, int x) {
174 super (layout, x, "RSSI");
180 class LastPacket extends Value {
184 void show(AltosState state, AltosListenerState listener_state) {
185 if (listener_state.running) {
186 long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
188 if (secs != last_secs) {
189 value.setText(String.format("%d", secs));
193 value.setText("done");
206 public LastPacket(GridBagLayout layout, int x) {
207 super (layout, x, "Age");
211 LastPacket last_packet;
213 public void disable_receive() {
214 last_packet.disable();
217 public void reset () {
225 public void font_size_changed(int font_size) {
230 last_packet.set_font();
233 public void units_changed(boolean imperial_units) {
236 public void show (AltosState state, AltosListenerState listener_state) {
237 call.show(state, listener_state);
238 serial.show(state, listener_state);
239 flight.show(state, listener_state);
240 rssi.show(state, listener_state);
241 last_packet.show(state, listener_state);
242 if (!listener_state.running)
246 public int height() {
247 Dimension d = layout.preferredLayoutSize(this);
251 TeleGPSStatusUpdate status_update;
252 javax.swing.Timer timer;
254 public void start(TeleGPSStatusUpdate status_update) {
255 this.status_update = status_update;
256 timer = new javax.swing.Timer(100, status_update);
267 public TeleGPSStatus() {
268 layout = new GridBagLayout();
272 call = new Call(layout, 0);
273 serial = new Serial(layout, 1);
274 flight = new Flight(layout, 2);
275 rssi = new RSSI(layout, 4);
276 last_packet = new LastPacket(layout, 5);