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 (dBm)");
129 public void reset () {
133 flight_state.reset();
137 public void set_font () {
141 flight_state.set_font();
145 public void show (AltosState state, int crc_errors) {
146 call.show(state, crc_errors);
147 serial.show(state, crc_errors);
148 flight.show(state, crc_errors);
149 flight_state.show(state, crc_errors);
150 rssi.show(state, crc_errors);
153 public int height() {
154 Dimension d = layout.preferredLayoutSize(this);
158 public AltosFlightStatus() {
159 layout = new GridBagLayout();
163 call = new Call(layout, 0);
164 serial = new Serial(layout, 1);
165 flight = new Flight(layout, 2);
166 flight_state = new FlightState(layout, 3);
167 rssi = new RSSI(layout, 4);