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_3.*;
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 void setVisible(boolean visible) {
43 label.setVisible(visible);
44 value.setVisible(visible);
47 public FlightValue (GridBagLayout layout, int x, String text) {
48 GridBagConstraints c = new GridBagConstraints();
49 c.insets = new Insets(5, 5, 5, 5);
50 c.anchor = GridBagConstraints.CENTER;
51 c.fill = GridBagConstraints.BOTH;
55 label = new JLabel(text);
56 label.setFont(Altos.status_font);
57 label.setHorizontalAlignment(SwingConstants.CENTER);
58 c.gridx = x; c.gridy = 0;
59 layout.setConstraints(label, c);
62 value = new JTextField("");
63 value.setFont(Altos.status_font);
64 value.setHorizontalAlignment(SwingConstants.CENTER);
65 c.gridx = x; c.gridy = 1;
66 layout.setConstraints(value, c);
71 class Call extends FlightValue {
72 void show(AltosState state, AltosListenerState listener_state) {
73 value.setText(state.callsign);
74 if (state.callsign == null)
79 public Call (GridBagLayout layout, int x) {
80 super (layout, x, "Callsign");
86 class Serial extends FlightValue {
87 void show(AltosState state, AltosListenerState listener_state) {
88 if (state.serial == AltosLib.MISSING)
89 value.setText("none");
91 value.setText(String.format("%d", state.serial));
93 public Serial (GridBagLayout layout, int x) {
94 super (layout, x, "Serial");
100 class Flight extends FlightValue {
101 void show(AltosState state, AltosListenerState listener_state) {
102 if (state.flight == AltosLib.MISSING)
103 value.setText("none");
105 value.setText(String.format("%d", state.flight));
107 public Flight (GridBagLayout layout, int x) {
108 super (layout, x, "Flight");
114 class FlightState extends FlightValue {
115 void show(AltosState state, AltosListenerState listener_state) {
116 value.setText(state.state_name());
118 public FlightState (GridBagLayout layout, int x) {
119 super (layout, x, "State");
123 FlightState flight_state;
125 class RSSI extends FlightValue {
126 void show(AltosState state, AltosListenerState listener_state) {
127 value.setText(String.format("%d", state.rssi()));
128 if (state.rssi == AltosLib.MISSING)
133 public RSSI (GridBagLayout layout, int x) {
134 super (layout, x, "RSSI");
140 class LastPacket extends FlightValue {
141 void show(AltosState state, AltosListenerState listener_state) {
142 long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
143 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 () {
156 flight_state.reset();
161 public void set_font () {
165 flight_state.set_font();
167 last_packet.set_font();
170 public void show (AltosState state, AltosListenerState listener_state) {
171 call.show(state, listener_state);
172 serial.show(state, listener_state);
173 flight.show(state, listener_state);
174 flight_state.show(state, listener_state);
175 rssi.show(state, listener_state);
176 last_packet.show(state, listener_state);
179 public int height() {
180 Dimension d = layout.preferredLayoutSize(this);
184 public AltosFlightStatus() {
185 layout = new GridBagLayout();
189 call = new Call(layout, 0);
190 serial = new Serial(layout, 1);
191 flight = new Flight(layout, 2);
192 flight_state = new FlightState(layout, 3);
193 rssi = new RSSI(layout, 4);
194 last_packet = new LastPacket(layout, 5);