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.
21 import java.awt.event.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.LinkedBlockingQueue;
30 import org.altusmetrum.AltosLib.*;
32 public class AltosFlightStatus extends JComponent implements AltosFlightDisplay {
35 public class FlightValue {
39 void show(AltosState state, int crc_errors) {}
46 label.setFont(Altos.status_font);
47 value.setFont(Altos.status_font);
50 public FlightValue (GridBagLayout layout, int x, String text) {
51 GridBagConstraints c = new GridBagConstraints();
52 c.insets = new Insets(5, 5, 5, 5);
53 c.anchor = GridBagConstraints.CENTER;
54 c.fill = GridBagConstraints.BOTH;
58 label = new JLabel(text);
59 label.setFont(Altos.status_font);
60 label.setHorizontalAlignment(SwingConstants.CENTER);
61 c.gridx = x; c.gridy = 0;
62 layout.setConstraints(label, c);
65 value = new JTextField("");
66 value.setFont(Altos.status_font);
67 value.setHorizontalAlignment(SwingConstants.CENTER);
68 c.gridx = x; c.gridy = 1;
69 layout.setConstraints(value, c);
74 class Call extends FlightValue {
75 void show(AltosState state, int crc_errors) {
76 value.setText(state.data.callsign);
78 public Call (GridBagLayout layout, int x) {
79 super (layout, x, "Callsign");
85 class Serial extends FlightValue {
86 void show(AltosState state, int crc_errors) {
87 value.setText(String.format("%d", state.data.serial));
89 public Serial (GridBagLayout layout, int x) {
90 super (layout, x, "Serial");
96 class Flight extends FlightValue {
97 void show(AltosState state, int crc_errors) {
98 value.setText(String.format("%d", state.data.flight));
100 public Flight (GridBagLayout layout, int x) {
101 super (layout, x, "Flight");
107 class FlightState extends FlightValue {
108 void show(AltosState state, int crc_errors) {
109 value.setText(state.data.state());
111 public FlightState (GridBagLayout layout, int x) {
112 super (layout, x, "State");
116 FlightState flight_state;
118 class RSSI extends FlightValue {
119 void show(AltosState state, int crc_errors) {
120 value.setText(String.format("%d", state.data.rssi));
122 public RSSI (GridBagLayout layout, int x) {
123 super (layout, x, "RSSI");
129 class LastPacket extends FlightValue {
130 void show(AltosState state, int crc_errors) {
131 long secs = (System.currentTimeMillis() - state.report_time + 500) / 1000;
132 value.setText(String.format("%d", secs));
134 public LastPacket(GridBagLayout layout, int x) {
135 super (layout, x, "Age");
139 LastPacket last_packet;
141 public void reset () {
145 flight_state.reset();
150 public void set_font () {
154 flight_state.set_font();
156 last_packet.set_font();
159 public void show (AltosState state, int crc_errors) {
160 call.show(state, crc_errors);
161 serial.show(state, crc_errors);
162 flight.show(state, crc_errors);
163 flight_state.show(state, crc_errors);
164 rssi.show(state, crc_errors);
165 last_packet.show(state, crc_errors);
168 public int height() {
169 Dimension d = layout.preferredLayoutSize(this);
173 public AltosFlightStatus() {
174 layout = new GridBagLayout();
178 call = new Call(layout, 0);
179 serial = new Serial(layout, 1);
180 flight = new Flight(layout, 2);
181 flight_state = new FlightState(layout, 3);
182 rssi = new RSSI(layout, 4);
183 last_packet = new LastPacket(layout, 5);