张世豪
2 天以前 c9b1d33979b3972fe6a82fa427b4ba9a20989112
src/gecaoji/GecaojiMeg.java
@@ -1,6 +1,9 @@
package gecaoji;
import javax.swing.*;
import publicway.buttonset;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
@@ -24,6 +27,22 @@
    private JLabel satelliteCountLabel;
    private JLabel realtimeSpeedLabel;
    private JLabel headingLabel;
    // 新增属性标签
    private JLabel pathIdLabel;
    private JLabel batteryLevelLabel;
    private JLabel batteryVoltageLabel;
    private JLabel operationModeLabel;
    private JLabel motorStatusLabel;
    private JLabel bladeStatusLabel;
    private JLabel bladeHeightLabel;
    private JLabel selfCheckStatusLabel;
    private JLabel errorCodeLabel;
    private JLabel errorMessageLabel;
    private JLabel rollLabel;
    private JLabel pitchLabel;
    private JLabel yawLabel;
    private JLabel updateTimeLabel;
    public GecaojiMeg(JPanel anchorPanel, Gecaoji mower) {
@@ -194,15 +213,57 @@
        headingLabel.setFont(valueFont);
        grid.add(headingLabel, gbc);
        
        // 第八行
        gbc.gridx = 0; gbc.gridy = 7;
        // 新增属性显示
        int currentRow = 7;
        // 存储的路径ID
        addLabelRow(grid, gbc, currentRow++, "路径ID:", pathIdLabel = createValueLabel(), titleFont, valueFont);
        // 电池电量
        addLabelRow(grid, gbc, currentRow++, "电池电量:", batteryLevelLabel = createValueLabel(), titleFont, valueFont);
        // 电池电压
        addLabelRow(grid, gbc, currentRow++, "电池电压:", batteryVoltageLabel = createValueLabel(), titleFont, valueFont);
        // 操作模式
        addLabelRow(grid, gbc, currentRow++, "操作模式:", operationModeLabel = createValueLabel(), titleFont, valueFont);
        // 电机状态
        addLabelRow(grid, gbc, currentRow++, "电机状态:", motorStatusLabel = createValueLabel(), titleFont, valueFont);
        // 刀片状态
        addLabelRow(grid, gbc, currentRow++, "刀片状态:", bladeStatusLabel = createValueLabel(), titleFont, valueFont);
        // 刀盘高度
        addLabelRow(grid, gbc, currentRow++, "刀盘高度:", bladeHeightLabel = createValueLabel(), titleFont, valueFont);
        // 自检状态
        addLabelRow(grid, gbc, currentRow++, "自检状态:", selfCheckStatusLabel = createValueLabel(), titleFont, valueFont);
        // 错误代码
        addLabelRow(grid, gbc, currentRow++, "错误代码:", errorCodeLabel = createValueLabel(), titleFont, valueFont);
        // 错误信息
        addLabelRow(grid, gbc, currentRow++, "错误信息:", errorMessageLabel = createValueLabel(), titleFont, valueFont);
        // 横滚角
        addLabelRow(grid, gbc, currentRow++, "横滚角:", rollLabel = createValueLabel(), titleFont, valueFont);
        // 俯仰角
        addLabelRow(grid, gbc, currentRow++, "俯仰角:", pitchLabel = createValueLabel(), titleFont, valueFont);
        // 偏航角
        addLabelRow(grid, gbc, currentRow++, "偏航角:", yawLabel = createValueLabel(), titleFont, valueFont);
        // 更新时间
        gbc.gridx = 0; gbc.gridy = currentRow;
        gbc.weightx = 0.3;
        JLabel label8 = new JLabel("更新时间:");
        label8.setFont(titleFont);
        label8.setForeground(new Color(102, 102, 102));
        grid.add(label8, gbc);
        
        gbc.gridx = 1; gbc.gridy = 7;
        gbc.gridx = 1; gbc.gridy = currentRow;
        gbc.weightx = 0.7;
        updateTimeLabel = createValueLabel();
        updateTimeLabel.setFont(valueFont);
@@ -211,11 +272,8 @@
        content.add(grid, BorderLayout.CENTER);
        // 按钮面板美化
        JButton closeButton = new JButton("关闭");
        JButton closeButton = buttonset.createStyledButton("关闭", new Color(0, 102, 204));
        closeButton.setFont(new Font("Microsoft YaHei", Font.BOLD, 13));
        closeButton.setBackground(new Color(0, 102, 204));
        closeButton.setForeground(Color.WHITE);
        closeButton.setFocusPainted(false);
        closeButton.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(new Color(0, 80, 180), 1),
            BorderFactory.createEmptyBorder(5, 18, 5, 18) // 减小按钮内边距
@@ -310,6 +368,21 @@
        satelliteCountLabel = null;
        realtimeSpeedLabel = null;
        headingLabel = null;
        pathIdLabel = null;
        batteryLevelLabel = null;
        batteryVoltageLabel = null;
        operationModeLabel = null;
        motorStatusLabel = null;
        bladeStatusLabel = null;
        bladeHeightLabel = null;
        selfCheckStatusLabel = null;
        errorCodeLabel = null;
        errorMessageLabel = null;
        rollLabel = null;
        pitchLabel = null;
        yawLabel = null;
        updateTimeLabel = null;
    }
@@ -333,6 +406,22 @@
        satelliteCountLabel.setText(formatDeviceValue(device.getSatelliteCount()));
        realtimeSpeedLabel.setText(formatDeviceValue(device.getRealtimeSpeed()));
        headingLabel.setText(formatDeviceValue(device.getHeading()));
        // 更新新增属性
        pathIdLabel.setText(formatDeviceValue(device.getPath_id_saved()));
        batteryLevelLabel.setText(formatDeviceValue(device.getBattery_level()));
        batteryVoltageLabel.setText(formatDeviceValue(device.getBattery_voltage()));
        operationModeLabel.setText(formatDeviceValue(device.getOperation_mode()));
        motorStatusLabel.setText(formatDeviceValue(device.getMotor_status()));
        bladeStatusLabel.setText(formatDeviceValue(device.getBlade_status()));
        bladeHeightLabel.setText(formatDeviceValue(device.getBlade_height()));
        selfCheckStatusLabel.setText(formatDeviceValue(device.getSelf_check_status()));
        errorCodeLabel.setText(formatDeviceValue(device.getError_code()));
        errorMessageLabel.setText(formatDeviceValue(device.getError_message()));
        rollLabel.setText(formatDeviceValue(device.getRoll()));
        pitchLabel.setText(formatDeviceValue(device.getPitch()));
        yawLabel.setText(formatDeviceValue(device.getYaw()));
        updateTimeLabel.setText(formatTimestamp(device.getGupdateTime()));
    }
@@ -344,6 +433,21 @@
        if (satelliteCountLabel != null) satelliteCountLabel.setText(value);
        if (realtimeSpeedLabel != null) realtimeSpeedLabel.setText(value);
        if (headingLabel != null) headingLabel.setText(value);
        if (pathIdLabel != null) pathIdLabel.setText(value);
        if (batteryLevelLabel != null) batteryLevelLabel.setText(value);
        if (batteryVoltageLabel != null) batteryVoltageLabel.setText(value);
        if (operationModeLabel != null) operationModeLabel.setText(value);
        if (motorStatusLabel != null) motorStatusLabel.setText(value);
        if (bladeStatusLabel != null) bladeStatusLabel.setText(value);
        if (bladeHeightLabel != null) bladeHeightLabel.setText(value);
        if (selfCheckStatusLabel != null) selfCheckStatusLabel.setText(value);
        if (errorCodeLabel != null) errorCodeLabel.setText(value);
        if (errorMessageLabel != null) errorMessageLabel.setText(value);
        if (rollLabel != null) rollLabel.setText(value);
        if (pitchLabel != null) pitchLabel.setText(value);
        if (yawLabel != null) yawLabel.setText(value);
        if (updateTimeLabel != null) updateTimeLabel.setText(value);
    }
@@ -406,4 +510,18 @@
            return sanitized;
        }
    }
    private void addLabelRow(JPanel grid, GridBagConstraints gbc, int row, String title, JLabel valueLabel, Font titleFont, Font valueFont) {
        gbc.gridx = 0; gbc.gridy = row;
        gbc.weightx = 0.3;
        JLabel label = new JLabel(title);
        label.setFont(titleFont);
        label.setForeground(new Color(102, 102, 102));
        grid.add(label, gbc);
        gbc.gridx = 1; gbc.gridy = row;
        gbc.weightx = 0.7;
        valueLabel.setFont(valueFont);
        grid.add(valueLabel, gbc);
    }
}