From ed6936545d20cc490145d2936cee4387be2afd53 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期一, 22 十二月 2025 19:04:34 +0800
Subject: [PATCH] 优化了导航预览模式

---
 src/zhuye/Shouye.java |  141 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 128 insertions(+), 13 deletions(-)

diff --git a/src/zhuye/Shouye.java b/src/zhuye/Shouye.java
index 22f8fc6..8162334 100644
--- a/src/zhuye/Shouye.java
+++ b/src/zhuye/Shouye.java
@@ -35,6 +35,7 @@
 import java.awt.geom.Point2D;
 
 import publicway.Gpstoxuzuobiao;
+import publicway.Fanhuibutton;
 
 /**
  * 棣栭〉鐣岄潰 - 閫傞厤6.5瀵哥珫灞忥紝浣跨敤鐙珛鐨凪apRenderer杩涜缁樺埗
@@ -561,7 +562,7 @@
 	private void showSettingsReturnButton() {
 		ensureFloatingButtonInfrastructure();
 		if (settingsReturnButton == null) {
-			settingsReturnButton = createFloatingTextButton("杩斿洖");
+			settingsReturnButton = Fanhuibutton.createReturnButton(null);
 			settingsReturnButton.setToolTipText("杩斿洖绯荤粺璁剧疆");
 			settingsReturnButton.addActionListener(e -> {
 				// 鍏抽棴鎵�鏈夌浉鍏虫ā寮�
@@ -1411,6 +1412,8 @@
 		remoteBtn.addActionListener(e -> showRemoteControlDialog());
 		areaSelectBtn.addActionListener(e -> {
 			// 鐐瑰嚮鈥滃湴鍧椻�濈洿鎺ユ墦寮�鍦板潡绠$悊瀵硅瘽妗嗭紙鑻ラ渶瑕佸彲浼犲叆鐗瑰畾鍦板潡缂栧彿锛�
+//			Dikuaiguanli.showDikuaiManagement(this, null);
+			// 鐩存帴杩涘叆鍦板潡绠$悊鐣岄潰
 			Dikuaiguanli.showDikuaiManagement(this, null);
 		});
 		baseStationBtn.addActionListener(e -> showBaseStationDialog());
@@ -2125,7 +2128,12 @@
 			updateStopButtonIcon();
 		}
 		if (statusLabel != null) {
-			statusLabel.setText(storedStatusBeforeDrawing != null ? storedStatusBeforeDrawing : "寰呮満");
+			// 濡傛灉鏄線杩旇矾寰勭粯鍒讹紝閫�鍑烘椂鎭㈠涓�"寰呮満"
+			if (returnPathDrawer != null && returnPathDrawer.isActive()) {
+				statusLabel.setText("寰呮満");
+			} else {
+				statusLabel.setText(storedStatusBeforeDrawing != null ? storedStatusBeforeDrawing : "寰呮満");
+			}
 		}
 		storedStatusBeforeDrawing = null;
 	}
@@ -2437,6 +2445,12 @@
 		mapRenderer.setHandheldMowerIconActive(active);
 	}
 
+	public void setStatusLabelText(String text) {
+		if (statusLabel != null) {
+			statusLabel.setText(text);
+		}
+	}
+
 	public boolean startMowerBoundaryCapture() {
 		if (mapRenderer == null) {
 			return false;
@@ -3080,7 +3094,11 @@
 		if (drawingControlModeActive) {
 			updateDrawingControlButtonLabels();
 			if (statusLabel != null) {
-				statusLabel.setText(paused ? "缁樺埗鏆傚仠" : "缁樺埗涓�");
+				if (returnPathDrawer != null && returnPathDrawer.isActive()) {
+					statusLabel.setText("姝e湪缁樺埗寰�杩旇矾寰�");
+				} else {
+					statusLabel.setText(paused ? "缁樺埗鏆傚仠" : "缁樺埗涓�");
+				}
 			}
 		}
 	}
@@ -3100,12 +3118,15 @@
 		enterDrawingControlMode();
 		
 		// 闅愯棌杩斿洖璁剧疆鎸夐挳锛堝鏋滄樉绀虹粯鍒舵寜閽紝鍒欎笉搴旇鏄剧ず杩斿洖鎸夐挳锛�
-		if (settingsReturnButton != null) {
-			settingsReturnButton.setVisible(false);
-		}
+//		if (settingsReturnButton != null) {
+//			settingsReturnButton.setVisible(false);
+//		}
 		
 		// 鏄剧ず"姝e湪缁樺埗杈圭晫"鎻愮ず
 		if (drawingBoundaryLabel != null) {
+			// 濡傛灉鏄線杩旇矾寰勭粯鍒讹紝涓嶆樉绀烘鏍囩锛堢姸鎬佹爮宸叉樉绀�"姝e湪缁樺埗寰�杩旇矾寰�"锛�
+//			boolean isReturnPathDrawing = returnPathDrawer != null && returnPathDrawer.isActive();
+//			drawingBoundaryLabel.setVisible(!isReturnPathDrawing);
 			drawingBoundaryLabel.setVisible(true);
 		}
 
@@ -3823,9 +3844,8 @@
 			endDrawingButton.setVisible(false);
 		}
 		if (pathPreviewReturnButton == null) {
-			pathPreviewReturnButton = createFloatingTextButton("杩斿洖");
+			pathPreviewReturnButton = Fanhuibutton.createReturnButton(e -> handlePathPreviewReturn());
 			pathPreviewReturnButton.setToolTipText("杩斿洖鏂板鍦板潡姝ラ");
-			pathPreviewReturnButton.addActionListener(e -> handlePathPreviewReturn());
 		}
 		pathPreviewReturnButton.setVisible(true);
 		if (floatingButtonPanel != null) {
@@ -4149,13 +4169,14 @@
     /**
      * 鍚姩寰�杩旇矾寰勭粯鍒�
      * @param finishCallback 瀹屾垚缁樺埗鏃剁殑鍥炶皟
+     * @param isHandheld 鏄惁浣跨敤鎵嬫寔璁惧妯″紡
      * @return 鏄惁鎴愬姛鍚姩
      */
-    public boolean startReturnPathDrawing(Runnable finishCallback) {
+    public boolean startReturnPathDrawing(Runnable finishCallback, boolean isHandheld) {
         if (returnPathDrawer == null) {
             return false;
         }
-        return returnPathDrawer.start(finishCallback);
+        return returnPathDrawer.start(finishCallback, isHandheld);
     }
     
     /**
@@ -4223,12 +4244,12 @@
         
         // 鍒涘缓鎴栨樉绀鸿繑鍥炴寜閽�
         if (pathPreviewReturnButton == null) {
-            pathPreviewReturnButton = publicway.buttonset.createStyledButton("杩斿洖", null);
-            pathPreviewReturnButton.setToolTipText("杩斿洖缁樺埗椤甸潰");
-            pathPreviewReturnButton.addActionListener(e -> {
+            // 浣跨敤 Fanhuibutton 鍒涘缓杩斿洖鎸夐挳
+            pathPreviewReturnButton = publicway.Fanhuibutton.createReturnButton(e -> {
                 // 鍋滄棰勮
                 stopReturnPathPreview();
             });
+            pathPreviewReturnButton.setToolTipText("杩斿洖缁樺埗椤甸潰");
         }
         
         // 闅愯棌鍏朵粬鎮诞鎸夐挳
@@ -4275,6 +4296,100 @@
             pathPreviewReturnAction.run();
         }
     }
+    
+    /**
+     * 鏄剧ず杈圭晫棰勮锛堝師濮嬭竟鐣�-绱壊锛屼紭鍖栧悗杈圭晫-缁胯壊锛�
+     * @param dikuai 鍦板潡瀵硅薄
+     * @param optimizedBoundary 浼樺寲鍚庣殑杈圭晫鍧愭爣瀛楃涓�
+     * @param returnCallback 杩斿洖鍥炶皟
+     */
+    public static void showBoundaryPreview(dikuai.Dikuai dikuai, String optimizedBoundary, Runnable returnCallback) {
+        Shouye shouye = getInstance();
+        if (shouye == null || shouye.mapRenderer == null || dikuai == null) {
+            return;
+        }
+        
+        // 鑾峰彇鍘熷杈圭晫XY鍧愭爣
+        String originalBoundaryXY = dikuai.getBoundaryOriginalXY();
+        
+        // 璁剧疆杈圭晫棰勮
+        shouye.mapRenderer.setBoundaryPreview(originalBoundaryXY, optimizedBoundary);
+        
+        // 鍋滄缁樺埗鍓茶崏鏈哄疄鏃舵嫋灏�
+        if (shouye.mapRenderer != null) {
+            shouye.mapRenderer.setIdleTrailSuppressed(true);
+        }
+        
+        // 璁剧疆杩斿洖鍥炶皟
+        shouye.pathPreviewReturnAction = returnCallback;
+        shouye.pathPreviewActive = true;
+        
+        // 纭繚鎮诞鎸夐挳鍩虹璁炬柦宸插垱寤�
+        shouye.ensureFloatingButtonInfrastructure();
+        
+        // 鍒涘缓鎴栨樉绀鸿繑鍥炴寜閽�
+        if (shouye.pathPreviewReturnButton == null) {
+            shouye.pathPreviewReturnButton = publicway.Fanhuibutton.createReturnButton(e -> shouye.handleBoundaryPreviewReturn());
+            shouye.pathPreviewReturnButton.setToolTipText("杩斿洖杈圭晫缂栬緫椤甸潰");
+        }
+        
+        // 闅愯棌鍏朵粬鎮诞鎸夐挳
+        shouye.hideFloatingDrawingControls();
+        
+        // 鏄剧ず杩斿洖鎸夐挳
+        shouye.pathPreviewReturnButton.setVisible(true);
+        if (shouye.floatingButtonPanel != null) {
+            shouye.floatingButtonPanel.setVisible(true);
+            if (shouye.floatingButtonPanel.getParent() != shouye.visualizationPanel) {
+                shouye.visualizationPanel.add(shouye.floatingButtonPanel, BorderLayout.SOUTH);
+            }
+        }
+        shouye.rebuildFloatingButtonColumn();
+        
+        shouye.visualizationPanel.revalidate();
+        shouye.visualizationPanel.repaint();
+    }
+    
+    /**
+     * 澶勭悊杈圭晫棰勮杩斿洖
+     */
+    private void handleBoundaryPreviewReturn() {
+        Runnable callback = pathPreviewReturnAction;
+        exitBoundaryPreview();
+        if (callback != null) {
+            callback.run();
+        }
+    }
+    
+    /**
+     * 閫�鍑鸿竟鐣岄瑙�
+     */
+    private void exitBoundaryPreview() {
+        pathPreviewActive = false;
+        
+        // 鎭㈠缁樺埗鍓茶崏鏈哄疄鏃舵嫋灏�
+        if (mapRenderer != null) {
+            mapRenderer.setIdleTrailSuppressed(false);
+        }
+        
+        // 娓呴櫎杈圭晫棰勮
+        if (mapRenderer != null) {
+            mapRenderer.clearBoundaryPreview();
+        }
+        
+        // 闅愯棌杩斿洖鎸夐挳
+        if (pathPreviewReturnButton != null) {
+            pathPreviewReturnButton.setVisible(false);
+        }
+        
+        // 闅愯棌鎮诞闈㈡澘
+        if (floatingButtonPanel != null) {
+            floatingButtonPanel.setVisible(false);
+        }
+        
+        visualizationPanel.revalidate();
+        visualizationPanel.repaint();
+    }
 
 	// 娴嬭瘯鏂规硶
     public static void main(String[] args) {

--
Gitblit v1.10.0