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_4.*;
23 import org.altusmetrum.altosuilib_2.*;
25 public class AltosFlightStatus extends JComponent implements AltosFlightDisplay {
28 public class FlightValue {
32 void show(AltosState state, AltosListenerState listener_state) {}
39 label.setFont(Altos.status_font);
40 value.setFont(Altos.status_font);
43 void setVisible(boolean visible) {
44 label.setVisible(visible);
45 value.setVisible(visible);
48 public FlightValue (GridBagLayout layout, int x, String text) {
49 GridBagConstraints c = new GridBagConstraints();
50 c.insets = new Insets(5, 5, 5, 5);
51 c.anchor = GridBagConstraints.CENTER;
52 c.fill = GridBagConstraints.BOTH;
56 label = new JLabel(text);
57 label.setFont(Altos.status_font);
58 label.setHorizontalAlignment(SwingConstants.CENTER);
59 c.gridx = x; c.gridy = 0;
60 layout.setConstraints(label, c);
63 value = new JTextField("");
64 value.setFont(Altos.status_font);
65 value.setHorizontalAlignment(SwingConstants.CENTER);
66 c.gridx = x; c.gridy = 1;
67 layout.setConstraints(value, c);
72 class Call extends FlightValue {
73 void show(AltosState state, AltosListenerState listener_state) {
74 value.setText(state.callsign);
75 if (state.callsign == null)
80 public Call (GridBagLayout layout, int x) {
81 super (layout, x, "Callsign");
87 class Serial extends FlightValue {
88 void show(AltosState state, AltosListenerState listener_state) {
89 if (state.serial == AltosLib.MISSING)
90 value.setText("none");
92 value.setText(String.format("%d", state.serial));
94 public Serial (GridBagLayout layout, int x) {
95 super (layout, x, "Serial");
101 class Flight extends FlightValue {
102 void show(AltosState state, AltosListenerState listener_state) {
103 if (state.flight == AltosLib.MISSING)
104 value.setText("none");
106 value.setText(String.format("%d", state.flight));
108 public Flight (GridBagLayout layout, int x) {
109 super (layout, x, "Flight");
115 class FlightState extends FlightValue {
116 void show(AltosState state, AltosListenerState listener_state) {
117 value.setText(state.state_name());
119 public FlightState (GridBagLayout layout, int x) {
120 super (layout, x, "State");
124 FlightState flight_state;
126 class RSSI extends FlightValue {
127 void show(AltosState state, AltosListenerState listener_state) {
128 value.setText(String.format("%d", state.rssi()));
129 if (state.rssi == AltosLib.MISSING)
134 public RSSI (GridBagLayout layout, int x) {
135 super (layout, x, "RSSI");
141 class LastPacket extends FlightValue {
142 void show(AltosState state, AltosListenerState listener_state) {
143 long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
144 value.setText(String.format("%d", secs));
146 public LastPacket(GridBagLayout layout, int x) {
147 super (layout, x, "Age");
151 LastPacket last_packet;
153 public void reset () {
157 flight_state.reset();
162 public void set_font () {
166 flight_state.set_font();
168 last_packet.set_font();
171 public void show (AltosState state, AltosListenerState listener_state) {
172 call.show(state, listener_state);
173 serial.show(state, listener_state);
174 flight.show(state, listener_state);
175 flight_state.show(state, listener_state);
176 rssi.show(state, listener_state);
177 last_packet.show(state, listener_state);
180 public int height() {
181 Dimension d = layout.preferredLayoutSize(this);
185 public AltosFlightStatus() {
186 layout = new GridBagLayout();
190 call = new Call(layout, 0);
191 serial = new Serial(layout, 1);
192 flight = new Flight(layout, 2);
193 flight_state = new FlightState(layout, 3);
194 rssi = new RSSI(layout, 4);
195 last_packet = new LastPacket(layout, 5);