张世豪
2025-12-04 3ad76f98fa8b4a9d3d95207cfb4ae4706087c964
src/set/Sets.java
@@ -1,4 +1,7 @@
package set;
import baseStation.BaseStation;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
@@ -26,21 +29,25 @@
    private JLabel mowerIdLabel;
    private JLabel handheldMarkerLabel;
    private JLabel simCardNumberLabel;
    private JLabel baseStationSimLabel;
    private JLabel firmwareVersionLabel;
    private JLabel appVersionLabel;
    
    private JButton mowerIdEditBtn;
    private JButton handheldEditBtn;
    private JButton checkUpdateBtn;
    private JButton systemDebugButton;
    private JButton feedbackButton;
    
    // 数据模型
    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();
    }
@@ -49,6 +56,7 @@
        super(parent, "系统设置", true);
        this.THEME_COLOR = themeColor;
        this.setData = new Setsys();
        this.baseStation = new BaseStation();
        initializeUI();
        loadData();
    }
@@ -99,10 +107,14 @@
        handheldEditBtn = (JButton) handheldPanel.getClientProperty("editButton");
        // 物联卡号
        JPanel simCardPanel = createSettingItemPanel("物联卡号",
        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);
@@ -116,9 +128,11 @@
        addRowWithSpacing(panel, mowerIdPanel);
        addRowWithSpacing(panel, handheldPanel);
        addRowWithSpacing(panel, simCardPanel);
    addRowWithSpacing(panel, baseStationSimPanel);
        addRowWithSpacing(panel, firmwarePanel);
        addRowWithSpacing(panel, feedbackPanel);
        panel.add(appVersionPanel);
    addRowWithSpacing(panel, appVersionPanel);
    panel.add(createDebugPanel());
        
        return panel;
    }
@@ -213,10 +227,10 @@
        checkUpdateBtn.setFont(new Font("微软雅黑", Font.PLAIN, 12));
        checkUpdateBtn.setBackground(THEME_COLOR);
        checkUpdateBtn.setForeground(Color.WHITE);
        checkUpdateBtn.setBorder(BorderFactory.createEmptyBorder(0, 12, 0, 12));
        checkUpdateBtn.setPreferredSize(new Dimension(90, 25));
        checkUpdateBtn.setMinimumSize(new Dimension(90, 25));
        checkUpdateBtn.setMaximumSize(new Dimension(90, 25));
    checkUpdateBtn.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 20));
    checkUpdateBtn.setPreferredSize(new Dimension(100, 28));
    checkUpdateBtn.setMinimumSize(new Dimension(100, 28));
    checkUpdateBtn.setMaximumSize(new Dimension(100, 28));
        checkUpdateBtn.setFocusPainted(false);
        checkUpdateBtn.addMouseListener(new MouseAdapter() {
@@ -242,6 +256,62 @@
        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);
        systemDebugButton = new JButton("系统调试");
        systemDebugButton.setFont(new Font("微软雅黑", Font.PLAIN, 12));
        systemDebugButton.setBackground(new Color(
            Math.max(THEME_COLOR.getRed() - 20, 0),
            Math.max(THEME_COLOR.getGreen() - 20, 0),
            Math.max(THEME_COLOR.getBlue() - 20, 0)));
        systemDebugButton.setForeground(Color.WHITE);
        systemDebugButton.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 20));
        systemDebugButton.setPreferredSize(new Dimension(100, 28));
        systemDebugButton.setMinimumSize(new Dimension(100, 28));
        systemDebugButton.setMaximumSize(new Dimension(100, 28));
        systemDebugButton.setFocusPainted(false);
        systemDebugButton.addMouseListener(new MouseAdapter() {
            public void mouseEntered(MouseEvent e) {
                systemDebugButton.setBackground(THEME_COLOR);
            }
            public void mouseExited(MouseEvent e) {
                systemDebugButton.setBackground(new Color(
                    Math.max(THEME_COLOR.getRed() - 20, 0),
                    Math.max(THEME_COLOR.getGreen() - 20, 0),
                    Math.max(THEME_COLOR.getBlue() - 20, 0)));
            }
        });
        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);
@@ -333,6 +403,7 @@
    private void loadData() {
        // 从Setsys类加载数据
        setData.initializeFromProperties();
        baseStation.load();
        updateDisplay();
    }
    
@@ -352,6 +423,10 @@
                setData.getSimCardNumber() : "未设置");
        }
        
        if (baseStationSimLabel != null) {
            baseStationSimLabel.setText(resolveBaseStationSimCard());
        }
        // 更新固件版本显示
        if (firmwareVersionLabel != null) {
            firmwareVersionLabel.setText(setData.getFirmwareVersion() != null ? 
@@ -365,6 +440,21 @@
        }
    }
    
    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 void setupEventHandlers() {
        // 割草机编号编辑按钮事件
        if (mowerIdEditBtn != null) {
@@ -384,6 +474,10 @@
            feedbackButton.addActionListener(e -> showFeedbackDialog());
        }
        
        if (systemDebugButton != null) {
            systemDebugButton.addActionListener(e -> openSystemDebugDialog());
        }
    }
    
    private void editMowerId() {
@@ -610,6 +704,12 @@
        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) {