| | |
| | | private JButton saveManualBoundaryButton; // 保存手动绘制边界的按钮 |
| | | private String previewRestoreLandNumber; |
| | | private String previewRestoreLandName; |
| | | private Dikuai currentBoundaryPreviewDikuai; // 当前边界预览的地块引用 |
| | | private boolean drawingPaused; |
| | | private ImageIcon pauseIcon; |
| | | private ImageIcon pauseActiveIcon; |
| | |
| | | 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; |
| | | } |
| | | |
| | | // 保存当前地块引用 |
| | | shouye.currentBoundaryPreviewDikuai = dikuai; |
| | | |
| | | // 获取原始边界XY坐标 |
| | | String originalBoundaryXY = dikuai.getBoundaryOriginalXY(); |
| | | |
| | | // 设置边界预览 |
| | | shouye.mapRenderer.setBoundaryPreview(originalBoundaryXY, optimizedBoundary); |
| | | |
| | | // 设置边界预览更新回调,用于保存删除坐标点后的边界 |
| | | shouye.mapRenderer.setBoundaryPreviewUpdateCallback(updatedBoundary -> { |
| | | if (shouye.currentBoundaryPreviewDikuai != null && updatedBoundary != null) { |
| | | // 保存更新后的边界坐标 |
| | | Dikuai.updateField(shouye.currentBoundaryPreviewDikuai.getLandNumber(), "boundaryCoordinates", updatedBoundary); |
| | | java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Dikuai.updateField(shouye.currentBoundaryPreviewDikuai.getLandNumber(), "updateTime", sdf.format(new java.util.Date())); |
| | | Dikuai.saveToProperties(); |
| | | |
| | | // 同步更新当前地块对象的内存值(确保返回时能获取到最新值) |
| | | shouye.currentBoundaryPreviewDikuai.setBoundaryCoordinates(updatedBoundary); |
| | | |
| | | // 更新预览边界(重新设置以刷新显示) |
| | | shouye.mapRenderer.setBoundaryPreview(originalBoundaryXY, updatedBoundary); |
| | | } |
| | | }); |
| | | |
| | | // 停止绘制割草机实时拖尾 |
| | | 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; |
| | | |
| | | // 清除当前地块引用 |
| | | currentBoundaryPreviewDikuai = null; |
| | | |
| | | // 恢复绘制割草机实时拖尾 |
| | | if (mapRenderer != null) { |
| | | mapRenderer.setIdleTrailSuppressed(false); |
| | | } |
| | | |
| | | // 清除边界预览 |
| | | if (mapRenderer != null) { |
| | | mapRenderer.clearBoundaryPreview(); |
| | | mapRenderer.setBoundaryPreviewUpdateCallback(null); |
| | | } |
| | | |
| | | // 隐藏返回按钮 |
| | | if (pathPreviewReturnButton != null) { |
| | | pathPreviewReturnButton.setVisible(false); |
| | | } |
| | | |
| | | // 隐藏悬浮面板 |
| | | if (floatingButtonPanel != null) { |
| | | floatingButtonPanel.setVisible(false); |
| | | } |
| | | |
| | | visualizationPanel.revalidate(); |
| | | visualizationPanel.repaint(); |
| | | } |
| | | |
| | | // 测试方法 |
| | | public static void main(String[] args) { |