Rev 1568 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1568 | - | 1 | package dongfang.mkt.ui.offscreendisplay; |
2 | |||
3 | import java.awt.BorderLayout; |
||
1570 | - | 4 | import java.awt.Font; |
1568 | - | 5 | import java.awt.GridLayout; |
6 | import java.util.Formatter; |
||
7 | import java.util.Locale; |
||
8 | import java.util.Timer; |
||
9 | import java.util.TimerTask; |
||
10 | |||
11 | import javax.swing.BorderFactory; |
||
12 | import javax.swing.JLabel; |
||
13 | import javax.swing.JPanel; |
||
14 | import javax.swing.JProgressBar; |
||
15 | import javax.swing.JSlider; |
||
16 | import javax.swing.border.Border; |
||
17 | |||
18 | import dongfang.mkt.frames.OSDDataResponseFrame; |
||
19 | |||
20 | public class VariousInfoPane extends JPanel implements OSDDataConsumer { |
||
1570 | - | 21 | |
22 | static class BigLabel extends JLabel { |
||
23 | public BigLabel() { |
||
24 | super(); |
||
25 | setFont(getFont().deriveFont(Font.BOLD, 16)); |
||
26 | } |
||
27 | } |
||
1568 | - | 28 | |
29 | class PositionsPanel extends JPanel implements OSDDataConsumer { |
||
30 | class CurrentPositionPanel extends JPanel { |
||
1570 | - | 31 | BigLabel lat; |
32 | BigLabel lon; |
||
1568 | - | 33 | |
34 | void init() { |
||
1570 | - | 35 | lat = new BigLabel(); |
36 | lon = new BigLabel(); |
||
1568 | - | 37 | } |
38 | |||
39 | int getNumRows() { |
||
40 | return 2; |
||
41 | } |
||
42 | |||
43 | void layoutSubs() { |
||
44 | add(new JLabel("lat")); |
||
45 | add(lat); |
||
46 | add(new JLabel("lon")); |
||
47 | add(lon); |
||
48 | } |
||
49 | |||
50 | CurrentPositionPanel() { |
||
51 | setLayout(new GridLayout(getNumRows(), 2)); |
||
52 | init(); |
||
53 | layoutSubs(); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | class HomePositionPanel extends CurrentPositionPanel { |
||
1570 | - | 58 | BigLabel home; |
1568 | - | 59 | |
60 | void init() { |
||
61 | super.init(); |
||
1570 | - | 62 | home = new BigLabel(); |
1568 | - | 63 | } |
64 | |||
65 | int getNumRows() { |
||
66 | return 3; |
||
67 | } |
||
68 | |||
69 | void layoutSubs() { |
||
70 | super.layoutSubs(); |
||
71 | add(new JLabel("home")); |
||
72 | add(home); |
||
73 | } |
||
74 | } |
||
75 | |||
76 | CurrentPositionPanel currentPosition = new CurrentPositionPanel(); |
||
77 | HomePositionPanel homePosition = new HomePositionPanel(); |
||
78 | |||
79 | public PositionsPanel() { |
||
80 | Border b = BorderFactory.createTitledBorder( |
||
81 | BorderFactory.createEtchedBorder(), "Curr pos"); |
||
82 | currentPosition.setBorder(b); |
||
83 | b = BorderFactory.createTitledBorder( |
||
84 | BorderFactory.createEtchedBorder(), "Home pos"); |
||
85 | homePosition.setBorder(b); |
||
86 | setLayout(new GridLayout(2, 1)); |
||
87 | add(currentPosition); |
||
88 | add(homePosition); |
||
89 | } |
||
90 | |||
91 | public void update(OSDDataResponseFrame data, long timestamp) { |
||
92 | if (data == null) |
||
93 | return; |
||
94 | |||
95 | String coordinateFormatString = "%+10.5f"; |
||
96 | |||
97 | StringBuilder sb = new StringBuilder(); |
||
98 | Formatter formatter = new Formatter(sb, Locale.US); |
||
99 | formatter.format(coordinateFormatString, data.getCurrentPosition() |
||
100 | .getLatitude()); |
||
101 | currentPosition.lat.setText(sb.toString()); |
||
102 | |||
103 | sb.setLength(0); |
||
104 | formatter.format(coordinateFormatString, data.getCurrentPosition() |
||
105 | .getLongitude()); |
||
106 | currentPosition.lon.setText(sb.toString()); |
||
107 | |||
108 | sb.setLength(0); |
||
109 | formatter.format(coordinateFormatString, data.getCurrentPosition() |
||
110 | .getLongitude()); |
||
111 | currentPosition.lon.setText(sb.toString()); |
||
112 | |||
113 | sb.setLength(0); |
||
114 | formatter.format(coordinateFormatString, data.getHomePosition() |
||
115 | .getLatitude()); |
||
116 | homePosition.lat.setText(sb.toString()); |
||
117 | |||
118 | sb.setLength(0); |
||
119 | formatter.format(coordinateFormatString, data.getHomePosition() |
||
120 | .getLongitude()); |
||
121 | homePosition.lon.setText(sb.toString()); |
||
122 | |||
123 | homePosition.home.setText(data.getCurrentToHome().toString()); |
||
124 | } |
||
125 | } |
||
126 | |||
127 | class HeightsPanel extends JPanel implements OSDDataConsumer { |
||
128 | class HeightPanel extends JPanel implements OSDDataConsumer { |
||
1570 | - | 129 | BigLabel baroHeight; |
130 | BigLabel GPSHeight; |
||
131 | BigLabel baroVVI; |
||
132 | BigLabel GPSVVI; |
||
1568 | - | 133 | |
134 | void init() { |
||
1570 | - | 135 | baroHeight = new BigLabel(); |
136 | GPSHeight = new BigLabel(); |
||
137 | baroVVI = new BigLabel(); |
||
138 | GPSVVI = new BigLabel(); |
||
1568 | - | 139 | } |
140 | |||
141 | int getNumRows() { |
||
142 | return 4; |
||
143 | } |
||
144 | |||
145 | void layoutSubs() { |
||
146 | add(new JLabel("BaroHeight")); |
||
147 | add(baroHeight); |
||
148 | add(new JLabel("baroVVI")); |
||
149 | add(baroVVI); |
||
150 | add(new JLabel("GPSHeight")); |
||
151 | add(GPSHeight); |
||
152 | add(new JLabel("GPSVVI")); |
||
153 | add(GPSVVI); |
||
154 | } |
||
155 | |||
156 | HeightPanel() { |
||
157 | setLayout(new GridLayout(getNumRows(), 2)); |
||
158 | } |
||
159 | |||
160 | public void update(OSDDataResponseFrame data, long timestamp) { |
||
161 | if (data == null) |
||
162 | return; |
||
163 | String heightFormatString = "%+10.1f"; |
||
164 | StringBuilder sb = new StringBuilder(); |
||
165 | Formatter formatter = new Formatter(sb, Locale.US); |
||
166 | formatter |
||
167 | .format(heightFormatString, data.getHeightByPressure()); |
||
168 | baroHeight.setText(sb.toString()); |
||
169 | |||
170 | sb.setLength(0); |
||
171 | double vviText = data.getVerticalVelocityByPressure(); |
||
172 | formatter.format(heightFormatString, vviText); |
||
173 | baroVVI.setText(sb.toString()); |
||
174 | |||
175 | sb.setLength(0); |
||
176 | double height = data.getCurrentPosition().getAltitude() |
||
177 | - data.getHomePosition().getAltitude(); |
||
178 | formatter.format(heightFormatString, height); |
||
179 | GPSHeight.setText(sb.toString()); |
||
180 | |||
181 | sb.setLength(0); |
||
182 | vviText = data.getVerticalVelocityByGPS(); |
||
183 | formatter.format(heightFormatString, vviText); |
||
184 | GPSVVI.setText(sb.toString()); |
||
185 | } |
||
186 | } |
||
187 | |||
188 | HeightPanel height; |
||
189 | JSlider vvi; |
||
190 | |||
191 | HeightsPanel() { |
||
192 | setLayout(new BorderLayout()); |
||
193 | vvi = new JSlider(-100, 100, 0); |
||
194 | vvi.setOrientation(JSlider.VERTICAL); |
||
195 | vvi.setEnabled(false); |
||
196 | add(vvi, BorderLayout.WEST); |
||
197 | height = new HeightPanel(); |
||
198 | height.init(); |
||
199 | height.layoutSubs(); |
||
200 | add(height, BorderLayout.CENTER); |
||
201 | setBorder(BorderFactory.createTitledBorder( |
||
202 | BorderFactory.createEtchedBorder(), "Altitude")); |
||
203 | } |
||
204 | |||
205 | public void update(OSDDataResponseFrame data, long timestamp) { |
||
206 | if (data == null) |
||
207 | return; |
||
208 | height.update(data, timestamp); |
||
209 | vvi.setValue((int) (data.getVerticalVelocityByPressure() * 50)); |
||
210 | } |
||
211 | } |
||
212 | |||
213 | class SpeedHeadingPanel extends JPanel implements OSDDataConsumer { |
||
1570 | - | 214 | BigLabel noseDirection; |
215 | BigLabel flightDirection; |
||
216 | BigLabel speed; |
||
1568 | - | 217 | |
218 | void init() { |
||
1570 | - | 219 | noseDirection = new BigLabel(); |
220 | flightDirection = new BigLabel(); |
||
221 | speed = new BigLabel(); |
||
1568 | - | 222 | Border b = BorderFactory.createTitledBorder( |
223 | BorderFactory.createEtchedBorder(), "Speed and heading"); |
||
224 | setBorder(b); |
||
225 | } |
||
226 | |||
227 | int getNumRows() { |
||
228 | return 3; |
||
229 | } |
||
230 | |||
231 | void layoutSubs() { |
||
232 | setLayout(new GridLayout(getNumRows(), 2)); |
||
233 | add(new JLabel("Nose")); |
||
234 | add(noseDirection); |
||
235 | add(new JLabel("Flight")); |
||
236 | add(flightDirection); |
||
237 | add(new JLabel("Speed")); |
||
238 | add(speed); |
||
239 | } |
||
240 | |||
241 | SpeedHeadingPanel() { |
||
242 | init(); |
||
243 | layoutSubs(); |
||
244 | } |
||
245 | |||
246 | public void update(OSDDataResponseFrame data, long timestamp) { |
||
247 | if (data == null) |
||
248 | return; |
||
249 | String speedFormatString = "%10.1f"; |
||
250 | StringBuilder sb = new StringBuilder(); |
||
251 | Formatter formatter = new Formatter(sb, Locale.US); |
||
252 | |||
253 | noseDirection.setText("" + data.getCompassHeading()); |
||
254 | flightDirection.setText("" + data.getDirectionOfFlight()); |
||
255 | |||
256 | formatter.format(speedFormatString, data.getGroundSpeed()); |
||
257 | speed.setText(sb.toString()); |
||
258 | } |
||
259 | } |
||
260 | |||
261 | class StatusPanel extends JPanel implements OSDDataConsumer { |
||
262 | JProgressBar dataAgeProgress; |
||
263 | JProgressBar battery; |
||
1570 | - | 264 | BigLabel numberOfSatellites; |
1568 | - | 265 | |
266 | long dataTime = 0; |
||
267 | |||
268 | void init() { |
||
269 | dataAgeProgress = new JProgressBar(0, 5000); |
||
270 | battery = new JProgressBar(100, 130); |
||
1570 | - | 271 | numberOfSatellites = new BigLabel(); |
1568 | - | 272 | |
273 | //dataAgeProgress.setEnabled(false); |
||
274 | Border b = BorderFactory.createTitledBorder( |
||
275 | BorderFactory.createEtchedBorder(), "Status"); |
||
276 | setBorder(b); |
||
277 | |||
278 | TimerTask dataAgeTask = new TimerTask() { |
||
279 | |||
280 | @Override |
||
281 | public void run() { |
||
282 | long age = System.currentTimeMillis() - dataTime; |
||
283 | if (age > 5000) age = 5000; |
||
284 | // System.out.println(age); |
||
285 | dataAgeProgress.setValue((int)age); |
||
286 | StatusPanel.this.repaint(); |
||
287 | } |
||
288 | }; |
||
289 | |||
290 | Timer t = new Timer(); |
||
291 | t.schedule(dataAgeTask, 0, 200); |
||
292 | } |
||
293 | |||
294 | int getNumRows() { |
||
1570 | - | 295 | return 3; |
1568 | - | 296 | } |
297 | |||
298 | void layoutSubs() { |
||
299 | add(new JLabel("Data age")); |
||
300 | add(dataAgeProgress); |
||
301 | add(new JLabel("Battery")); |
||
302 | add(battery); |
||
1570 | - | 303 | add(new JLabel("Satellites")); |
304 | add(numberOfSatellites); |
||
1568 | - | 305 | } |
306 | |||
307 | StatusPanel() { |
||
308 | setLayout(new GridLayout(getNumRows(), 2)); |
||
309 | init(); |
||
310 | layoutSubs(); |
||
311 | } |
||
312 | |||
313 | public void update(OSDDataResponseFrame data, long timestamp) { |
||
314 | if (data == null) |
||
315 | return; |
||
316 | dataTime = System.currentTimeMillis(); |
||
317 | battery.setValue(data.getBatteryVoltage()); |
||
1570 | - | 318 | numberOfSatellites.setText("" + data.getNumberOfSatellites()); |
1568 | - | 319 | } |
320 | } |
||
321 | |||
322 | StatusPanel status = new StatusPanel(); |
||
323 | PositionsPanel positions = new PositionsPanel(); |
||
324 | SpeedHeadingPanel speedHeading = new SpeedHeadingPanel(); |
||
325 | HeightsPanel altitudes = new HeightsPanel(); |
||
326 | |||
327 | public VariousInfoPane() { |
||
328 | } |
||
329 | |||
330 | public void init() { |
||
331 | setLayout(new GridLayout(0, 1)); |
||
332 | add(status); |
||
333 | add(positions); |
||
334 | add(speedHeading); |
||
335 | add(altitudes); |
||
336 | } |
||
337 | |||
338 | public void update(OSDDataResponseFrame data, long timestamp) { |
||
339 | status.update(data, timestamp); |
||
340 | positions.update(data, timestamp); |
||
341 | speedHeading.update(data, timestamp); |
||
342 | altitudes.update(data, timestamp); |
||
343 | } |
||
344 | |||
345 | public void setWidth(int width) { |
||
346 | positions.setSize(width, (int) positions.getSize().getHeight()); |
||
347 | altitudes.setSize(width, (int) altitudes.getSize().getHeight()); |
||
348 | } |
||
349 | } |