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_1.*;
24 public class AltosFlightStatus extends JComponent implements AltosFlightDisplay {
27 public class FlightValue {
31 void show(AltosState state, AltosListenerState listener_state) {}
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, AltosListenerState listener_state) {
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, AltosListenerState listener_state) {
79 if (state.data.serial == AltosRecord.MISSING)
80 value.setText("none");
82 value.setText(String.format("%d", state.data.serial));
84 public Serial (GridBagLayout layout, int x) {
85 super (layout, x, "Serial");
91 class Flight extends FlightValue {
92 void show(AltosState state, AltosListenerState listener_state) {
93 if (state.data.flight == AltosRecord.MISSING)
94 value.setText("none");
96 value.setText(String.format("%d", state.data.flight));
98 public Flight (GridBagLayout layout, int x) {
99 super (layout, x, "Flight");
105 class FlightState extends FlightValue {
106 void show(AltosState state, AltosListenerState listener_state) {
107 value.setText(state.data.state());
109 public FlightState (GridBagLayout layout, int x) {
110 super (layout, x, "State");
114 FlightState flight_state;
116 class RSSI extends FlightValue {
117 void show(AltosState state, AltosListenerState listener_state) {
118 value.setText(String.format("%d", state.data.rssi));
120 public RSSI (GridBagLayout layout, int x) {
121 super (layout, x, "RSSI");
127 class LastPacket extends FlightValue {
128 void show(AltosState state, AltosListenerState listener_state) {
129 long secs = (System.currentTimeMillis() - state.report_time + 500) / 1000;
130 value.setText(String.format("%d", secs));
132 public LastPacket(GridBagLayout layout, int x) {
133 super (layout, x, "Age");
137 LastPacket last_packet;
139 public void reset () {
143 flight_state.reset();
148 public void set_font () {
152 flight_state.set_font();
154 last_packet.set_font();
157 public void show (AltosState state, AltosListenerState listener_state) {
158 call.show(state, listener_state);
159 serial.show(state, listener_state);
160 flight.show(state, listener_state);
161 flight_state.show(state, listener_state);
162 rssi.show(state, listener_state);
163 last_packet.show(state, listener_state);
166 public int height() {
167 Dimension d = layout.preferredLayoutSize(this);
171 public AltosFlightStatus() {
172 layout = new GridBagLayout();
176 call = new Call(layout, 0);
177 serial = new Serial(layout, 1);
178 flight = new Flight(layout, 2);
179 flight_state = new FlightState(layout, 3);
180 rssi = new RSSI(layout, 4);
181 last_packet = new LastPacket(layout, 5);