From 8ce07ce9a4034fdc959d280dd38ecb3e05cbe6e1 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期三, 17 十二月 2025 16:40:11 +0800
Subject: [PATCH] 重新设计了障碍物的绘制逻辑

---
 src/dikuai/addzhangaiwu.java |  379 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 375 insertions(+), 4 deletions(-)

diff --git a/src/dikuai/addzhangaiwu.java b/src/dikuai/addzhangaiwu.java
index 5f31288..098de63 100644
--- a/src/dikuai/addzhangaiwu.java
+++ b/src/dikuai/addzhangaiwu.java
@@ -10,8 +10,11 @@
 import java.awt.Font;
 import java.awt.Image;
 import java.awt.Window;
+import java.awt.Container;
+import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.io.File;
@@ -52,6 +55,7 @@
 import zhangaiwu.Obstacledge;
 import zhangaiwu.yulanzhangaiwu;
 import zhuye.buttonset;
+import bianjie.bianjieguihua2;
 
 /**
  * 闅滅鐗╂柊澧�/缂栬緫瀵硅瘽妗嗐�傝璁¤瑷�鍙傝�� {@link AddDikuai}锛屾敮鎸侀�氳繃瀹炲湴缁樺埗閲囬泦闅滅鐗╁潗鏍囥��
@@ -88,7 +92,10 @@
     private JPanel selectedMethodPanel;
     private JPanel selectedShapePanel;
     private JButton drawButton;
+    private JButton generateBoundaryButton;  // 鐢熸垚闅滅鐗╄竟鐣屾寜閽�
+    private JButton previewButton;  // 棰勮鎸夐挳
     private JLabel drawingStatusLabel;
+    private JLabel boundaryStatusLabel;  // 鐢熸垚闅滅鐗╄竟鐣岀姸鎬佹爣绛�
     private JTextField obstacleNameField;
     private JPanel existingObstacleListPanel;
     private JPanel step1NextButtonRow;
@@ -490,6 +497,7 @@
             formData.remove("editingObstacleName");
             formData.remove("obstacleCoordinates");
             formData.remove("obstacleOriginalCoordinates");
+            formData.remove("generatedBoundaryCoordinates");  // 娓呴櫎鐢熸垚鐨勮竟鐣屽潗鏍�
             if (obstacleNameField != null) {
                 obstacleNameField.setText("");
             } else {
@@ -497,6 +505,7 @@
             }
             updateDrawingStatus();
             updateSaveButtonState();
+            updatePreviewButtonState();
         }
     }
 
@@ -539,10 +548,24 @@
 
         stepPanel.add(Box.createRigidArea(new Dimension(0, 24)));
 
+        // 鎸夐挳瀹瑰櫒锛氶噸鏂扮粯鍒� + 鐢熸垚闅滅鐗╄竟鐣�
+        JPanel buttonRow = new JPanel();
+        buttonRow.setLayout(new BoxLayout(buttonRow, BoxLayout.X_AXIS));
+        buttonRow.setOpaque(false);
+        buttonRow.setAlignmentX(Component.LEFT_ALIGNMENT);
+        
         drawButton = createPrimaryButton("寮�濮嬬粯鍒�", 16);
-        drawButton.setAlignmentX(Component.LEFT_ALIGNMENT);
         drawButton.addActionListener(e -> startDrawingWorkflow());
-        stepPanel.add(drawButton);
+        buttonRow.add(drawButton);
+        
+        buttonRow.add(Box.createRigidArea(new Dimension(10, 0)));
+        
+        generateBoundaryButton = createPrimaryButton("鐢熸垚闅滅鐗╄竟鐣�", 16);
+        generateBoundaryButton.setVisible(false);  // 鍒濆闅愯棌锛岀粯鍒跺畬鎴愬悗鏄剧ず
+        generateBoundaryButton.addActionListener(e -> generateObstacleBoundary());
+        buttonRow.add(generateBoundaryButton);
+        
+        stepPanel.add(buttonRow);
 
         stepPanel.add(Box.createRigidArea(new Dimension(0, 12)));
 
@@ -551,6 +574,15 @@
         drawingStatusLabel.setForeground(LIGHT_TEXT);
         drawingStatusLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
         stepPanel.add(drawingStatusLabel);
+        
+        // 娣诲姞鐢熸垚闅滅鐗╄竟鐣岀姸鎬佹爣绛�
+        stepPanel.add(Box.createRigidArea(new Dimension(0, 8)));
+        boundaryStatusLabel = new JLabel("");
+        boundaryStatusLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 13));
+        boundaryStatusLabel.setForeground(LIGHT_TEXT);
+        boundaryStatusLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
+        boundaryStatusLabel.setVisible(false);  // 鍒濆闅愯棌
+        stepPanel.add(boundaryStatusLabel);
 
         stepPanel.add(Box.createVerticalGlue());
         return stepPanel;
@@ -567,12 +599,21 @@
         // 璁剧疆涓嬩竴姝ユ寜閽搴︿负300鍍忕礌
         nextButton.setPreferredSize(new Dimension(300, nextButton.getPreferredSize().height));
         nextButton.setMaximumSize(new Dimension(300, nextButton.getPreferredSize().height));
+        
+        previewButton = createSecondaryButton("棰勮");
+        previewButton.setVisible(false);  // 鍒濆闅愯棌锛岀敓鎴愯竟鐣屽悗鏄剧ず
+        previewButton.setOpaque(true);
+        previewButton.setContentAreaFilled(true);
+        previewButton.addActionListener(e -> previewObstacleBoundary());
+        
         saveButton = createPrimaryButton("淇濆瓨", 16);
         saveButton.setVisible(false);
 
         buttonPanel.add(prevButton);
         buttonPanel.add(Box.createHorizontalGlue());
         buttonPanel.add(Box.createRigidArea(new Dimension(12, 0)));
+        buttonPanel.add(previewButton);
+        buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
         buttonPanel.add(saveButton);
 
         attachNextButtonToStep1Row();
@@ -869,6 +910,17 @@
         }
 
         activeDrawingShape = null;
+        
+        // 閲嶆柊缁樺埗鏃舵竻闄や箣鍓嶇敓鎴愮殑杈圭晫鍧愭爣
+        formData.remove("generatedBoundaryCoordinates");
+        if (previewButton != null) {
+            previewButton.setVisible(false);
+        }
+        // 娓呴櫎杈圭晫鐘舵�佹爣绛�
+        if (boundaryStatusLabel != null) {
+            boundaryStatusLabel.setVisible(false);
+            boundaryStatusLabel.setText("");
+        }
 
         String method = formData.get("drawingMethod");
         if (!isMeaningfulValue(method)) {
@@ -1368,8 +1420,15 @@
     private void preloadData() {
         formData.remove("obstacleCoordinates");
         formData.remove("obstacleOriginalCoordinates");
+        formData.remove("generatedBoundaryCoordinates");  // 娓呴櫎鐢熸垚鐨勮竟鐣屽潗鏍�
         formData.remove("editingObstacleName");
         updateDrawingStatus();
+        updatePreviewButtonState();
+        // 娓呴櫎杈圭晫鐘舵�佹爣绛�
+        if (boundaryStatusLabel != null) {
+            boundaryStatusLabel.setVisible(false);
+            boundaryStatusLabel.setText("");
+        }
     }
 
     private void updateDrawingStatus() {
@@ -1384,14 +1443,113 @@
                 drawButton.setText("閲嶆柊缁樺埗");
                 drawButton.setEnabled(true);
             }
+            // 缁樺埗瀹屾垚鍚庢樉绀�"鐢熸垚闅滅鐗╄竟鐣�"鎸夐挳
+            if (generateBoundaryButton != null) {
+                generateBoundaryButton.setVisible(true);
+            }
         } else {
             drawingStatusLabel.setText("灏氭湭閲囬泦闅滅鐗╁潗鏍�");
             if (!drawingInProgress && drawButton != null) {
                 drawButton.setText("寮�濮嬬粯鍒�");
                 drawButton.setEnabled(true);
             }
+            // 鏈粯鍒舵椂闅愯棌"鐢熸垚闅滅鐗╄竟鐣�"鎸夐挳
+            if (generateBoundaryButton != null) {
+                generateBoundaryButton.setVisible(false);
+            }
+            // 鏈敓鎴愯竟鐣屾椂闅愯棌棰勮鎸夐挳
+            if (previewButton != null) {
+                previewButton.setVisible(false);
+            }
+            // 闅愯棌杈圭晫鐘舵�佹爣绛�
+            if (boundaryStatusLabel != null) {
+                boundaryStatusLabel.setVisible(false);
+            }
         }
         updateSaveButtonState();
+        updatePreviewButtonState();
+    }
+    
+    /**
+     * 鏇存柊杈圭晫鐘舵�佹爣绛�
+     */
+    private void updateBoundaryStatusLabel(int pointCount) {
+        if (boundaryStatusLabel == null) {
+            return;
+        }
+        if (pointCount > 0) {
+            boundaryStatusLabel.setText("鐢熸垚闅滅鐗╄竟鐣岀偣鏁帮細" + pointCount);
+            boundaryStatusLabel.setVisible(true);
+        } else {
+            boundaryStatusLabel.setText("");
+            boundaryStatusLabel.setVisible(false);
+        }
+    }
+    
+    /**
+     * 鏇存柊棰勮鎸夐挳鐨勬樉绀虹姸鎬�
+     */
+    private void updatePreviewButtonState() {
+        if (previewButton == null) {
+            return;
+        }
+        // 鍙湁鍦ㄧ敓鎴愯竟鐣屽悗鎵嶆樉绀洪瑙堟寜閽�
+        String generatedBoundary = formData.get("generatedBoundaryCoordinates");
+        boolean hasGeneratedBoundary = isMeaningfulValue(generatedBoundary);
+        
+        if (hasGeneratedBoundary) {
+            // 鐢熸垚杈圭晫鍚庯紝閲嶆柊鍒涘缓缁胯壊鐨勯瑙堟寜閽�
+            // 鑾峰彇鎸夐挳鐨勭埗瀹瑰櫒鍜屼綅缃�
+            Container parent = previewButton.getParent();
+            if (parent != null) {
+                // 淇濆瓨鍘熸湁鐨凙ctionListener
+                ActionListener[] listeners = previewButton.getActionListeners();
+                
+                // 绉婚櫎鏃ф寜閽�
+                parent.remove(previewButton);
+                
+                // 鍒涘缓鏂扮殑缁胯壊棰勮鎸夐挳锛堜娇鐢ㄤ富鎸夐挳鏍峰紡锛�
+                previewButton = createPrimaryButton("棰勮", 16);
+                previewButton.setVisible(true);
+                previewButton.setEnabled(true);
+                
+                // 鎭㈠ActionListener
+                for (ActionListener listener : listeners) {
+                    previewButton.addActionListener(listener);
+                }
+                
+                // 娣诲姞鍒扮埗瀹瑰櫒锛堝湪淇濆瓨鎸夐挳涔嬪墠锛�
+                int previewIndex = -1;
+                Component[] components = parent.getComponents();
+                for (int i = 0; i < components.length; i++) {
+                    if (components[i] instanceof JButton) {
+                        JButton btn = (JButton) components[i];
+                        if ("淇濆瓨".equals(btn.getText())) {
+                            previewIndex = i;
+                            break;
+                        }
+                    }
+                }
+                
+                if (previewIndex >= 0) {
+                    parent.add(previewButton, previewIndex);
+                    parent.add(Box.createRigidArea(new Dimension(10, 0)), previewIndex + 1);
+                } else {
+                    // 濡傛灉鎵句笉鍒颁繚瀛樻寜閽紝娣诲姞鍒版湯灏�
+                    parent.add(Box.createRigidArea(new Dimension(12, 0)));
+                    parent.add(previewButton);
+                    parent.add(Box.createRigidArea(new Dimension(10, 0)));
+                }
+                
+                // 鍒锋柊甯冨眬
+                parent.revalidate();
+                parent.repaint();
+            }
+        } else {
+            // 鏈敓鎴愯竟鐣屾椂锛岄殣钘忔寜閽�
+            previewButton.setVisible(false);
+            previewButton.setEnabled(false);
+        }
     }
 
     private int countCoordinatePairs(String coords) {
@@ -1419,16 +1577,32 @@
         if (saveButton != null) {
             boolean hasCoords = isMeaningfulValue(formData.get("obstacleCoordinates"));
             boolean hasName = isMeaningfulValue(formData.get("obstacleName"));
-            boolean enabled = hasCoords && hasName;
+            
+            // 妫�鏌ユ槸鍚︾敓鎴愪簡闅滅鐗╄竟鐣屽潗鏍�
+            String shapeKey = formData.get("obstacleShape");
+            boolean hasGeneratedBoundary = isMeaningfulValue(formData.get("generatedBoundaryCoordinates"));
+            
+            // 濡傛灉鏄杈瑰舰闅滅鐗╋紝蹇呴』鐢熸垚杈圭晫鍧愭爣鎵嶈兘淇濆瓨
+            // 濡傛灉鏄渾褰㈤殰纰嶇墿鎴栧叾浠栧舰鐘讹紝涓嶉渶瑕佺敓鎴愯竟鐣屽氨鑳戒繚瀛�
+            boolean boundaryRequirementMet = true;
+            if ("polygon".equals(shapeKey)) {
+                boundaryRequirementMet = hasGeneratedBoundary;
+            }
+            
+            boolean enabled = hasCoords && hasName && boundaryRequirementMet;
             saveButton.setEnabled(enabled);
             if (enabled) {
                 saveButton.setBackground(PRIMARY_COLOR);
                 saveButton.setForeground(WHITE);
                 saveButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
+                saveButton.setOpaque(true);
+                saveButton.setContentAreaFilled(true);
             } else {
                 saveButton.setBackground(MEDIUM_GRAY);
                 saveButton.setForeground(TEXT_COLOR);
                 saveButton.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+                saveButton.setOpaque(true);
+                saveButton.setContentAreaFilled(true);
             }
         }
     }
@@ -1466,6 +1640,7 @@
         String obstacleName = formData.get("obstacleName");
         String coordsValue = formData.get("obstacleCoordinates");
         String originalValue = formData.get("obstacleOriginalCoordinates");
+        String generatedBoundaryValue = formData.get("generatedBoundaryCoordinates");  // 鐢熸垚鐨勮竟鐣屽潗鏍�
         String shapeKey = formData.get("obstacleShape");
         String previousName = formData.get("editingObstacleName");
 
@@ -1476,6 +1651,8 @@
 
         String coords = coordsValue.trim();
         String originalCoords = isMeaningfulValue(originalValue) ? originalValue.trim() : null;
+        // 濡傛灉鏈夌敓鎴愮殑杈圭晫鍧愭爣锛屼娇鐢ㄧ敓鎴愮殑杈圭晫鍧愭爣锛涘惁鍒欎娇鐢ㄥ師濮嬪潗鏍�
+        String finalCoords = isMeaningfulValue(generatedBoundaryValue) ? generatedBoundaryValue.trim() : coords;
         String trimmedName = isMeaningfulValue(obstacleName) ? obstacleName.trim() : null;
         if (!isMeaningfulValue(trimmedName)) {
             JOptionPane.showMessageDialog(this, "闅滅鐗╁悕绉版棤鏁�", "閿欒", JOptionPane.ERROR_MESSAGE);
@@ -1487,7 +1664,7 @@
             formData.put("editingObstacleName", trimmedName);
         }
 
-        if (!persistObstacleToConfig(landNumber, previousName, trimmedName, shapeKey, coords, originalCoords)) {
+        if (!persistObstacleToConfig(landNumber, previousName, trimmedName, shapeKey, finalCoords, originalCoords)) {
             JOptionPane.showMessageDialog(this, "鍐欏叆闅滅鐗╅厤缃け璐ワ紝璇烽噸璇�", "閿欒", JOptionPane.ERROR_MESSAGE);
             return;
         }
@@ -1499,6 +1676,171 @@
         activeSession = null;
         dispose();
     }
+    
+    /**
+     * 鐢熸垚闅滅鐗╄竟鐣屽潗鏍�
+     */
+    private void generateObstacleBoundary() {
+        String originalCoords = formData.get("obstacleOriginalCoordinates");
+        if (!isMeaningfulValue(originalCoords)) {
+            JOptionPane.showMessageDialog(this, "鏃犲師濮嬪潗鏍囨暟鎹紝鏃犳硶鐢熸垚杈圭晫", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }
+        
+        String baseStation = targetDikuai.getBaseStationCoordinates();
+        if (!isMeaningfulValue(baseStation)) {
+            JOptionPane.showMessageDialog(this, "鍦板潡鏈缃熀绔欏潗鏍�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+        
+        String shapeKey = formData.get("obstacleShape");
+        if (!"polygon".equals(shapeKey)) {
+            JOptionPane.showMessageDialog(this, "鍙湁澶氳竟褰㈤殰纰嶇墿鎵嶉渶瑕佺敓鎴愯竟鐣屽潗鏍�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }
+        
+        try {
+            // 妫�鏌ョ粯鍒舵柟寮忥紝鍙湁鍓茶崏鏈虹粯鍒剁殑澶氳竟褰㈡墠璋冪敤bianjieguihua2
+            String method = formData.get("drawingMethod");
+            if (!"mower".equals(method)) {
+                JOptionPane.showMessageDialog(this, "鍙湁鍓茶崏鏈虹粯鍒剁殑澶氳竟褰㈡墠鏀寔鐢熸垚杈圭晫鍧愭爣", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+                return;
+            }
+            
+            // 灏嗗師濮嬪潗鏍囪浆鎹负Coordinate瀵硅薄鍒楄〃
+            List<Coordinate> coordinateList = parseOriginalCoordinatesToCoordinateList(originalCoords);
+            if (coordinateList.isEmpty()) {
+                JOptionPane.showMessageDialog(this, "鍘熷鍧愭爣鏁版嵁鏃犳晥", "閿欒", JOptionPane.ERROR_MESSAGE);
+                return;
+            }
+            
+            // 淇濆瓨褰撳墠鐨凜oordinate.coordinates
+            List<Coordinate> savedCoordinates = new ArrayList<>(Coordinate.coordinates);
+            
+            try {
+                // 璁剧疆鍒板叏灞�鍧愭爣鍒楄〃
+                Coordinate.coordinates.clear();
+                Coordinate.coordinates.addAll(coordinateList);
+                
+                // 璋冪敤bianjieguihua2绠楁硶鐢熸垚浼樺寲鍚庣殑澶氳竟褰㈣竟鐣屽潗鏍�
+                String optimizedCoordsStr = bianjieguihua2.processCoordinateListAuto(baseStation);
+                
+                if (optimizedCoordsStr == null || optimizedCoordsStr.trim().isEmpty()) {
+                    JOptionPane.showMessageDialog(this, "鐢熸垚杈圭晫鍧愭爣澶辫触", "閿欒", JOptionPane.ERROR_MESSAGE);
+                    return;
+                }
+                
+                // 淇濆瓨鐢熸垚鐨勮竟鐣屽潗鏍�
+                formData.put("generatedBoundaryCoordinates", optimizedCoordsStr.trim());
+                
+                // 璁$畻鐢熸垚鐨勮竟鐣岀偣鏁�
+                int boundaryPointCount = countCoordinatePairs(optimizedCoordsStr.trim());
+                
+                // 鏇存柊杈圭晫鐘舵�佹爣绛炬樉绀�
+                updateBoundaryStatusLabel(boundaryPointCount);
+                
+                // 鏇存柊棰勮鎸夐挳鏄剧ず锛堝彉鎴愮豢鑹插彲鐐瑰嚮锛�
+                updatePreviewButtonState();
+                
+                // 鏇存柊淇濆瓨鎸夐挳鐘舵�侊紙鍙樻垚鍙偣鍑伙級
+                updateSaveButtonState();
+                
+                // 寮哄埗鍒锋柊UI
+                SwingUtilities.invokeLater(() -> {
+                    if (previewButton != null) {
+                        previewButton.revalidate();
+                        previewButton.repaint();
+                    }
+                });
+                
+                JOptionPane.showMessageDialog(this, "闅滅鐗╄竟鐣屽潗鏍囧凡鐢熸垚", "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+                
+            } finally {
+                // 鎭㈠鍘熸潵鐨勫潗鏍囧垪琛�
+                Coordinate.coordinates.clear();
+                Coordinate.coordinates.addAll(savedCoordinates);
+            }
+            
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            JOptionPane.showMessageDialog(this, "鐢熸垚杈圭晫鍧愭爣鏃跺彂鐢熼敊璇�: " + ex.getMessage(), "閿欒", JOptionPane.ERROR_MESSAGE);
+        }
+    }
+    
+    /**
+     * 灏嗗師濮嬪潗鏍囧瓧绗︿覆瑙f瀽涓篊oordinate瀵硅薄鍒楄〃
+     */
+    private List<Coordinate> parseOriginalCoordinatesToCoordinateList(String originalCoords) {
+        List<Coordinate> coordinateList = new ArrayList<>();
+        if (!isMeaningfulValue(originalCoords)) {
+            return coordinateList;
+        }
+        
+        // 鍘熷鍧愭爣鏍煎紡锛氱含搴�1,鏂瑰悜1,缁忓害1,鏂瑰悜1;绾害2,鏂瑰悜2,缁忓害2,鏂瑰悜2;...
+        String[] pointStrings = originalCoords.split(";");
+        for (String pointStr : pointStrings) {
+            pointStr = pointStr.trim();
+            if (pointStr.isEmpty()) continue;
+            
+            String[] parts = pointStr.split(",");
+            if (parts.length >= 4) {
+                try {
+                    String lat = parts[0].trim();
+                    String latDir = parts[1].trim();
+                    String lon = parts[2].trim();
+                    String lonDir = parts[3].trim();
+                    
+                    Coordinate coord = new Coordinate(lat, latDir, lon, lonDir, 0.0);
+                    coordinateList.add(coord);
+                } catch (Exception e) {
+                    // 璺宠繃鏃犳晥鐨勫潗鏍囩偣
+                    continue;
+                }
+            }
+        }
+        
+        return coordinateList;
+    }
+    
+    /**
+     * 棰勮闅滅鐗╄竟鐣�
+     */
+    private void previewObstacleBoundary() {
+        String generatedBoundary = formData.get("generatedBoundaryCoordinates");
+        if (!isMeaningfulValue(generatedBoundary)) {
+            JOptionPane.showMessageDialog(this, "璇峰厛鐢熸垚闅滅鐗╄竟鐣屽潗鏍�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }
+        
+        String landNumber = targetDikuai.getLandNumber();
+        String landName = targetDikuai.getLandName();
+        String boundary = targetDikuai.getBoundaryCoordinates();
+        
+        // 鍏抽棴褰撳墠瀵硅瘽妗�
+        setVisible(false);
+        
+        SwingUtilities.invokeLater(() -> {
+            Shouye shouye = Shouye.getInstance();
+            if (shouye != null) {
+                // 浼犻�掑洖璋冧互閲嶆柊鎵撳紑鏂板闅滅鐗╂楠�2椤甸潰
+                shouye.startMowingPathPreview(
+                    landNumber,
+                    landName,
+                    boundary,
+                    generatedBoundary,  // 浣跨敤鐢熸垚鐨勮竟鐣屽潗鏍囦綔涓洪殰纰嶇墿鍧愭爣
+                    null,
+                    () -> SwingUtilities.invokeLater(() -> {
+                        // 閲嶆柊鎵撳紑鏂板闅滅鐗╂楠�2椤甸潰
+                        Window owner = SwingUtilities.getWindowAncestor(shouye);
+                        setVisible(true);
+                    })
+                );
+            } else {
+                JOptionPane.showMessageDialog(null, "鏃犳硶鎵撳紑涓婚〉闈㈣繘琛岄瑙�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+                setVisible(true);
+            }
+        });
+    }
 
     private boolean persistObstacleToConfig(String landNumber, String previousName, String obstacleName,
                                             String shapeKey, String xyCoords, String originalCoords) {
@@ -1706,10 +2048,14 @@
         if (step < 2) {
             nextButton.setVisible(true);
             saveButton.setVisible(false);
+            if (previewButton != null) {
+                previewButton.setVisible(false);
+            }
         } else {
             nextButton.setVisible(false);
             saveButton.setVisible(true);
             updateDrawingStatus();
+            updatePreviewButtonState();
         }
         updateSaveButtonState();
         revalidate();
@@ -1753,6 +2099,24 @@
         }
 
         updateDrawingStatus();
+        
+        // 濡傛灉宸叉湁鐢熸垚鐨勮竟鐣屽潗鏍囷紝鏇存柊杈圭晫鐘舵�佹爣绛�
+        String generatedBoundary = session.data.get("generatedBoundaryCoordinates");
+        if (isMeaningfulValue(generatedBoundary)) {
+            int boundaryPointCount = countCoordinatePairs(generatedBoundary);
+            updateBoundaryStatusLabel(boundaryPointCount);
+        } else {
+            // 濡傛灉娌℃湁鐢熸垚鐨勮竟鐣屽潗鏍囷紝闅愯棌杈圭晫鐘舵�佹爣绛�
+            if (boundaryStatusLabel != null) {
+                boundaryStatusLabel.setVisible(false);
+                boundaryStatusLabel.setText("");
+            }
+        }
+        
+        // 鏇存柊鎸夐挳鐘舵��
+        updatePreviewButtonState();
+        updateSaveButtonState();
+        
         currentStep = 2;
         showStep(2);
     }
@@ -1882,6 +2246,8 @@
                 BorderFactory.createLineBorder(PRIMARY_DARK, 2),
                 BorderFactory.createEmptyBorder(10, 22, 10, 22)));
         button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
+        button.setOpaque(true);
+        button.setContentAreaFilled(true);
         button.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseEntered(MouseEvent e) {
@@ -1894,6 +2260,9 @@
             public void mouseExited(MouseEvent e) {
                 if (button.isEnabled()) {
                     button.setBackground(PRIMARY_COLOR);
+                } else {
+                    // 绂佺敤鏃朵繚鎸佺伆鑹茶儗鏅�
+                    button.setBackground(MEDIUM_GRAY);
                 }
             }
         });
@@ -1908,6 +2277,8 @@
                 BorderFactory.createLineBorder(BORDER_COLOR, 2),
                 BorderFactory.createEmptyBorder(10, 22, 10, 22)));
         button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
+        button.setOpaque(true);
+        button.setContentAreaFilled(true);
         return button;
     }
 

--
Gitblit v1.10.0