张世豪
2 天以前 c9b1d33979b3972fe6a82fa427b4ba9a20989112
src/zhuye/Shouye.java
@@ -35,6 +35,7 @@
import java.awt.geom.Point2D;
import publicway.Gpstoxuzuobiao;
import publicway.Fanhuibutton;
/**
 * 首页界面 - 适配6.5寸竖屏,使用独立的MapRenderer进行绘制
@@ -112,10 +113,13 @@
   private final Consumer<String> serialLineListener = line -> {
      SwingUtilities.invokeLater(() -> {
         updateDataPacketCountLabel();
         // 如果收到$GNGGA数据,立即更新拖尾
         if (line != null && line.trim().startsWith("$GNGGA")) {
            if (mapRenderer != null && !pathPreviewActive) {
               mapRenderer.forceUpdateIdleMowerTrail();
         // 如果收到GGA数据,立即更新拖尾
         if (line != null) {
            String trimmed = line.trim();
            if (trimmed.startsWith("$GNGGA") || trimmed.startsWith("$GPGGA") || trimmed.startsWith("$GBGGA")) {
               if (mapRenderer != null && !pathPreviewActive) {
                  mapRenderer.forceUpdateIdleMowerTrail();
               }
            }
         }
      });
@@ -561,7 +565,7 @@
   private void showSettingsReturnButton() {
      ensureFloatingButtonInfrastructure();
      if (settingsReturnButton == null) {
         settingsReturnButton = createFloatingTextButton("返回");
         settingsReturnButton = Fanhuibutton.createReturnButton(null);
         settingsReturnButton.setToolTipText("返回系统设置");
         settingsReturnButton.addActionListener(e -> {
            // 关闭所有相关模式
@@ -1411,6 +1415,8 @@
      remoteBtn.addActionListener(e -> showRemoteControlDialog());
      areaSelectBtn.addActionListener(e -> {
         // 点击“地块”直接打开地块管理对话框(若需要可传入特定地块编号)
//       Dikuaiguanli.showDikuaiManagement(this, null);
         // 直接进入地块管理界面
         Dikuaiguanli.showDikuaiManagement(this, null);
      });
      baseStationBtn.addActionListener(e -> showBaseStationDialog());
@@ -3115,15 +3121,16 @@
      enterDrawingControlMode();
      
      // 隐藏返回设置按钮(如果显示绘制按钮,则不应该显示返回按钮)
      if (settingsReturnButton != null) {
         settingsReturnButton.setVisible(false);
      }
//    if (settingsReturnButton != null) {
//       settingsReturnButton.setVisible(false);
//    }
      
      // 显示"正在绘制边界"提示
      if (drawingBoundaryLabel != null) {
         // 如果是往返路径绘制,不显示此标签(状态栏已显示"正在绘制往返路径")
         boolean isReturnPathDrawing = returnPathDrawer != null && returnPathDrawer.isActive();
         drawingBoundaryLabel.setVisible(!isReturnPathDrawing);
//       boolean isReturnPathDrawing = returnPathDrawer != null && returnPathDrawer.isActive();
//       drawingBoundaryLabel.setVisible(!isReturnPathDrawing);
         drawingBoundaryLabel.setVisible(true);
      }
      boolean enableCircleGuidance = drawingShape != null
@@ -3840,9 +3847,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) {
@@ -4293,18 +4299,99 @@
            pathPreviewReturnAction.run();
        }
    }
   // 测试方法
    public static void main(String[] args) {
        JFrame frame = new JFrame("AutoMow - 首页");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 800);
        frame.setLocationRelativeTo(null);
    /**
     * 显示边界预览(原始边界-紫色,优化后边界-绿色)
     * @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;
        }
        
        Shouye shouye = new Shouye();
        frame.add(shouye);
        // 获取原始边界XY坐标
        String originalBoundaryXY = dikuai.getBoundaryOriginalXY();
        
        frame.setVisible(true);
        UDPServer.startAsync();//启动数据接收线程
        // 设置边界预览
        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();
    }
}