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