张世豪
2025-12-11 6f59464fc6e12a525ba3004864eceb1bc1573a31
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
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
package set;
 
import baseStation.BaseStation;
 
import zhuye.MapRenderer;
import zhuye.Shouye;
import zhuye.buttonset;
 
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
 
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
 
/**
 * 设置对话框 - 参考Shouye.java样式
 */
public class Sets extends JDialog {
    private static final long serialVersionUID = 1L;
    private static final int ROW_HEIGHT = 40;
    private static final int ROW_SPACING = 25;
    
    // 主题颜色
    private final Color THEME_COLOR;
    private final Color BACKGROUND_COLOR = new Color(250, 250, 250);
    private final Color PANEL_BACKGROUND = new Color(255, 255, 255);
    private final Color BORDER_COLOR = new Color(220, 220, 220);
    
    // 设置项组件
    private JLabel mowerIdLabel;
    private JLabel baseStationIdLabel;
    private JLabel handheldMarkerLabel;
    private JLabel simCardNumberLabel;
    private JLabel baseStationSimLabel;
    private JLabel firmwareVersionLabel;
    private JLabel appVersionLabel;
    private JLabel idleTrailDurationLabel;
    
    private JButton mowerIdEditBtn;
    private JButton baseStationIdEditBtn;
    private JButton handheldEditBtn;
    private JButton checkUpdateBtn;
    private JButton systemDebugButton;
    private JButton feedbackButton;
    private JButton idleTrailEditBtn;
    
    // 数据模型
    private Setsys setData;
    private final BaseStation baseStation;
    
    public Sets(JFrame parent, Color themeColor) {
        super(parent, "系统设置", true);
        this.THEME_COLOR = themeColor;
        this.setData = new Setsys();
        this.baseStation = new BaseStation();
        initializeUI();
        loadData();
    }
    
    public Sets(JDialog parent, Color themeColor) {
        super(parent, "系统设置", true);
        this.THEME_COLOR = themeColor;
        this.setData = new Setsys();
        this.baseStation = new BaseStation();
        initializeUI();
        loadData();
    }
    
    private void initializeUI() {
        setLayout(new BorderLayout());
        setBackground(BACKGROUND_COLOR);
    setSize(400, 800);
    setPreferredSize(new Dimension(400, 800));
    setMinimumSize(new Dimension(400, 800));
        setLocationRelativeTo(getParent());
        setResizable(false);
        
        // 创建主内容面板
        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
        mainPanel.setBackground(BACKGROUND_COLOR);
        mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        
        // 创建设置项面板
        JPanel settingsPanel = createSettingsPanel();
        
        // 添加组件到主面板
        mainPanel.add(settingsPanel);
        mainPanel.add(Box.createVerticalGlue());
        
        add(mainPanel, BorderLayout.CENTER);
    }
    
    private JPanel createSettingsPanel() {
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        panel.setBackground(PANEL_BACKGROUND);
        panel.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(BORDER_COLOR),
            BorderFactory.createEmptyBorder(20, 20, 20, 20)
        ));
        
        // 割草机编号
        JPanel mowerIdPanel = createSettingItemPanel("割草机编号", 
            setData.getMowerId() != null ? setData.getMowerId() : "未设置", true);
        mowerIdLabel = (JLabel) mowerIdPanel.getClientProperty("valueLabel");
        mowerIdEditBtn = (JButton) mowerIdPanel.getClientProperty("editButton");
 
        JPanel baseStationIdPanel = createSettingItemPanel("差分基准站编号",
            resolveBaseStationId(), true);
        baseStationIdLabel = (JLabel) baseStationIdPanel.getClientProperty("valueLabel");
        baseStationIdEditBtn = (JButton) baseStationIdPanel.getClientProperty("editButton");
        
        JPanel handheldPanel = createSettingItemPanel("便携打点器编号",
            setData.getHandheldMarkerId() != null ? setData.getHandheldMarkerId() : "未设置", true);
        handheldMarkerLabel = (JLabel) handheldPanel.getClientProperty("valueLabel");
        handheldEditBtn = (JButton) handheldPanel.getClientProperty("editButton");
 
        // 物联卡号
        JPanel simCardPanel = createSettingItemPanel("割草机物联网卡号", 
            setData.getSimCardNumber() != null ? setData.getSimCardNumber() : "未设置", false);
        simCardNumberLabel = (JLabel) simCardPanel.getClientProperty("valueLabel");
 
        JPanel baseStationSimPanel = createSettingItemPanel("基准站物联网卡号",
            resolveBaseStationSimCard(), false);
        baseStationSimLabel = (JLabel) baseStationSimPanel.getClientProperty("valueLabel");
        
        // 固件版本
        JPanel firmwarePanel = createSettingItemPanel("固件版本", 
            setData.getFirmwareVersion() != null ? setData.getFirmwareVersion() : "未设置", false);
        firmwareVersionLabel = (JLabel) firmwarePanel.getClientProperty("valueLabel");
 
        JPanel idleTrailPanel = createSettingItemPanel("轨迹拖尾时长",
            formatIdleTrailDurationValue(), true);
        idleTrailDurationLabel = (JLabel) idleTrailPanel.getClientProperty("valueLabel");
        idleTrailEditBtn = (JButton) idleTrailPanel.getClientProperty("editButton");
 
        JPanel feedbackPanel = createFeedbackPanel();
        
        // APP版本
        JPanel appVersionPanel = createAppVersionPanel();
        
    addRowWithSpacing(panel, mowerIdPanel);
    addRowWithSpacing(panel, baseStationIdPanel);
        addRowWithSpacing(panel, handheldPanel);
    addRowWithSpacing(panel, simCardPanel);
    addRowWithSpacing(panel, baseStationSimPanel);
    addRowWithSpacing(panel, firmwarePanel);
    addRowWithSpacing(panel, idleTrailPanel);
    addRowWithSpacing(panel, feedbackPanel);
    addRowWithSpacing(panel, appVersionPanel);
    panel.add(createDebugPanel());
        
        return panel;
    }
 
    private String formatIdleTrailDurationValue() {
        int seconds = setData != null ? setData.getIdleTrailDurationSeconds() : Setsys.DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
        if (seconds <= 0) {
            seconds = Setsys.DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
        }
        return seconds + "秒";
    }
 
    private void addRowWithSpacing(JPanel container, JPanel row) {
        container.add(row);
        container.add(Box.createRigidArea(new Dimension(0, ROW_SPACING)));
    }
    
    private JPanel createSettingItemPanel(String title, String value, boolean editable) {
        JPanel panel = new JPanel(new GridBagLayout());
        panel.setBackground(PANEL_BACKGROUND);
        panel.setAlignmentX(Component.LEFT_ALIGNMENT);
        panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
        panel.setPreferredSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
        panel.setMinimumSize(new Dimension(0, ROW_HEIGHT));
 
        GridBagConstraints gbc = new GridBagConstraints();
 
        JLabel titleLabel = new JLabel(title);
        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 14));
        titleLabel.setForeground(Color.BLACK);
        titleLabel.setHorizontalAlignment(SwingConstants.RIGHT);
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 0;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(0, 0, 0, 12);
        panel.add(titleLabel, gbc);
 
        JLabel valueLabel = new JLabel(value);
        valueLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
        valueLabel.setForeground(Color.DARK_GRAY);
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.anchor = GridBagConstraints.EAST;
        panel.add(valueLabel, gbc);
 
        panel.putClientProperty("valueLabel", valueLabel);
 
        if (editable) {
            JButton editBtn = createEditButton();
            editBtn.setPreferredSize(new Dimension(30, 30));
            editBtn.setMinimumSize(new Dimension(30, 30));
            editBtn.setMaximumSize(new Dimension(30, 30));
            gbc = new GridBagConstraints();
            gbc.gridx = 2;
            gbc.gridy = 0;
            gbc.weightx = 0;
            gbc.anchor = GridBagConstraints.EAST;
            panel.add(editBtn, gbc);
            panel.putClientProperty("editButton", editBtn);
        }
 
        return panel;
    }
    
    private JPanel createAppVersionPanel() {
        JPanel panel = new JPanel(new GridBagLayout());
        panel.setBackground(PANEL_BACKGROUND);
        panel.setAlignmentX(Component.LEFT_ALIGNMENT);
        panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
        panel.setPreferredSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
        panel.setMinimumSize(new Dimension(0, ROW_HEIGHT));
 
        GridBagConstraints gbc = new GridBagConstraints();
 
        JLabel titleLabel = new JLabel("APP版本");
        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 14));
        titleLabel.setForeground(Color.BLACK);
        titleLabel.setHorizontalAlignment(SwingConstants.RIGHT);
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 0;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(0, 0, 0, 12);
        panel.add(titleLabel, gbc);
 
        appVersionLabel = new JLabel(setData.getAppVersion() != null ? setData.getAppVersion() : "未设置");
        appVersionLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
        appVersionLabel.setForeground(Color.DARK_GRAY);
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.anchor = GridBagConstraints.EAST;
        panel.add(appVersionLabel, gbc);
 
        checkUpdateBtn = buttonset.createStyledButton("检查更新", THEME_COLOR);
        checkUpdateBtn.setFont(new Font("微软雅黑", Font.PLAIN, 12));
 
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = 0;
        gbc.weightx = 0;
        gbc.anchor = GridBagConstraints.EAST;
        panel.add(checkUpdateBtn, gbc);
 
        return panel;
    }
 
    private JPanel createDebugPanel() {
        JPanel panel = new JPanel(new GridBagLayout());
        panel.setBackground(PANEL_BACKGROUND);
        panel.setAlignmentX(Component.LEFT_ALIGNMENT);
        panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
        panel.setPreferredSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
        panel.setMinimumSize(new Dimension(0, ROW_HEIGHT));
 
        GridBagConstraints gbc = new GridBagConstraints();
 
        JLabel titleLabel = new JLabel("系统调试");
        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 14));
        titleLabel.setForeground(Color.BLACK);
        titleLabel.setHorizontalAlignment(SwingConstants.RIGHT);
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 0;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(0, 0, 0, 12);
        panel.add(titleLabel, gbc);
 
        Color darkerTheme = new Color(
            Math.max(THEME_COLOR.getRed() - 20, 0),
            Math.max(THEME_COLOR.getGreen() - 20, 0),
            Math.max(THEME_COLOR.getBlue() - 20, 0));
        systemDebugButton = buttonset.createStyledButton("系统调试", darkerTheme);
        systemDebugButton.setFont(new Font("微软雅黑", Font.PLAIN, 12));
 
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.anchor = GridBagConstraints.EAST;
        panel.add(systemDebugButton, gbc);
 
        return panel;
    }
 
    private JPanel createFeedbackPanel() {
        JPanel panel = new JPanel(new GridBagLayout());
        panel.setBackground(PANEL_BACKGROUND);
        panel.setAlignmentX(Component.LEFT_ALIGNMENT);
        panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
        panel.setPreferredSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
        panel.setMinimumSize(new Dimension(0, ROW_HEIGHT));
 
        GridBagConstraints gbc = new GridBagConstraints();
 
        JLabel titleLabel = new JLabel("问题反馈咨询");
        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 14));
        titleLabel.setForeground(Color.BLACK);
        titleLabel.setHorizontalAlignment(SwingConstants.RIGHT);
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 0;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(0, 0, 0, 12);
        panel.add(titleLabel, gbc);
 
        feedbackButton = buttonset.createStyledButton("反馈", THEME_COLOR);
        feedbackButton.setFont(new Font("微软雅黑", Font.PLAIN, 12));
 
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.anchor = GridBagConstraints.EAST;
        panel.add(feedbackButton, gbc);
 
        return panel;
    }
    
    private JButton createEditButton() {
        JButton button = new JButton();
        try {
            // 加载编辑图标
            ImageIcon editIcon = new ImageIcon("image/bianjie.png");
            // 调整图片大小
            Image scaledImage = editIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH);
            button.setIcon(new ImageIcon(scaledImage));
        } catch (Exception e) {
            // 如果图片加载失败,使用文本
            button.setText("编辑");
            System.err.println("无法加载编辑图标: " + e.getMessage());
        }
        
        button.setPreferredSize(new Dimension(30, 30));
        button.setBackground(PANEL_BACKGROUND);
        button.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        button.setFocusPainted(false);
        
        // 悬停效果
        button.addMouseListener(new MouseAdapter() {
            public void mouseEntered(MouseEvent e) {
                button.setBackground(new Color(240, 240, 240));
            }
            public void mouseExited(MouseEvent e) {
                button.setBackground(PANEL_BACKGROUND);
            }
        });
        
        return button;
    }
    
    private void loadData() {
        // 从Setsys类加载数据
        setData.initializeFromProperties();
        baseStation.load();
        updateDisplay();
    }
    
    private void updateDisplay() {
        // 更新割草机编号显示
        if (mowerIdLabel != null) {
            mowerIdLabel.setText(setData.getMowerId() != null ? setData.getMowerId() : "未设置");
        }
 
        if (baseStationIdLabel != null) {
            baseStationIdLabel.setText(resolveBaseStationId());
        }
 
        if (handheldMarkerLabel != null) {
            handheldMarkerLabel.setText(setData.getHandheldMarkerId() != null ? setData.getHandheldMarkerId() : "未设置");
        }
        
        // 更新物联卡号显示
        if (simCardNumberLabel != null) {
            simCardNumberLabel.setText(setData.getSimCardNumber() != null ? 
                setData.getSimCardNumber() : "未设置");
        }
 
        if (baseStationSimLabel != null) {
            baseStationSimLabel.setText(resolveBaseStationSimCard());
        }
        
        // 更新固件版本显示
        if (firmwareVersionLabel != null) {
            firmwareVersionLabel.setText(setData.getFirmwareVersion() != null ? 
                setData.getFirmwareVersion() : "未设置");
        }
 
        if (idleTrailDurationLabel != null) {
            idleTrailDurationLabel.setText(formatIdleTrailDurationValue());
        }
        
        // 更新APP版本显示
        if (appVersionLabel != null) {
            appVersionLabel.setText(setData.getAppVersion() != null ? 
                setData.getAppVersion() : "未设置");
        }
    }
 
    private String resolveBaseStationSimCard() {
        if (baseStation == null) {
            return "未设置";
        }
        String value = baseStation.getIotSimCardNumber();
        if (value == null) {
            return "未设置";
        }
        String trimmed = value.trim();
        if (trimmed.isEmpty() || "-1".equals(trimmed)) {
            return "未设置";
        }
        return trimmed;
    }
 
    private String resolveBaseStationId() {
        if (baseStation == null) {
            return "未设置";
        }
        String value = baseStation.getDeviceId();
        if (value == null) {
            return "未设置";
        }
        String trimmed = value.trim();
        if (trimmed.isEmpty() || "-1".equals(trimmed)) {
            return "未设置";
        }
        return trimmed;
    }
    
    private void setupEventHandlers() {
        // 割草机编号编辑按钮事件
        if (mowerIdEditBtn != null) {
            mowerIdEditBtn.addActionListener(e -> editMowerId());
        }
 
        if (baseStationIdEditBtn != null) {
            baseStationIdEditBtn.addActionListener(e -> editBaseStationId());
        }
        
        // 检查更新按钮事件
        if (checkUpdateBtn != null) {
            checkUpdateBtn.addActionListener(e -> checkForUpdates());
        }
 
        if (handheldEditBtn != null) {
            handheldEditBtn.addActionListener(e -> editHandheldMarkerId());
        }
 
        if (feedbackButton != null) {
            feedbackButton.addActionListener(e -> showFeedbackDialog());
        }
 
        if (systemDebugButton != null) {
            systemDebugButton.addActionListener(e -> openSystemDebugDialog());
        }
 
        if (idleTrailEditBtn != null) {
            idleTrailEditBtn.addActionListener(e -> editIdleTrailDuration());
        }
        
    }
    
    private void editMowerId() {
        String currentValue = setData.getMowerId() != null ? setData.getMowerId() : "";
        String newValue = (String) JOptionPane.showInputDialog(this,
            "请输入割草机编号:",
            "修改割草机编号",
            JOptionPane.QUESTION_MESSAGE,
            null,
            null,
            currentValue);
 
        if (newValue == null) {
            return; // 用户取消
        }
 
        newValue = newValue.trim();
        if (!newValue.isEmpty()) {
            if (setData.updateProperty("mowerId", newValue)) {
                mowerIdLabel.setText(newValue);
                JOptionPane.showMessageDialog(this, "割草机编号更新成功", "成功", JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "割草机编号更新失败", "错误", JOptionPane.ERROR_MESSAGE);
            }
        }
    }
 
    private void editHandheldMarkerId() {
        String currentValue = setData.getHandheldMarkerId() != null ? setData.getHandheldMarkerId() : "";
        String newValue = (String) JOptionPane.showInputDialog(this,
                "请输入便携打点器编号:",
                "修改便携打点器编号",
                JOptionPane.QUESTION_MESSAGE,
                null,
                null,
                currentValue);
 
        if (newValue == null) {
            return;
        }
 
        newValue = newValue.trim();
        if (!newValue.isEmpty()) {
            if (setData.updateProperty("handheldMarkerId", newValue)) {
                if (handheldMarkerLabel != null) {
                    handheldMarkerLabel.setText(newValue);
                }
                JOptionPane.showMessageDialog(this, "便携打点器编号更新成功", "成功", JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "便携打点器编号更新失败", "错误", JOptionPane.ERROR_MESSAGE);
            }
        }
    }
 
    private void editBaseStationId() {
        String currentValue = "未设置".equals(resolveBaseStationId()) ? "" : resolveBaseStationId();
        String newValue = (String) JOptionPane.showInputDialog(this,
                "请输入差分基准站编号:",
                "修改差分基准站编号",
                JOptionPane.QUESTION_MESSAGE,
                null,
                null,
                currentValue);
 
        if (newValue == null) {
            return;
        }
 
        newValue = newValue.trim();
        if (newValue.isEmpty()) {
            JOptionPane.showMessageDialog(this, "差分基准站编号不能为空", "提示", JOptionPane.WARNING_MESSAGE);
            return;
        }
 
        try {
            baseStation.updateByDeviceId(newValue,
                    baseStation.getInstallationCoordinates(),
                    baseStation.getIotSimCardNumber(),
                    baseStation.getDeviceActivationTime(),
                    baseStation.getDataUpdateTime());
            baseStation.load();
            if (baseStationIdLabel != null) {
                baseStationIdLabel.setText(resolveBaseStationId());
            }
            JOptionPane.showMessageDialog(this, "差分基准站编号更新成功", "成功", JOptionPane.INFORMATION_MESSAGE);
        } catch (IllegalArgumentException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "输入错误", JOptionPane.WARNING_MESSAGE);
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, "差分基准站编号更新失败", "错误", JOptionPane.ERROR_MESSAGE);
        }
    }
 
    private void editIdleTrailDuration() {
        int currentSeconds = setData != null ? setData.getIdleTrailDurationSeconds() : Setsys.DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
        if (currentSeconds <= 0) {
            currentSeconds = Setsys.DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
        }
 
        String input = JOptionPane.showInputDialog(this,
            "请输入轨迹拖尾时长(单位:秒)",
            currentSeconds);
 
        if (input == null) {
            return;
        }
 
        String trimmed = input.trim();
        if (trimmed.isEmpty()) {
            JOptionPane.showMessageDialog(this, "轨迹拖尾时长不能为空", "提示", JOptionPane.WARNING_MESSAGE);
            return;
        }
 
        int parsedSeconds;
        try {
            parsedSeconds = Integer.parseInt(trimmed);
        } catch (NumberFormatException ex) {
            JOptionPane.showMessageDialog(this, "请输入有效的整数秒数", "提示", JOptionPane.WARNING_MESSAGE);
            return;
        }
 
        if (parsedSeconds < 5 || parsedSeconds > 600) {
            JOptionPane.showMessageDialog(this, "请输入5到600之间的秒数", "提示", JOptionPane.WARNING_MESSAGE);
            return;
        }
 
        if (setData.updateProperty("idleTrailDurationSeconds", String.valueOf(parsedSeconds))) {
            int appliedSeconds = setData.getIdleTrailDurationSeconds();
            if (idleTrailDurationLabel != null) {
                idleTrailDurationLabel.setText(appliedSeconds + "秒");
            }
            MapRenderer renderer = null;
            Shouye shouye = Shouye.getInstance();
            if (shouye != null) {
                renderer = shouye.getMapRenderer();
            }
            if (renderer != null) {
                renderer.setIdleTrailDurationSeconds(appliedSeconds);
            }
            JOptionPane.showMessageDialog(this, "轨迹拖尾时长已更新为 " + appliedSeconds + " 秒", "成功", JOptionPane.INFORMATION_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, "轨迹拖尾时长更新失败", "错误", JOptionPane.ERROR_MESSAGE);
        }
    }
 
    private void showFeedbackDialog() {
    JDialog dialog = new JDialog(this, "问题反馈咨询", true);
    dialog.setLayout(new BorderLayout(0, 12));
    dialog.setResizable(false);
    dialog.setPreferredSize(new Dimension(400, 800));
    dialog.setSize(new Dimension(400, 800));
    dialog.setMinimumSize(new Dimension(400, 800));
 
    JPanel content = new JPanel();
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    content.setBorder(BorderFactory.createEmptyBorder(20, 24, 20, 24));
    dialog.add(content, BorderLayout.CENTER);
 
        JLabel descriptionLabel = new JLabel("问题描述:");
        descriptionLabel.setFont(new Font("微软雅黑", Font.BOLD, 13));
        descriptionLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        content.add(descriptionLabel);
 
        content.add(Box.createRigidArea(new Dimension(0, 8)));
 
        JTextArea descriptionArea = new JTextArea(5, 30);
        descriptionArea.setLineWrap(true);
        descriptionArea.setWrapStyleWord(true);
        descriptionArea.setFont(new Font("微软雅黑", Font.PLAIN, 13));
        JScrollPane scrollPane = new JScrollPane(descriptionArea);
        scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT);
        content.add(scrollPane);
 
        content.add(Box.createRigidArea(new Dimension(0, 16)));
 
        JPanel photoControls = new JPanel(new FlowLayout(FlowLayout.LEFT, 12, 0));
        photoControls.setAlignmentX(Component.LEFT_ALIGNMENT);
        JLabel photoLabel = new JLabel("选择照片(最多6张):");
        photoLabel.setFont(new Font("微软雅黑", Font.BOLD, 13));
    JButton selectPhotosButton = buttonset.createStyledButton("选择照片", THEME_COLOR);
    selectPhotosButton.setFont(new Font("微软雅黑", Font.PLAIN, 12));
        photoControls.add(photoLabel);
        photoControls.add(selectPhotosButton);
    content.add(photoControls);
 
    content.add(Box.createRigidArea(new Dimension(0, 20)));
 
        JPanel photoGrid = new JPanel(new GridLayout(2, 3, 12, 12));
        photoGrid.setAlignmentX(Component.LEFT_ALIGNMENT);
        photoGrid.setMaximumSize(new Dimension(Integer.MAX_VALUE, 220));
        List<JLabel> photoSlots = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            JLabel slot = buildPhotoSlot();
            photoGrid.add(slot);
            photoSlots.add(slot);
        }
        content.add(photoGrid);
 
        content.add(Box.createRigidArea(new Dimension(0, 20)));
 
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    JButton cancelButton = buttonset.createStyledButton("放弃", new Color(128, 128, 128));
    cancelButton.setFont(new Font("微软雅黑", Font.PLAIN, 12));
    JButton submitButton = buttonset.createStyledButton("提交", THEME_COLOR);
    submitButton.setFont(new Font("微软雅黑", Font.PLAIN, 12));
 
        buttonPanel.add(cancelButton);
        buttonPanel.add(submitButton);
        dialog.add(buttonPanel, BorderLayout.SOUTH);
 
        List<File> selectedPhotos = new ArrayList<>();
 
        selectPhotosButton.addActionListener(e -> {
            JFileChooser chooser = new JFileChooser();
            chooser.setMultiSelectionEnabled(true);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            chooser.setFileFilter(new FileNameExtensionFilter("图片文件", "jpg", "jpeg", "png", "bmp", "gif", "webp"));
 
            if (chooser.showOpenDialog(dialog) == JFileChooser.APPROVE_OPTION) {
                File[] files = chooser.getSelectedFiles();
                if (files != null) {
                    if (selectedPhotos.size() >= 6) {
                        JOptionPane.showMessageDialog(dialog, "已达到6张照片上限", "提示", JOptionPane.WARNING_MESSAGE);
                        return;
                    }
                    for (File file : files) {
                        if (selectedPhotos.size() >= 6) {
                            break;
                        }
                        if (file != null && file.exists() && file.isFile()) {
                            selectedPhotos.add(file);
                        }
                    }
                    updatePhotoPreview(photoSlots, selectedPhotos);
                }
            }
        });
 
        cancelButton.addActionListener(e -> dialog.dispose());
 
        submitButton.addActionListener(e -> {
            String description = descriptionArea.getText() != null ? descriptionArea.getText().trim() : "";
            if (description.isEmpty()) {
                JOptionPane.showMessageDialog(dialog, "请填写问题描述", "提示", JOptionPane.WARNING_MESSAGE);
                descriptionArea.requestFocusInWindow();
                return;
            }
 
            // 提交逻辑占位
            JOptionPane.showMessageDialog(dialog,
                    "反馈已提交,感谢您的支持!\n描述字数:" + description.length() + ",照片数量:" + selectedPhotos.size(),
                    "提交成功",
                    JOptionPane.INFORMATION_MESSAGE);
            dialog.dispose();
        });
 
        dialog.pack();
        dialog.setLocationRelativeTo(this);
        dialog.setVisible(true);
    }
 
    private JLabel buildPhotoSlot() {
        JLabel slot = new JLabel();
        slot.setPreferredSize(new Dimension(100, 100));
        slot.setMinimumSize(new Dimension(100, 100));
        slot.setOpaque(true);
        slot.setBackground(new Color(245, 245, 245));
        slot.setHorizontalAlignment(SwingConstants.CENTER);
        slot.setVerticalAlignment(SwingConstants.CENTER);
        slot.setBorder(BorderFactory.createLineBorder(new Color(220, 220, 220), 1));
        slot.setText("+");
        slot.setFont(new Font("微软雅黑", Font.BOLD, 18));
        slot.setForeground(new Color(180, 180, 180));
        return slot;
    }
 
    private void updatePhotoPreview(List<JLabel> slots, List<File> photos) {
        for (int i = 0; i < slots.size(); i++) {
            JLabel slot = slots.get(i);
            if (i < photos.size()) {
                File photo = photos.get(i);
                ImageIcon icon = new ImageIcon(photo.getAbsolutePath());
                Image scaled = icon.getImage().getScaledInstance(100, 100, Image.SCALE_SMOOTH);
                slot.setIcon(new ImageIcon(scaled));
                slot.setText(null);
            } else {
                slot.setIcon(null);
                slot.setText("+");
            }
        }
    }
    
    private void checkForUpdates() {
        // 模拟检查更新过程
        checkUpdateBtn.setEnabled(false);
        checkUpdateBtn.setText("检查中...");
        
        // 使用定时器模拟网络请求
        Timer timer = new Timer(2000, e -> {
            // 这里应该是实际的检查更新逻辑
            // 目前只是模拟
            checkUpdateBtn.setEnabled(true);
            checkUpdateBtn.setText("检查更新");
            
            // 假设当前已是最新版本
            JOptionPane.showMessageDialog(this, 
                "当前已是最新版本: " + (setData.getAppVersion() != null ? setData.getAppVersion() : "未知"), 
                "检查更新", 
                JOptionPane.INFORMATION_MESSAGE);
        });
        timer.setRepeats(false);
        timer.start();
    }
 
    private void openSystemDebugDialog() {
        debug dialog = new debug(this, THEME_COLOR);
        dialog.setLocationRelativeTo(this);
        dialog.setVisible(true);
    }
    
    @Override
    public void setVisible(boolean visible) {
        if (visible) {
            setupEventHandlers();
            loadData(); // 每次显示时重新加载数据
        }
        super.setVisible(visible);
    }
       
}