Subversion Repositories Projects

Rev

Rev 1568 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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