altosui: remove un-used import
[fw/altos] / altosui / AltosFlightStatus.java
1 /*
2  * Copyright © 2010 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 package altosui;
19
20 import java.awt.*;
21 import javax.swing.*;
22 import org.altusmetrum.AltosLib.*;
23
24 public class AltosFlightStatus extends JComponent implements AltosFlightDisplay {
25         GridBagLayout   layout;
26
27         public class FlightValue {
28                 JLabel          label;
29                 JTextField      value;
30
31                 void show(AltosState state, int crc_errors) {}
32
33                 void reset() {
34                         value.setText("");
35                 }
36
37                 void set_font() {
38                         label.setFont(Altos.status_font);
39                         value.setFont(Altos.status_font);
40                 }
41
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;
47                         c.weightx = 1;
48                         c.weighty = 1;
49
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);
55                         add(label);
56
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);
62                         add(value);
63                 }
64         }
65
66         class Call extends FlightValue {
67                 void show(AltosState state, int crc_errors) {
68                         value.setText(state.data.callsign);
69                 }
70                 public Call (GridBagLayout layout, int x) {
71                         super (layout, x, "Callsign");
72                 }
73         }
74
75         Call call;
76
77         class Serial extends FlightValue {
78                 void show(AltosState state, int crc_errors) {
79                         value.setText(String.format("%d", state.data.serial));
80                 }
81                 public Serial (GridBagLayout layout, int x) {
82                         super (layout, x, "Serial");
83                 }
84         }
85
86         Serial serial;
87
88         class Flight extends FlightValue {
89                 void show(AltosState state, int crc_errors) {
90                         value.setText(String.format("%d", state.data.flight));
91                 }
92                 public Flight (GridBagLayout layout, int x) {
93                         super (layout, x, "Flight");
94                 }
95         }
96
97         Flight flight;
98
99         class FlightState extends FlightValue {
100                 void show(AltosState state, int crc_errors) {
101                         value.setText(state.data.state());
102                 }
103                 public FlightState (GridBagLayout layout, int x) {
104                         super (layout, x, "State");
105                 }
106         }
107
108         FlightState flight_state;
109
110         class RSSI extends FlightValue {
111                 void show(AltosState state, int crc_errors) {
112                         value.setText(String.format("%d", state.data.rssi));
113                 }
114                 public RSSI (GridBagLayout layout, int x) {
115                         super (layout, x, "RSSI");
116                 }
117         }
118
119         RSSI rssi;
120
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));
125                 }
126                 public LastPacket(GridBagLayout layout, int x) {
127                         super (layout, x, "Age");
128                 }
129         }
130
131         LastPacket last_packet;
132
133         public void reset () {
134                 call.reset();
135                 serial.reset();
136                 flight.reset();
137                 flight_state.reset();
138                 rssi.reset();
139                 last_packet.reset();
140         }
141
142         public void set_font () {
143                 call.set_font();
144                 serial.set_font();
145                 flight.set_font();
146                 flight_state.set_font();
147                 rssi.set_font();
148                 last_packet.set_font();
149         }
150
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);
158         }
159
160         public int height() {
161                 Dimension d = layout.preferredLayoutSize(this);
162                 return d.height;
163         }
164
165         public AltosFlightStatus() {
166                 layout = new GridBagLayout();
167
168                 setLayout(layout);
169
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);
176         }
177 }