From 6700283f9103a45bc087838ebf3eeeeb9022dd98 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 19 十二月 2025 12:11:45 +0800
Subject: [PATCH] 新增了割草机长宽和割草安全距离属性

---
 src/set/Sets.java |  751 +++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 669 insertions(+), 82 deletions(-)

diff --git a/src/set/Sets.java b/src/set/Sets.java
index 3e5134d..5b2bafa 100644
--- a/src/set/Sets.java
+++ b/src/set/Sets.java
@@ -1,11 +1,13 @@
 package set;
 
 import baseStation.BaseStation;
+import gecaoji.Device;
+import gecaoji.MowerSafetyDistanceCalculator;
 
 import zhuye.MapRenderer;
 import zhuye.Shouye;
 import zhuye.buttonset;
-
+import zhuye.celiangmoshi;
 import javax.swing.*;
 import javax.swing.filechooser.FileNameExtensionFilter;
 
@@ -20,17 +22,20 @@
  */
 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 static final int ROW_HEIGHT = 50;  // 澧炲姞琛岄珮浠ラ�傚簲鍒嗗壊绾�
+    private static final int ITEM_PADDING = 16;  // 鍒楄〃椤瑰唴杈硅窛
     
     // 涓婚棰滆壊
     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 final Color BACKGROUND_COLOR = new Color(245, 247, 250);  // 鏇存煍鍜岀殑娴呯伆鑹茶儗鏅�
+    private final Color PANEL_BACKGROUND = new Color(255, 255, 255);  // 鐧借壊闈㈡澘
+    private final Color BORDER_COLOR = new Color(233, 236, 239);  // 娴呰竟妗嗚壊
+    private final Color DIVIDER_COLOR = new Color(233, 236, 239);  // 鍒嗗壊绾块鑹�
     
     // 璁剧疆椤圭粍浠�
     private JLabel mowerIdLabel;
+    private JLabel mowerSizeLabel;
+    private JLabel mowingSafetyDistanceLabel;
     private JLabel baseStationIdLabel;
     private JLabel handheldMarkerLabel;
     private JLabel simCardNumberLabel;
@@ -38,12 +43,15 @@
     private JLabel firmwareVersionLabel;
     private JLabel appVersionLabel;
     private JLabel idleTrailDurationLabel;
+    private JLabel boundaryLengthVisibleLabel;
+    private JLabel measurementModeEnabledLabel;
     
     private JButton mowerIdEditBtn;
+    private JButton mowerSizeEditBtn;
+    private JButton mowingSafetyDistanceEditBtn;
     private JButton baseStationIdEditBtn;
     private JButton handheldEditBtn;
     private JButton checkUpdateBtn;
-    private JButton systemDebugButton;
     private JButton feedbackButton;
     private JButton idleTrailEditBtn;
     
@@ -78,30 +86,42 @@
         setLocationRelativeTo(getParent());
         setResizable(false);
         
-        // 鍒涘缓涓诲唴瀹归潰鏉�
+        // 鍒涘缓涓诲唴瀹归潰鏉匡紙浣跨敤鏇存煍鍜岀殑娴呯伆鑹茶儗鏅級
         JPanel mainPanel = new JPanel();
-        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
+        mainPanel.setLayout(new BorderLayout());
         mainPanel.setBackground(BACKGROUND_COLOR);
         mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
         
-        // 鍒涘缓璁剧疆椤归潰鏉�
+        // 鍒涘缓璁剧疆椤归潰鏉匡紙鍦嗚鐧借壊闈㈡澘锛�
         JPanel settingsPanel = createSettingsPanel();
         
         // 娣诲姞缁勪欢鍒颁富闈㈡澘
-        mainPanel.add(settingsPanel);
-        mainPanel.add(Box.createVerticalGlue());
+        mainPanel.add(settingsPanel, BorderLayout.CENTER);
         
         add(mainPanel, BorderLayout.CENTER);
     }
     
     private JPanel createSettingsPanel() {
+        // 鍒涘缓鍦嗚鐧借壊闈㈡澘瀹瑰櫒
+        JPanel container = new JPanel() {
+            @Override
+            protected void paintComponent(Graphics g) {
+                Graphics2D g2d = (Graphics2D) g.create();
+                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+                g2d.setColor(PANEL_BACKGROUND);
+                // 缁樺埗鍦嗚鐭╁舰鑳屾櫙
+                g2d.fillRoundRect(0, 0, getWidth(), getHeight(), 16, 16);
+                g2d.dispose();
+            }
+        };
+        container.setLayout(new BorderLayout());
+        container.setOpaque(false);
+        
+        // 鍐呭闈㈡澘
         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)
-        ));
+        panel.setOpaque(false);
+        panel.setBorder(BorderFactory.createEmptyBorder(8, 0, 8, 0));
         
         // 鍓茶崏鏈虹紪鍙�
         JPanel mowerIdPanel = createSettingItemPanel("鍓茶崏鏈虹紪鍙�", 
@@ -109,6 +129,18 @@
         mowerIdLabel = (JLabel) mowerIdPanel.getClientProperty("valueLabel");
         mowerIdEditBtn = (JButton) mowerIdPanel.getClientProperty("editButton");
 
+        // 鍓茶崏鏈洪暱瀹�
+        JPanel mowerSizePanel = createSettingItemPanel("鍓茶崏鏈洪暱瀹�",
+            formatMowerSize(), true);
+        mowerSizeLabel = (JLabel) mowerSizePanel.getClientProperty("valueLabel");
+        mowerSizeEditBtn = (JButton) mowerSizePanel.getClientProperty("editButton");
+
+        // 鍓茶崏瀹夊叏璺濈
+        JPanel mowingSafetyDistancePanel = createSettingItemPanel("鍓茶崏瀹夊叏璺濈",
+            formatMowingSafetyDistance(), true);
+        mowingSafetyDistanceLabel = (JLabel) mowingSafetyDistancePanel.getClientProperty("valueLabel");
+        mowingSafetyDistanceEditBtn = (JButton) mowingSafetyDistancePanel.getClientProperty("editButton");
+
         JPanel baseStationIdPanel = createSettingItemPanel("宸垎鍩哄噯绔欑紪鍙�",
             resolveBaseStationId(), true);
         baseStationIdLabel = (JLabel) baseStationIdPanel.getClientProperty("valueLabel");
@@ -137,24 +169,52 @@
             formatIdleTrailDurationValue(), true);
         idleTrailDurationLabel = (JLabel) idleTrailPanel.getClientProperty("valueLabel");
         idleTrailEditBtn = (JButton) idleTrailPanel.getClientProperty("editButton");
+        
+        // 鏄剧ず杈圭晫璺濈璁剧疆椤�
+        JPanel boundaryLengthPanel = createBoundaryLengthPanel();
+        boundaryLengthVisibleLabel = (JLabel) boundaryLengthPanel.getClientProperty("valueLabel");
+        
+        // 寮�鍚祴閲忔ā寮忚缃」
+        JPanel measurementModePanel = createMeasurementModePanel();
+        measurementModeEnabledLabel = (JLabel) measurementModePanel.getClientProperty("valueLabel");
 
         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());
+        // 娣诲姞璁剧疆椤癸紝浣跨敤鍒嗗壊绾垮垎闅�
+        addSettingItem(panel, mowerIdPanel, true);
+        addSettingItem(panel, mowerSizePanel, true);
+        addSettingItem(panel, mowingSafetyDistancePanel, true);
+        addSettingItem(panel, baseStationIdPanel, true);
+        addSettingItem(panel, handheldPanel, true);
+        addSettingItem(panel, simCardPanel, true);
+        addSettingItem(panel, baseStationSimPanel, true);
+        addSettingItem(panel, firmwarePanel, true);
+        addSettingItem(panel, idleTrailPanel, true);
+        addSettingItem(panel, boundaryLengthPanel, true);
+        addSettingItem(panel, measurementModePanel, true);
+        addSettingItem(panel, feedbackPanel, true);
+        addSettingItem(panel, appVersionPanel, false);  // 鏈�鍚庝竴椤逛笉鍔犲垎鍓茬嚎
         
-        return panel;
+        container.add(panel, BorderLayout.CENTER);
+        return container;
+    }
+    
+    /**
+     * 娣诲姞璁剧疆椤癸紙甯﹀垎鍓茬嚎锛�
+     */
+    private void addSettingItem(JPanel container, JPanel itemPanel, boolean showDivider) {
+        container.add(itemPanel);
+        if (showDivider) {
+            // 娣诲姞鍒嗗壊绾�
+            JSeparator divider = new JSeparator();
+            divider.setForeground(DIVIDER_COLOR);
+            divider.setMaximumSize(new Dimension(Integer.MAX_VALUE, 1));
+            divider.setAlignmentX(Component.LEFT_ALIGNMENT);
+            container.add(divider);
+        }
     }
 
     private String formatIdleTrailDurationValue() {
@@ -165,18 +225,76 @@
         return seconds + "绉�";
     }
 
-    private void addRowWithSpacing(JPanel container, JPanel row) {
-        container.add(row);
-        container.add(Box.createRigidArea(new Dimension(0, ROW_SPACING)));
+    /**
+     * 灏嗗瓧绗︿覆鍊艰浆鎹负绫筹紙鍏煎鏃ф暟鎹紝濡傛灉鍊煎ぇ浜�100璁や负鏄帢绫筹紝闇�瑕侀櫎浠�100锛�
+     */
+    private double convertToMeters(String value) {
+        if (value == null || value.trim().isEmpty() || "-1".equals(value.trim())) {
+            return -1;
+        }
+        try {
+            double val = Double.parseDouble(value.trim());
+            // 濡傛灉鍊煎ぇ浜�100锛岃涓烘槸鍘樼背锛岄渶瑕佽浆鎹负绫�
+            if (val > 100) {
+                return val / 100.0;
+            }
+            return val;
+        } catch (NumberFormatException e) {
+            return -1;
+        }
     }
+
+    /**
+     * 鏍煎紡鍖栨暟鍊间负绫筹紝淇濈暀2浣嶅皬鏁�
+     */
+    private String formatMeters(double value) {
+        if (value < 0) {
+            return "鏈缃�";
+        }
+        return String.format("%.2f", value) + "m";
+    }
+
+    private String formatMowerSize() {
+        Device device = Device.getActiveDevice();
+        if (device == null) {
+            return "鏈缃�";
+        }
+        String width = device.getMowerWidth();
+        String length = device.getMowerLength();
+        double widthMeters = convertToMeters(width);
+        double lengthMeters = convertToMeters(length);
+        
+        if (widthMeters < 0 && lengthMeters < 0) {
+            return "鏈缃�";
+        }
+        
+        String widthStr = widthMeters >= 0 ? formatMeters(widthMeters) : "鏈缃�";
+        String lengthStr = lengthMeters >= 0 ? formatMeters(lengthMeters) : "鏈缃�";
+        return lengthStr + " 脳 " + widthStr;
+    }
+
+    private String formatMowingSafetyDistance() {
+        Device device = Device.getActiveDevice();
+        if (device == null) {
+            return "鏈缃�";
+        }
+        String distance = device.getMowingSafetyDistance();
+        double distanceMeters = convertToMeters(distance);
+        if (distanceMeters < 0) {
+            return "鏈缃�";
+        }
+        return formatMeters(distanceMeters);
+    }
+
     
     private JPanel createSettingItemPanel(String title, String value, boolean editable) {
         JPanel panel = new JPanel(new GridBagLayout());
-        panel.setBackground(PANEL_BACKGROUND);
+        panel.setOpaque(false);  // 閫忔槑鑳屾櫙锛岀敱瀹瑰櫒缁樺埗
         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));
+        panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING));
 
         GridBagConstraints gbc = new GridBagConstraints();
 
@@ -222,11 +340,12 @@
     
     private JPanel createAppVersionPanel() {
         JPanel panel = new JPanel(new GridBagLayout());
-        panel.setBackground(PANEL_BACKGROUND);
+        panel.setOpaque(false);  // 閫忔槑鑳屾櫙
         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));
+        panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING));
 
         GridBagConstraints gbc = new GridBagConstraints();
 
@@ -264,51 +383,14 @@
         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.setOpaque(false);  // 閫忔槑鑳屾櫙
         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));
+        panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING));
 
         GridBagConstraints gbc = new GridBagConstraints();
 
@@ -336,6 +418,253 @@
         return panel;
     }
     
+    /**
+     * 鍒涘缓鏄剧ず杈圭晫璺濈璁剧疆闈㈡澘
+     */
+    private JPanel createBoundaryLengthPanel() {
+        JPanel panel = new JPanel(new GridBagLayout());
+        panel.setOpaque(false);  // 閫忔槑鑳屾櫙
+        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));
+        panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING));
+
+        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);
+
+        boundaryLengthVisibleLabel = new JLabel(setData.isBoundaryLengthVisible() ? "宸插紑鍚�" : "宸插叧闂�");
+        boundaryLengthVisibleLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+        boundaryLengthVisibleLabel.setForeground(Color.DARK_GRAY);
+        gbc = new GridBagConstraints();
+        gbc.gridx = 1;
+        gbc.gridy = 0;
+        gbc.weightx = 1.0;
+        gbc.anchor = GridBagConstraints.EAST;
+        panel.add(boundaryLengthVisibleLabel, gbc);
+
+        panel.putClientProperty("valueLabel", boundaryLengthVisibleLabel);
+
+        // 鍒涘缓鍒囨崲鎸夐挳锛堜娇鐢ㄥ浘鏍囷級
+        JButton toggleBtn = createBoundaryLengthToggleButton();
+        gbc = new GridBagConstraints();
+        gbc.gridx = 2;
+        gbc.gridy = 0;
+        gbc.weightx = 0;
+        gbc.anchor = GridBagConstraints.EAST;
+        panel.add(toggleBtn, gbc);
+        panel.putClientProperty("toggleButton", toggleBtn);
+
+        return panel;
+    }
+    
+    /**
+     * 鍒涘缓寮�鍚祴閲忔ā寮忚缃潰鏉�
+     */
+    private JPanel createMeasurementModePanel() {
+        JPanel panel = new JPanel(new GridBagLayout());
+        panel.setOpaque(false);  // 閫忔槑鑳屾櫙
+        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));
+        panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING));
+
+        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);
+
+        measurementModeEnabledLabel = new JLabel(setData.isMeasurementModeEnabled() ? "宸插紑鍚�" : "宸插叧闂�");
+        measurementModeEnabledLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+        measurementModeEnabledLabel.setForeground(Color.DARK_GRAY);
+        gbc = new GridBagConstraints();
+        gbc.gridx = 1;
+        gbc.gridy = 0;
+        gbc.weightx = 1.0;
+        gbc.anchor = GridBagConstraints.EAST;
+        panel.add(measurementModeEnabledLabel, gbc);
+
+        panel.putClientProperty("valueLabel", measurementModeEnabledLabel);
+
+        // 鍒涘缓鍒囨崲鎸夐挳锛堜娇鐢ㄥ浘鏍囷級
+        JButton toggleBtn = createMeasurementModeToggleButton();
+        gbc = new GridBagConstraints();
+        gbc.gridx = 2;
+        gbc.gridy = 0;
+        gbc.weightx = 0;
+        gbc.anchor = GridBagConstraints.EAST;
+        panel.add(toggleBtn, gbc);
+        panel.putClientProperty("toggleButton", toggleBtn);
+
+        return panel;
+    }
+    
+    /**
+     * 鍒涘缓娴嬮噺妯″紡鍒囨崲鎸夐挳
+     */
+    private JButton createMeasurementModeToggleButton() {
+        JButton button = new JButton();
+        button.setContentAreaFilled(false);
+        button.setBorder(null);
+        button.setFocusPainted(false);
+        button.setCursor(new Cursor(Cursor.HAND_CURSOR));
+        button.setPreferredSize(new Dimension(32, 32));
+        button.setMinimumSize(new Dimension(32, 32));
+        button.setMaximumSize(new Dimension(32, 32));
+        
+        updateMeasurementModeToggleButton(button);
+        
+        button.addActionListener(e -> toggleMeasurementMode(button));
+        
+        return button;
+    }
+    
+    /**
+     * 鏇存柊娴嬮噺妯″紡鍒囨崲鎸夐挳鍥炬爣
+     */
+    private void updateMeasurementModeToggleButton(JButton button) {
+        boolean isEnabled = setData.isMeasurementModeEnabled();
+        try {
+            String iconPath = isEnabled ? "image/open.png" : "image/close.png";
+            ImageIcon icon = new ImageIcon(iconPath);
+            if (icon.getIconWidth() > 0) {
+                Image scaledImage = icon.getImage().getScaledInstance(32, 32, Image.SCALE_SMOOTH);
+                button.setIcon(new ImageIcon(scaledImage));
+                button.setText(null);
+            } else {
+                button.setIcon(null);
+                button.setText(isEnabled ? "寮�" : "鍏�");
+            }
+        } catch (Exception e) {
+            button.setIcon(null);
+            button.setText(isEnabled ? "寮�" : "鍏�");
+            System.err.println("鏃犳硶鍔犺浇娴嬮噺妯″紡鍥炬爣: " + e.getMessage());
+        }
+    }
+    
+    /**
+     * 鍒囨崲娴嬮噺妯″紡鐘舵��
+     */
+    private void toggleMeasurementMode(JButton button) {
+        boolean newValue = !setData.isMeasurementModeEnabled();
+        setData.setMeasurementModeEnabled(newValue);
+        
+        // 淇濆瓨鍒伴厤缃枃浠�
+        setData.updateProperty("measurementModeEnabled", String.valueOf(newValue));
+        
+        // 鏇存柊UI
+        if (measurementModeEnabledLabel != null) {
+            measurementModeEnabledLabel.setText(newValue ? "宸插紑鍚�" : "宸插叧闂�");
+        }
+        updateMeasurementModeToggleButton(button);
+        
+        // 閫氱煡MapRenderer鏇存柊
+        Shouye shouye = Shouye.getInstance();
+        if (shouye != null) {
+            MapRenderer renderer = shouye.getMapRenderer();
+            if (renderer != null) {
+                renderer.setMeasurementMode(newValue);
+            }
+            if (newValue) {
+                celiangmoshi.start();
+            } else {
+                celiangmoshi.stop();
+            }
+            // 鍒锋柊鍦板浘鏄剧ず锛堥�氳繃MapRenderer瑙﹀彂閲嶇粯锛�
+            if (renderer != null) {
+                renderer.repaint();
+            }
+        }
+    }
+    
+    /**
+     * 鍒涘缓杈圭晫璺濈鏄剧ず鍒囨崲鎸夐挳
+     */
+    private JButton createBoundaryLengthToggleButton() {
+        JButton button = new JButton();
+        button.setContentAreaFilled(false);
+        button.setBorder(null);
+        button.setFocusPainted(false);
+        button.setCursor(new Cursor(Cursor.HAND_CURSOR));
+        button.setPreferredSize(new Dimension(32, 32));
+        button.setMinimumSize(new Dimension(32, 32));
+        button.setMaximumSize(new Dimension(32, 32));
+        
+        updateBoundaryLengthToggleButton(button);
+        
+        button.addActionListener(e -> toggleBoundaryLengthVisible(button));
+        
+        return button;
+    }
+    
+    /**
+     * 鏇存柊杈圭晫璺濈鍒囨崲鎸夐挳鍥炬爣
+     */
+    private void updateBoundaryLengthToggleButton(JButton button) {
+        boolean isVisible = setData.isBoundaryLengthVisible();
+        try {
+            String iconPath = isVisible ? "image/open.png" : "image/close.png";
+            ImageIcon icon = new ImageIcon(iconPath);
+            if (icon.getIconWidth() > 0) {
+                Image scaledImage = icon.getImage().getScaledInstance(32, 32, Image.SCALE_SMOOTH);
+                button.setIcon(new ImageIcon(scaledImage));
+                button.setText(null);
+            } else {
+                button.setIcon(null);
+                button.setText(isVisible ? "寮�" : "鍏�");
+            }
+        } catch (Exception e) {
+            button.setIcon(null);
+            button.setText(isVisible ? "寮�" : "鍏�");
+            System.err.println("鏃犳硶鍔犺浇杈圭晫璺濈鍥炬爣: " + e.getMessage());
+        }
+    }
+    
+    /**
+     * 鍒囨崲杈圭晫璺濈鏄剧ず鐘舵��
+     */
+    private void toggleBoundaryLengthVisible(JButton button) {
+        boolean newValue = !setData.isBoundaryLengthVisible();
+        setData.setBoundaryLengthVisible(newValue);
+        
+        // 淇濆瓨鍒伴厤缃枃浠�
+        setData.updateProperty("boundaryLengthVisible", String.valueOf(newValue));
+        
+        // 鏇存柊UI
+        if (boundaryLengthVisibleLabel != null) {
+            boundaryLengthVisibleLabel.setText(newValue ? "宸插紑鍚�" : "宸插叧闂�");
+        }
+        updateBoundaryLengthToggleButton(button);
+        
+        // 閫氱煡MapRenderer鏇存柊
+        Shouye shouye = Shouye.getInstance();
+        if (shouye != null) {
+            MapRenderer renderer = shouye.getMapRenderer();
+            if (renderer != null) {
+                renderer.setBoundaryLengthVisible(newValue);
+            }
+        }
+    }
+    
     private JButton createEditButton() {
         JButton button = new JButton();
         try {
@@ -372,7 +701,54 @@
         // 浠嶴etsys绫诲姞杞芥暟鎹�
         setData.initializeFromProperties();
         baseStation.load();
+        // 浠巇evice.properties鍔犺浇璁惧鏁版嵁
+        Device device = Device.getActiveDevice();
+        if (device != null) {
+            device.initFromProperties();
+        }
         updateDisplay();
+        // 鍔犺浇骞跺簲鐢ㄤ笂娆′繚瀛樼殑瑙嗗浘涓績鍧愭爣
+        loadViewCenterFromProperties();
+    }
+    
+    /**
+     * 浠庨厤缃枃浠跺姞杞借鍥句腑蹇冨潗鏍囧苟搴旂敤鍒癕apRenderer
+     */
+    private void loadViewCenterFromProperties() {
+        Shouye shouye = Shouye.getInstance();
+        if (shouye == null) {
+            return;
+        }
+        MapRenderer renderer = shouye.getMapRenderer();
+        if (renderer == null) {
+            return;
+        }
+        
+        // 浠庨厤缃枃浠惰鍙栬鍥句腑蹇冨潗鏍�
+        String viewCenterXValue = Setsys.getPropertyValue("viewCenterX");
+        String viewCenterYValue = Setsys.getPropertyValue("viewCenterY");
+        
+        double savedTranslateX = 0.0;
+        double savedTranslateY = 0.0;
+        
+        if (viewCenterXValue != null && !viewCenterXValue.trim().isEmpty()) {
+            try {
+                savedTranslateX = Double.parseDouble(viewCenterXValue.trim());
+            } catch (NumberFormatException e) {
+                savedTranslateX = 0.0;
+            }
+        }
+        if (viewCenterYValue != null && !viewCenterYValue.trim().isEmpty()) {
+            try {
+                savedTranslateY = Double.parseDouble(viewCenterYValue.trim());
+            } catch (NumberFormatException e) {
+                savedTranslateY = 0.0;
+            }
+        }
+        
+        // 搴旂敤瑙嗗浘涓績鍧愭爣锛堜繚鎸佸綋鍓嶇缉鏀炬瘮渚嬶級
+        double currentScale = renderer.getScale();
+        renderer.setViewTransform(currentScale, savedTranslateX, savedTranslateY);
     }
     
     private void updateDisplay() {
@@ -381,6 +757,16 @@
             mowerIdLabel.setText(setData.getMowerId() != null ? setData.getMowerId() : "鏈缃�");
         }
 
+        // 鏇存柊鍓茶崏鏈洪暱瀹芥樉绀�
+        if (mowerSizeLabel != null) {
+            mowerSizeLabel.setText(formatMowerSize());
+        }
+
+        // 鏇存柊鍓茶崏瀹夊叏璺濈鏄剧ず
+        if (mowingSafetyDistanceLabel != null) {
+            mowingSafetyDistanceLabel.setText(formatMowingSafetyDistance());
+        }
+
         if (baseStationIdLabel != null) {
             baseStationIdLabel.setText(resolveBaseStationId());
         }
@@ -409,6 +795,32 @@
             idleTrailDurationLabel.setText(formatIdleTrailDurationValue());
         }
         
+        // 鏇存柊鏄剧ず杈圭晫璺濈鐘舵��
+        if (boundaryLengthVisibleLabel != null) {
+            boundaryLengthVisibleLabel.setText(setData.isBoundaryLengthVisible() ? "宸插紑鍚�" : "宸插叧闂�");
+        }
+        // 鏇存柊鍒囨崲鎸夐挳鍥炬爣
+        JPanel boundaryLengthPanel = (JPanel) boundaryLengthVisibleLabel.getParent();
+        if (boundaryLengthPanel != null) {
+            JButton toggleBtn = (JButton) boundaryLengthPanel.getClientProperty("toggleButton");
+            if (toggleBtn != null) {
+                updateBoundaryLengthToggleButton(toggleBtn);
+            }
+        }
+        
+        // 鏇存柊娴嬮噺妯″紡鐘舵��
+        if (measurementModeEnabledLabel != null) {
+            measurementModeEnabledLabel.setText(setData.isMeasurementModeEnabled() ? "宸插紑鍚�" : "宸插叧闂�");
+        }
+        // 鏇存柊娴嬮噺妯″紡鍒囨崲鎸夐挳鍥炬爣
+        JPanel measurementModePanel = (JPanel) measurementModeEnabledLabel.getParent();
+        if (measurementModePanel != null) {
+            JButton toggleBtn = (JButton) measurementModePanel.getClientProperty("toggleButton");
+            if (toggleBtn != null) {
+                updateMeasurementModeToggleButton(toggleBtn);
+            }
+        }
+        
         // 鏇存柊APP鐗堟湰鏄剧ず
         if (appVersionLabel != null) {
             appVersionLabel.setText(setData.getAppVersion() != null ? 
@@ -452,6 +864,16 @@
             mowerIdEditBtn.addActionListener(e -> editMowerId());
         }
 
+        // 鍓茶崏鏈洪暱瀹界紪杈戞寜閽簨浠�
+        if (mowerSizeEditBtn != null) {
+            mowerSizeEditBtn.addActionListener(e -> editMowerSize());
+        }
+
+        // 鍓茶崏瀹夊叏璺濈缂栬緫鎸夐挳浜嬩欢
+        if (mowingSafetyDistanceEditBtn != null) {
+            mowingSafetyDistanceEditBtn.addActionListener(e -> editMowingSafetyDistance());
+        }
+
         if (baseStationIdEditBtn != null) {
             baseStationIdEditBtn.addActionListener(e -> editBaseStationId());
         }
@@ -469,10 +891,6 @@
             feedbackButton.addActionListener(e -> showFeedbackDialog());
         }
 
-        if (systemDebugButton != null) {
-            systemDebugButton.addActionListener(e -> openSystemDebugDialog());
-        }
-
         if (idleTrailEditBtn != null) {
             idleTrailEditBtn.addActionListener(e -> editIdleTrailDuration());
         }
@@ -504,6 +922,181 @@
         }
     }
 
+    private void editMowerSize() {
+        Device device = Device.getActiveDevice();
+        if (device == null) {
+            JOptionPane.showMessageDialog(this, "璁惧鏈垵濮嬪寲", "閿欒", JOptionPane.ERROR_MESSAGE);
+            return;
+        }
+
+        // 鑾峰彇褰撳墠鍊煎苟杞崲涓虹背锛堝吋瀹规棫鏁版嵁锛�
+        double currentLengthMeters = convertToMeters(device.getMowerLength());
+        double currentWidthMeters = convertToMeters(device.getMowerWidth());
+        
+        String currentLengthStr = currentLengthMeters >= 0 ? String.format("%.2f", currentLengthMeters) : "";
+        String currentWidthStr = currentWidthMeters >= 0 ? String.format("%.2f", currentWidthMeters) : "";
+
+        // 鍒涘缓杈撳叆瀵硅瘽妗�
+        JPanel inputPanel = new JPanel(new GridLayout(2, 2, 5, 5));
+        inputPanel.add(new JLabel("闀垮害(m):"));
+        JTextField lengthField = new JTextField(currentLengthStr);
+        inputPanel.add(lengthField);
+        inputPanel.add(new JLabel("瀹藉害(m):"));
+        JTextField widthField = new JTextField(currentWidthStr);
+        inputPanel.add(widthField);
+
+        int result = JOptionPane.showConfirmDialog(this,
+            inputPanel,
+            "淇敼鍓茶崏鏈洪暱瀹�",
+            JOptionPane.OK_CANCEL_OPTION,
+            JOptionPane.QUESTION_MESSAGE);
+
+        if (result == JOptionPane.OK_OPTION) {
+            String newLength = lengthField.getText().trim();
+            String newWidth = widthField.getText().trim();
+
+            // 楠岃瘉杈撳叆
+            if (newLength.isEmpty() && newWidth.isEmpty()) {
+                JOptionPane.showMessageDialog(this, "闀垮害鍜屽搴︿笉鑳藉悓鏃朵负绌�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+                return;
+            }
+
+            double lengthValue = -1;
+            double widthValue = -1;
+
+            if (!newLength.isEmpty()) {
+                try {
+                    lengthValue = Double.parseDouble(newLength);
+                    if (lengthValue < 0) {
+                        JOptionPane.showMessageDialog(this, "闀垮害蹇呴』澶т簬绛変簬0", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+                        return;
+                    }
+                } catch (NumberFormatException e) {
+                    JOptionPane.showMessageDialog(this, "闀垮害蹇呴』鏄湁鏁堢殑鏁板瓧", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+                    return;
+                }
+            }
+
+            if (!newWidth.isEmpty()) {
+                try {
+                    widthValue = Double.parseDouble(newWidth);
+                    if (widthValue < 0) {
+                        JOptionPane.showMessageDialog(this, "瀹藉害蹇呴』澶т簬绛変簬0", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+                        return;
+                    }
+                } catch (NumberFormatException e) {
+                    JOptionPane.showMessageDialog(this, "瀹藉害蹇呴』鏄湁鏁堢殑鏁板瓧", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+                    return;
+                }
+            }
+
+            // 鏇存柊璁惧灞炴�э紙淇濆瓨涓虹背锛屼繚鐣�2浣嶅皬鏁帮級
+            if (lengthValue >= 0) {
+                String lengthStr = String.format("%.2f", lengthValue);
+                device.setMowerLength(lengthStr);
+                device.updateField("mowerLength", lengthStr);
+            } else {
+                device.setMowerLength("-1");
+                device.updateField("mowerLength", "-1");
+            }
+
+            if (widthValue >= 0) {
+                String widthStr = String.format("%.2f", widthValue);
+                device.setMowerWidth(widthStr);
+                device.updateField("mowerWidth", widthStr);
+            } else {
+                device.setMowerWidth("-1");
+                device.updateField("mowerWidth", "-1");
+            }
+
+            // 濡傛灉闀垮害鍜屽搴﹂兘鏈夋晥锛岃嚜鍔ㄨ绠楀畨鍏ㄨ窛绂�
+            if (lengthValue > 0 && widthValue > 0) {
+                try {
+                    double safetyDistance = MowerSafetyDistanceCalculator.calculateSafetyDistance(lengthValue, widthValue);
+                    String safetyDistanceStr = String.format("%.2f", safetyDistance);
+                    device.setMowingSafetyDistance(safetyDistanceStr);
+                    device.updateField("mowingSafetyDistance", safetyDistanceStr);
+                    
+                    // 鏇存柊瀹夊叏璺濈鏄剧ず
+                    if (mowingSafetyDistanceLabel != null) {
+                        mowingSafetyDistanceLabel.setText(formatMowingSafetyDistance());
+                    }
+                } catch (IllegalArgumentException e) {
+                    // 濡傛灉璁$畻澶辫触锛屼笉鏇存柊瀹夊叏璺濈
+                    System.err.println("璁$畻瀹夊叏璺濈澶辫触: " + e.getMessage());
+                }
+            }
+
+            // 淇濆瓨鍒癲evice.properties
+            device.saveToProperties();
+
+            // 鏇存柊鏄剧ず
+            if (mowerSizeLabel != null) {
+                mowerSizeLabel.setText(formatMowerSize());
+            }
+            JOptionPane.showMessageDialog(this, "鍓茶崏鏈洪暱瀹芥洿鏂版垚鍔�" + 
+                (lengthValue > 0 && widthValue > 0 ? "锛屽畨鍏ㄨ窛绂诲凡鑷姩璁$畻" : ""), 
+                "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+        }
+    }
+
+    private void editMowingSafetyDistance() {
+        Device device = Device.getActiveDevice();
+        if (device == null) {
+            JOptionPane.showMessageDialog(this, "璁惧鏈垵濮嬪寲", "閿欒", JOptionPane.ERROR_MESSAGE);
+            return;
+        }
+
+        // 鑾峰彇褰撳墠鍊煎苟杞崲涓虹背锛堝吋瀹规棫鏁版嵁锛�
+        double currentDistanceMeters = convertToMeters(device.getMowingSafetyDistance());
+        String currentValueStr = currentDistanceMeters >= 0 ? String.format("%.2f", currentDistanceMeters) : "";
+
+        String newValue = (String) JOptionPane.showInputDialog(this,
+            "璇疯緭鍏ュ壊鑽夊畨鍏ㄨ窛绂�(鍗曚綅:m):",
+            "淇敼鍓茶崏瀹夊叏璺濈",
+            JOptionPane.QUESTION_MESSAGE,
+            null,
+            null,
+            currentValueStr);
+
+        if (newValue == null) {
+            return; // 鐢ㄦ埛鍙栨秷
+        }
+
+        newValue = newValue.trim();
+        if (newValue.isEmpty()) {
+            JOptionPane.showMessageDialog(this, "鍓茶崏瀹夊叏璺濈涓嶈兘涓虹┖", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+
+        // 楠岃瘉杈撳叆
+        double distanceValue;
+        try {
+            distanceValue = Double.parseDouble(newValue);
+            if (distanceValue < 0) {
+                JOptionPane.showMessageDialog(this, "鍓茶崏瀹夊叏璺濈蹇呴』澶т簬绛変簬0", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+                return;
+            }
+        } catch (NumberFormatException e) {
+            JOptionPane.showMessageDialog(this, "鍓茶崏瀹夊叏璺濈蹇呴』鏄湁鏁堢殑鏁板瓧", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+
+        // 鏇存柊璁惧灞炴�э紙淇濆瓨涓虹背锛屼繚鐣�2浣嶅皬鏁帮級
+        String distanceStr = String.format("%.2f", distanceValue);
+        device.setMowingSafetyDistance(distanceStr);
+        device.updateField("mowingSafetyDistance", distanceStr);
+
+        // 淇濆瓨鍒癲evice.properties
+        device.saveToProperties();
+
+        // 鏇存柊鏄剧ず
+        if (mowingSafetyDistanceLabel != null) {
+            mowingSafetyDistanceLabel.setText(formatMowingSafetyDistance());
+        }
+        JOptionPane.showMessageDialog(this, "鍓茶崏瀹夊叏璺濈鏇存柊鎴愬姛", "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+    }
+
     private void editHandheldMarkerId() {
         String currentValue = setData.getHandheldMarkerId() != null ? setData.getHandheldMarkerId() : "";
         String newValue = (String) JOptionPane.showInputDialog(this,
@@ -790,12 +1383,6 @@
         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) {

--
Gitblit v1.10.0