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.
18 package org.altusmetrum.telegps;
22 import org.altusmetrum.altoslib_4.*;
23 import org.altusmetrum.altosuilib_2.*;
25 public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
32 void show(AltosState state, AltosListenerState listener_state) {}
39 label.setFont(AltosUILib.status_font);
40 value.setFont(AltosUILib.status_font);
43 void setVisible(boolean visible) {
44 label.setVisible(visible);
45 value.setVisible(visible);
48 public Value (GridBagLayout layout, int x, String text) {
49 GridBagConstraints c = new GridBagConstraints();
50 c.insets = new Insets(5, 5, 5, 5);
51 c.anchor = GridBagConstraints.CENTER;
52 c.fill = GridBagConstraints.BOTH;
56 label = new JLabel(text);
57 label.setFont(AltosUILib.status_font);
58 label.setHorizontalAlignment(SwingConstants.CENTER);
59 c.gridx = x; c.gridy = 0;
60 layout.setConstraints(label, c);
63 value = new JTextField("");
64 value.setEditable(false);
65 value.setFont(AltosUILib.status_font);
66 value.setHorizontalAlignment(SwingConstants.CENTER);
67 c.gridx = x; c.gridy = 1;
68 layout.setConstraints(value, c);
73 class Call extends Value {
76 void show(AltosState state, AltosListenerState listener_state) {
77 if (state.callsign != call) {
78 value.setText(state.callsign);
79 call = state.callsign;
81 if (state.callsign == null)
86 public Call (GridBagLayout layout, int x) {
87 super (layout, x, "Callsign");
93 class Serial extends Value {
95 void show(AltosState state, AltosListenerState listener_state) {
96 if (state.serial != serial) {
97 if (state.serial == AltosLib.MISSING)
98 value.setText("none");
100 value.setText(String.format("%d", state.serial));
101 serial = state.serial;
104 public Serial (GridBagLayout layout, int x) {
105 super (layout, x, "Serial");
111 class RSSI extends Value {
114 void show(AltosState state, AltosListenerState listener_state) {
115 int new_rssi = state.rssi();
117 if (new_rssi != rssi) {
118 value.setText(String.format("%d", new_rssi));
119 if (state.rssi == AltosLib.MISSING)
126 public RSSI (GridBagLayout layout, int x) {
127 super (layout, x, "RSSI");
133 class LastPacket extends Value {
137 void show(AltosState state, AltosListenerState listener_state) {
138 long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
140 if (secs != last_secs) {
141 value.setText(String.format("%d", secs));
145 public LastPacket(GridBagLayout layout, int x) {
146 super (layout, x, "Age");
150 LastPacket last_packet;
152 public void reset () {
159 public void font_size_changed(int font_size) {
163 last_packet.set_font();
166 public void units_changed(boolean imperial_units) {
169 public void show (AltosState state, AltosListenerState listener_state) {
170 call.show(state, listener_state);
171 serial.show(state, listener_state);
172 rssi.show(state, listener_state);
173 last_packet.show(state, listener_state);
176 public int height() {
177 Dimension d = layout.preferredLayoutSize(this);
181 public TeleGPSStatus() {
182 layout = new GridBagLayout();
186 call = new Call(layout, 0);
187 serial = new Serial(layout, 1);
188 rssi = new RSSI(layout, 4);
189 last_packet = new LastPacket(layout, 5);