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.
22 import org.altusmetrum.AltosLib.*;
24 public class AltosFlightStatus extends JComponent implements AltosFlightDisplay {
27 public class FlightValue {
31 void show(AltosState state, int crc_errors) {}
38 label.setFont(Altos.status_font);
39 value.setFont(Altos.status_font);
42 public FlightValue (GridBagLayout layout, int x, String text) {
43 GridBagConstraints c = new GridBagConstraints();
44 c.insets = new Insets(5, 5, 5, 5);
45 c.anchor = GridBagConstraints.CENTER;
46 c.fill = GridBagConstraints.BOTH;
50 label = new JLabel(text);
51 label.setFont(Altos.status_font);
52 label.setHorizontalAlignment(SwingConstants.CENTER);
53 c.gridx = x; c.gridy = 0;
54 layout.setConstraints(label, c);
57 value = new JTextField("");
58 value.setFont(Altos.status_font);
59 value.setHorizontalAlignment(SwingConstants.CENTER);
60 c.gridx = x; c.gridy = 1;
61 layout.setConstraints(value, c);
66 class Call extends FlightValue {
67 void show(AltosState state, int crc_errors) {
68 value.setText(state.data.callsign);
70 public Call (GridBagLayout layout, int x) {
71 super (layout, x, "Callsign");
77 class Serial extends FlightValue {
78 void show(AltosState state, int crc_errors) {
79 value.setText(String.format("%d", state.data.serial));
81 public Serial (GridBagLayout layout, int x) {
82 super (layout, x, "Serial");
88 class Flight extends FlightValue {
89 void show(AltosState state, int crc_errors) {
90 value.setText(String.format("%d", state.data.flight));
92 public Flight (GridBagLayout layout, int x) {
93 super (layout, x, "Flight");
99 class FlightState extends FlightValue {
100 void show(AltosState state, int crc_errors) {
101 value.setText(state.data.state());
103 public FlightState (GridBagLayout layout, int x) {
104 super (layout, x, "State");
108 FlightState flight_state;
110 class RSSI extends FlightValue {
111 void show(AltosState state, int crc_errors) {
112 value.setText(String.format("%d", state.data.rssi));
114 public RSSI (GridBagLayout layout, int x) {
115 super (layout, x, "RSSI");
121 class LastPacket extends FlightValue {
122 void show(AltosState state, int crc_errors) {
123 long secs = (System.currentTimeMillis() - state.report_time + 500) / 1000;
124 value.setText(String.format("%d", secs));
126 public LastPacket(GridBagLayout layout, int x) {
127 super (layout, x, "Age");
131 LastPacket last_packet;
133 public void reset () {
137 flight_state.reset();
142 public void set_font () {
146 flight_state.set_font();
148 last_packet.set_font();
151 public void show (AltosState state, int crc_errors) {
152 call.show(state, crc_errors);
153 serial.show(state, crc_errors);
154 flight.show(state, crc_errors);
155 flight_state.show(state, crc_errors);
156 rssi.show(state, crc_errors);
157 last_packet.show(state, crc_errors);
160 public int height() {
161 Dimension d = layout.preferredLayoutSize(this);
165 public AltosFlightStatus() {
166 layout = new GridBagLayout();
170 call = new Call(layout, 0);
171 serial = new Serial(layout, 1);
172 flight = new Flight(layout, 2);
173 flight_state = new FlightState(layout, 3);
174 rssi = new RSSI(layout, 4);
175 last_packet = new LastPacket(layout, 5);