826220679@qq.com
2 天以前 48ee74129bb09a817a0bbbabe860c4007b74c66b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
package baseStation;
 
import javax.swing.*;
 
import gecaoji.Device;
import publicway.buttonset;
 
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Properties;
 
public class BaseStationDialog extends JDialog {
    private final Color THEME_COLOR;
    private final Device device;
    private final BaseStation baseStation;
    private JLabel deviceIdLabel;
    private JLabel statusLabel;
    private JLabel updateTimeLabel;
    private JLabel positionLabel;
    private JLabel simCardLabel;
    private Timer refreshTimer;
 
    public BaseStationDialog(Component parent, Color themeColor, Device device, BaseStation baseStation) {
        super(resolveOwner(parent), "基准站信息", Dialog.ModalityType.APPLICATION_MODAL);
        this.THEME_COLOR = themeColor;
        this.device = device;
        this.baseStation = baseStation != null ? baseStation : new BaseStation();
        this.baseStation.load();
        initializeDialog(400, 800);
        initializeBaseStationContent();
        startRefreshTimer();
        if (getOwner() == null) {
            setLocationRelativeTo(null);
        }
    }
 
    private static Window resolveOwner(Component parent) {
        if (parent instanceof Window) {
            return (Window) parent;
        }
        if (parent != null) {
            Window owner = SwingUtilities.getWindowAncestor(parent);
            if (owner != null) {
                return owner;
            }
        }
        return null;
    }
    
    private void initializeDialog(int width, int height) {
        setSize(width, height);
        setPreferredSize(new Dimension(width, height));
        setMinimumSize(new Dimension(width, height));
        setLocationRelativeTo(getParent());
        setResizable(false);
        getContentPane().setBackground(Color.WHITE);
    }
    
    private void initializeBaseStationContent() {
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
        contentPanel.setBorder(BorderFactory.createEmptyBorder(25, 10, 25, 25)); // 左边距改为10像素
        contentPanel.setBackground(Color.WHITE);
        
        JPanel deviceIdPanel = createHorizontalInfoPanel("基准站编号:", getDeviceIdDisplay(), Color.BLACK);
        contentPanel.add(deviceIdPanel);
        contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
 
        // 状态信息
        JPanel statusPanel = createHorizontalInfoPanel("基准站状态:", getStatusText(), getStatusColor());
        contentPanel.add(statusPanel);
        contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
        
        // 数据更新时间
        JPanel updateTimePanel = createHorizontalInfoPanel("数据更新时间:", getUpdateTimeDisplay(), Color.BLACK);
        contentPanel.add(updateTimePanel);
        contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
        
        // 基准站位置
        JPanel positionPanel = createHorizontalInfoPanel("基准站位置:", getBaseStationPositionDisplay(), Color.BLACK);
        contentPanel.add(positionPanel);
        contentPanel.add(Box.createRigidArea(new Dimension(0, 30)));
 
        JPanel simCardPanel = createHorizontalInfoPanel("基准站卡号:", getSimCardDisplay(), Color.BLACK);
        contentPanel.add(simCardPanel);
        contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
 
        JPanel tutorialRow = createActionPanel("查看安装教程", "查看", new Color(70, 130, 180), e -> showInstallationTutorial());
        contentPanel.add(tutorialRow);
        contentPanel.add(Box.createRigidArea(new Dimension(0, 12)));
 
        JPanel lockRow = createActionPanel("锁定基准站位置", "锁定", THEME_COLOR, e -> lockBaseStationPosition());
        contentPanel.add(lockRow);
        contentPanel.add(Box.createRigidArea(new Dimension(0, 30)));
        
        // 按钮面板
        contentPanel.add(Box.createVerticalGlue());
        
        getContentPane().add(contentPanel);
        refreshLabels();
    }
    
    private JPanel createHorizontalInfoPanel(String title, String value, Color valueColor) {
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
        panel.setBackground(Color.WHITE);
        panel.setAlignmentX(Component.LEFT_ALIGNMENT);
        panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 40));
        
        JLabel titleLabel = new JLabel(title);
        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 14));
        titleLabel.setForeground(Color.DARK_GRAY);
        titleLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        // 创建值标签(不再使用文本框)
        JLabel valueLabel = new JLabel(value);
        valueLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
        valueLabel.setForeground(valueColor);
        valueLabel.setBackground(Color.WHITE);
        valueLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
        
        // 根据字段类型保存引用
        if ("基准站编号:".equals(title)) {
            deviceIdLabel = valueLabel;
        } else if ("基准站状态:".equals(title)) {
            statusLabel = valueLabel;
        } else if ("数据更新时间:".equals(title)) {
            updateTimeLabel = valueLabel;
        } else if ("基准站位置:".equals(title)) {
            positionLabel = valueLabel;
            final Color clickableColor = THEME_COLOR != null ? THEME_COLOR : new Color(70, 130, 180);
            titleLabel.setForeground(clickableColor);
            titleLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            titleLabel.setToolTipText("点击修改基准站位置");
            titleLabel.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 1) {
                        promptEditBaseStationPosition();
                    }
                }
 
                @Override
                public void mouseEntered(MouseEvent e) {
                    titleLabel.setForeground(brightenColor(clickableColor));
                }
 
                @Override
                public void mouseExited(MouseEvent e) {
                    titleLabel.setForeground(clickableColor);
                }
            });
        } else if ("基准站卡号:".equals(title)) {
            simCardLabel = valueLabel;
        }
        
        // 修改布局:标题和值标签都左对齐,中间添加3像素间隔
        panel.add(titleLabel);
        panel.add(Box.createRigidArea(new Dimension(3, 0))); // 添加3像素间隔
        panel.add(valueLabel);
        
        return panel;
    }
 
    private void promptEditBaseStationPosition() {
        if (baseStation == null) {
            JOptionPane.showMessageDialog(this,
                    "基准站信息未初始化,无法修改位置。",
                    "错误",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }
 
        baseStation.load();
 
        String currentRaw = baseStation.getInstallationCoordinates();
        String normalizedCurrent = canonicalizeCoordinateValue(currentRaw);
        boolean hasExistingCoordinate = normalizedCurrent != null && !"-1".equals(normalizedCurrent);
 
        JTextField inputField = new JTextField(hasExistingCoordinate ? normalizedCurrent : "");
        inputField.setColumns(28);
 
        JPanel dialogPanel = new JPanel(new BorderLayout(0, 8));
        JLabel hintLabel = new JLabel("请输入新的基准站坐标(示例:3949.90238860,N,11616.75692000,E)");
        hintLabel.setFont(new Font("微软雅黑", Font.PLAIN, 12));
        dialogPanel.add(hintLabel, BorderLayout.NORTH);
        dialogPanel.add(inputField, BorderLayout.CENTER);
 
        JOptionPane optionPane = new JOptionPane(dialogPanel,
            JOptionPane.PLAIN_MESSAGE,
            JOptionPane.OK_CANCEL_OPTION);
        JDialog dialog = optionPane.createDialog(this, "修改基准站位置");
        dialog.setModal(true);
        dialog.pack();
 
        Dimension packedSize = dialog.getSize();
        Window ownerWindow = getOwner();
        int referenceWidth = ownerWindow != null ? ownerWindow.getWidth() : getWidth();
        if (referenceWidth <= 0) {
            referenceWidth = 400;
        }
        dialog.setSize(new Dimension(referenceWidth, packedSize.height));
        dialog.setResizable(false);
        dialog.setLocationRelativeTo(this);
        dialog.setVisible(true);
        Object selectedValue = optionPane.getValue();
        if (!(selectedValue instanceof Integer) || ((Integer) selectedValue) != JOptionPane.OK_OPTION) {
            return;
        }
 
        String userInput = inputField.getText();
        if (userInput == null) {
            return;
        }
 
        String trimmed = userInput.trim();
        if (trimmed.isEmpty()) {
            int confirm = JOptionPane.showConfirmDialog(this,
                    "未输入坐标,保存后将视为未安装状态,是否继续?",
                    "确认",
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.WARNING_MESSAGE);
            if (confirm != JOptionPane.OK_OPTION) {
                return;
            }
        }
 
        String valueToSave = trimmed.isEmpty() ? "-1" : canonicalizeCoordinateValue(trimmed);
 
        if (!"-1".equals(valueToSave) && !looksLikeCoordinateFormat(valueToSave)) {
            int confirm = JOptionPane.showConfirmDialog(this,
                    "坐标格式似乎不符合“纬度,方向,经度,方向”的预期,仍然保存吗?",
                    "格式确认",
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.WARNING_MESSAGE);
            if (confirm != JOptionPane.OK_OPTION) {
                return;
            }
        }
 
        if (normalizedCurrent.equals(valueToSave)) {
            JOptionPane.showMessageDialog(this,
                    "基准站位置未发生变化。",
                    "提示",
                    JOptionPane.INFORMATION_MESSAGE);
            return;
        }
 
        baseStation.updateInstallationCoordinates(valueToSave);
        baseStation.load();
 
        if (device != null) {
            device.setBaseStationCoordinates(valueToSave);
            updatePropertiesFile("baseStationCoordinates", valueToSave);
        }
 
        refreshLabels();
 
        JOptionPane.showMessageDialog(this,
                "基准站位置已更新。",
                "更新成功",
                JOptionPane.INFORMATION_MESSAGE);
    }
 
    private boolean looksLikeCoordinateFormat(String value) {
        if (value == null) {
            return false;
        }
        String[] parts = value.split(",");
        if (parts.length != 4) {
            return false;
        }
        for (String part : parts) {
            if (part.trim().isEmpty()) {
                return false;
            }
        }
        return true;
    }
    
    private JPanel createActionPanel(String title, String buttonText, Color buttonColor, ActionListener actionListener) {
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
        panel.setBackground(Color.WHITE);
        panel.setAlignmentX(Component.LEFT_ALIGNMENT);
        panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 45));
 
        JLabel titleLabel = new JLabel(title);
        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 14));
        titleLabel.setForeground(Color.DARK_GRAY);
 
        JButton actionButton = buttonset.createStyledButton(buttonText, buttonColor);
        actionButton.addActionListener(actionListener);
 
        panel.add(titleLabel);
        panel.add(Box.createHorizontalGlue());
        panel.add(actionButton);
 
        return panel;
    }
    
    private Color brightenColor(Color color) {
        int r = Math.min(255, color.getRed() + 30);
        int g = Math.min(255, color.getGreen() + 30);
        int b = Math.min(255, color.getBlue() + 30);
        return new Color(r, g, b);
    }
    
    private void startRefreshTimer() {
        refreshTimer = new Timer(1000, e -> refreshLabels());
        refreshTimer.start();
    }
 
    private void refreshLabels() {
        if (baseStation != null) {
            baseStation.load();
        }
 
        if (deviceIdLabel != null) {
            deviceIdLabel.setText(getDeviceIdDisplay());
        }
 
        if (statusLabel != null) {
            statusLabel.setText(getStatusText());
            statusLabel.setForeground(getStatusColor());
        }
 
        if (updateTimeLabel != null) {
            updateTimeLabel.setText(getUpdateTimeDisplay());
        }
 
        if (positionLabel != null) {
            positionLabel.setText(getBaseStationPositionDisplay());
        }
 
        if (simCardLabel != null) {
            simCardLabel.setText(getSimCardDisplay());
        }
    }
 
    public void refreshData() {
        refreshLabels();
    }
    
    private String getDeviceIdDisplay() {
        if (baseStation == null) {
            return "未录入";
        }
        String deviceId = baseStation.getDeviceId();
        if (deviceId == null) {
            return "未录入";
        }
        String trimmed = deviceId.trim();
        if (trimmed.isEmpty() || "-1".equals(trimmed)) {
            return "未录入";
        }
        return trimmed;
    }
 
    private String getStatusText() {
        long updateMillis = getLastUpdateTimeMillis();
        if (updateMillis <= 0) {
            return "离线 ✗";
        }
        long diff = System.currentTimeMillis() - updateMillis;
        return diff < 10_000 ? "在线 ✓" : "离线 ✗";
    }
    
    private Color getStatusColor() {
        long updateMillis = getLastUpdateTimeMillis();
        if (updateMillis > 0 && System.currentTimeMillis() - updateMillis < 10_000) {
            return new Color(0, 150, 0);
        }
        return Color.GRAY;
    }
    
    private String getUpdateTimeDisplay() {
        long updateMillis = getLastUpdateTimeMillis();
        if (updateMillis <= 0) {
            return "初始化无数据";
        }
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return sdf.format(new Date(updateMillis));
        } catch (Exception e) {
            return String.valueOf(updateMillis);
        }
    }
    
    private String getBaseStationPositionDisplay() {
        if (baseStation == null) {
            return "设备没有安装固定";
        }
        String coordinates = baseStation.getInstallationCoordinates();
        String canonical = canonicalizeCoordinateValue(coordinates);
        if (canonical == null || "-1".equals(canonical)) {
            return "设备没有安装固定";
        }
        return canonical;
    }
 
    private String getSimCardDisplay() {
        if (baseStation == null) {
            return "未绑定";
        }
        String number = baseStation.getIotSimCardNumber();
        if (number == null) {
            return "未绑定";
        }
        String trimmed = number.trim();
        if (trimmed.isEmpty() || "-1".equals(trimmed)) {
            return "未绑定";
        }
        return trimmed;
    }
 
    private long getLastUpdateTimeMillis() {
        if (baseStation == null) {
            return -1;
        }
        String updateTime = baseStation.getDataUpdateTime();
        if (updateTime == null) {
            return -1;
        }
        String trimmed = updateTime.trim();
        if (trimmed.isEmpty() || "-1".equals(trimmed)) {
            return -1;
        }
        try {
            long value = Long.parseLong(trimmed);
            if (value < 1_000_000_000_000L) {
                return value * 1000;
            }
            return value;
        } catch (NumberFormatException e) {
            return -1;
        }
    }
 
    private boolean hasBaseStationId() {
        if (baseStation == null) {
            return false;
        }
        String deviceId = baseStation.getDeviceId();
        if (deviceId == null) {
            return false;
        }
        String trimmed = deviceId.trim();
        return !trimmed.isEmpty() && !"-1".equals(trimmed);
    }
    
    // Normalizes coordinate strings into degree-minute format when possible for consistent display/storage
    private String canonicalizeCoordinateValue(String value) {
        if (value == null) {
            return "-1";
        }
        String trimmed = value.trim();
        if (trimmed.isEmpty() || "-1".equals(trimmed)) {
            return "-1";
        }
        String[] parts = trimmed.split(",");
        if (parts.length != 4) {
            return trimmed;
        }
        String latDirRaw = parts[1] == null ? "" : parts[1].trim();
        String lonDirRaw = parts[3] == null ? "" : parts[3].trim();
        if (latDirRaw.isEmpty() || lonDirRaw.isEmpty()) {
            return trimmed;
        }
        String latDir = latDirRaw.toUpperCase(Locale.ROOT);
        String lonDir = lonDirRaw.toUpperCase(Locale.ROOT);
        if (!isValidDirection(latDir, true) || !isValidDirection(lonDir, false)) {
            return trimmed;
        }
        String formattedLat = convertToDegreeMinuteString(parts[0], latDir, true);
        String formattedLon = convertToDegreeMinuteString(parts[2], lonDir, false);
        if (formattedLat == null || formattedLon == null) {
            return trimmed;
        }
        return formattedLat + "," + latDir + "," + formattedLon + "," + lonDir;
    }
 
    private boolean isValidDirection(String direction, boolean isLatitude) {
        if (direction == null) {
            return false;
        }
        if (isLatitude) {
            return "N".equals(direction) || "S".equals(direction);
        }
        return "E".equals(direction) || "W".equals(direction);
    }
 
    // Converts decimal degrees or degree-minute input into a canonical degree-minute string (8 decimal places)
    private String convertToDegreeMinuteString(String rawValue, String direction, boolean isLatitude) {
        double decimal = parseCoordinateToDecimalDegrees(rawValue, direction, isLatitude);
        if (!Double.isFinite(decimal)) {
            return null;
        }
        double absDecimal = Math.abs(decimal);
        int degrees = (int) Math.floor(absDecimal);
        double minutes = (absDecimal - degrees) * 60.0d;
        double degreeMinutes = degrees * 100.0d + minutes;
        return String.format(Locale.US, "%.8f", degreeMinutes);
    }
 
    private double parseCoordinateToDecimalDegrees(String rawValue, String direction, boolean isLatitude) {
        if (rawValue == null) {
            return Double.NaN;
        }
        String trimmed = rawValue.trim();
        if (trimmed.isEmpty()) {
            return Double.NaN;
        }
        double numeric;
        try {
            numeric = Double.parseDouble(trimmed);
        } catch (NumberFormatException ex) {
            return Double.NaN;
        }
 
        double abs = Math.abs(numeric);
        double boundary = isLatitude ? 90d : 180d;
        double decimal;
        if (abs <= boundary) {
            decimal = abs;
        } else {
            double degrees = Math.floor(abs / 100d);
            double minutes = abs - degrees * 100d;
            decimal = degrees + minutes / 60d;
        }
 
        String dirUpper = direction == null ? "" : direction.trim().toUpperCase(Locale.ROOT);
        if ("S".equals(dirUpper) || "W".equals(dirUpper)) {
            decimal = -decimal;
        } else if (!"N".equals(dirUpper) && !"E".equals(dirUpper) && numeric < 0d) {
            decimal = -decimal;
        }
        return decimal;
    }
    
    private void lockBaseStationPosition() {
        // 显示警告确认对话框
        int result = JOptionPane.showConfirmDialog(
            this,
            "<html><body style='width: 250px;'>" +
            "<b>基准站位置锁定确认</b><br>" +
            "基准站位置在使用过程中禁止移动!<br>" +
            "如果移动将会导致:<br>" +
            "所有之前绘制的割草路径无效<br>" +            
            "安装要求:<br>" +
            "安装在空旷位置<br>" +
            "保证良好的卫星信号接收<br>" +
            "确定要锁定基准站位置吗?" +
            "</body></html>",
            "锁定基准站位置",
            JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.WARNING_MESSAGE
        );
        
        if (result == JOptionPane.OK_OPTION) {
            // 模拟发送数据给基准站
            JOptionPane.showMessageDialog(this, 
                "已发送锁定指令到基准站\n基准站位置已固定",
                "操作成功",
                JOptionPane.INFORMATION_MESSAGE);
            
            // 更新基准站位置(这里使用模拟数据,实际应从GPS获取)
            String newPosition = canonicalizeCoordinateValue("2324.194945,N,11330.938547,E");
            String timestamp = String.valueOf(System.currentTimeMillis());
 
            if (!hasBaseStationId()) {
                JOptionPane.showMessageDialog(this,
                        "请先录入基准站编号。",
                        "提示",
                        JOptionPane.WARNING_MESSAGE);
                return;
            }
 
            if (baseStation != null) {
                try {
                    baseStation.updateByDeviceId(baseStation.getDeviceId(),
                            newPosition,
                            baseStation.getIotSimCardNumber(),
                            baseStation.getDeviceActivationTime(),
                            timestamp);
                } catch (IllegalArgumentException ex) {
                    JOptionPane.showMessageDialog(this,
                            ex.getMessage(),
                            "错误",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }
            
            if (device != null) {
                // 更新Device对象中的属性
                device.setBaseStationCoordinates(newPosition);
                device.setBupdateTime(timestamp);
                
                // 更新properties文件
                updatePropertiesFile("baseStationCoordinates", newPosition);
                updatePropertiesFile("BupdateTime", timestamp);
            }
 
            refreshLabels();
        }
    }
    
    private void showInstallationTutorial() {
        File videoFile = new File("base.mp4");
        if (videoFile.exists()) {
            try {
                // 使用系统默认程序打开视频文件
                Desktop.getDesktop().open(videoFile);
                JOptionPane.showMessageDialog(this, 
                    "正在打开安装教程视频...\n如果视频没有自动播放,请手动打开文件:\n" + videoFile.getAbsolutePath(),
                    "打开教程",
                    JOptionPane.INFORMATION_MESSAGE);
            } catch (IOException e) {
                JOptionPane.showMessageDialog(this, 
                    "无法打开教程视频文件: " + e.getMessage(), 
                    "错误", 
                    JOptionPane.ERROR_MESSAGE);
            } catch (UnsupportedOperationException e) {
                JOptionPane.showMessageDialog(this, 
                    "系统不支持直接打开视频文件,请手动打开: " + videoFile.getAbsolutePath(), 
                    "提示", 
                    JOptionPane.INFORMATION_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(this, 
                "<html>教程视频文件不存在:<br>" + videoFile.getAbsolutePath() + "<br><br>" +
                "请确保base.mp4文件位于应用程序根目录。</html>", 
                "文件未找到", 
                JOptionPane.ERROR_MESSAGE);
        }
    }
    
    private void updatePropertiesFile(String key, String value) {
        Properties properties = new Properties();
        try {
            // 加载现有属性
            java.io.FileInputStream input = new java.io.FileInputStream("device.properties");
            properties.load(input);
            input.close();
            
            // 更新指定属性
            properties.setProperty(key, value);
            
            // 保存回文件
            FileOutputStream output = new FileOutputStream("device.properties");
            properties.store(output, "Updated base station information");
            output.close();
            
        } catch (IOException e) {
            System.err.println("更新device.properties文件失败: " + e.getMessage());
            JOptionPane.showMessageDialog(this, 
                "更新配置文件失败: " + e.getMessage(), 
                "错误", 
                JOptionPane.ERROR_MESSAGE);
        }
    }
    
    @Override
    public void dispose() {
        // 停止定时器
        if (refreshTimer != null && refreshTimer.isRunning()) {
            refreshTimer.stop();
        }
        super.dispose();
    }
}