| | |
| | | import java.awt.geom.Point2D; |
| | | |
| | | import publicway.Gpstoxuzuobiao; |
| | | import publicway.Fanhuibutton; |
| | | |
| | | /** |
| | | * 首页界面 - 适配6.5寸竖屏,使用独立的MapRenderer进行绘制 |
| | |
| | | private Runnable pathPreviewReturnAction; |
| | | private JButton settingsReturnButton; // 返回系统设置页面的悬浮按钮 |
| | | private JButton saveManualBoundaryButton; // 保存手动绘制边界的按钮 |
| | | private JButton toggleBoundaryDisplayButton; // 切换边界显示按钮(只显示原始边界/显示全部) |
| | | private String previewRestoreLandNumber; |
| | | private String previewRestoreLandName; |
| | | private Dikuai currentBoundaryPreviewDikuai; // 当前边界预览的地块引用 |
| | | private boolean drawingPaused; |
| | | private ImageIcon pauseIcon; |
| | | private ImageIcon pauseActiveIcon; |
| | |
| | | private void showSettingsReturnButton() { |
| | | ensureFloatingButtonInfrastructure(); |
| | | if (settingsReturnButton == null) { |
| | | settingsReturnButton = createFloatingTextButton("返回"); |
| | | settingsReturnButton = Fanhuibutton.createReturnButton(null); |
| | | settingsReturnButton.setToolTipText("返回系统设置"); |
| | | settingsReturnButton.addActionListener(e -> { |
| | | // 关闭所有相关模式 |
| | |
| | | remoteBtn.addActionListener(e -> showRemoteControlDialog()); |
| | | areaSelectBtn.addActionListener(e -> { |
| | | // 点击“地块”直接打开地块管理对话框(若需要可传入特定地块编号) |
| | | // Dikuaiguanli.showDikuaiManagement(this, null); |
| | | // 直接进入地块管理界面 |
| | | Dikuaiguanli.showDikuaiManagement(this, null); |
| | | }); |
| | | baseStationBtn.addActionListener(e -> showBaseStationDialog()); |
| | |
| | | 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 |
| | |
| | | floatingButtonColumn.add(pathPreviewReturnButton); |
| | | added = true; |
| | | } |
| | | if (toggleBoundaryDisplayButton != null && toggleBoundaryDisplayButton.isVisible()) { |
| | | if (added) { |
| | | floatingButtonColumn.add(Box.createRigidArea(new Dimension(0, 10))); |
| | | } |
| | | floatingButtonColumn.add(toggleBoundaryDisplayButton); |
| | | added = true; |
| | | } |
| | | if (saveManualBoundaryButton != null && saveManualBoundaryButton.isVisible()) { |
| | | if (added) { |
| | | floatingButtonColumn.add(Box.createRigidArea(new Dimension(0, 10))); |
| | |
| | | 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) { |
| | |
| | | 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("返回边界编辑页面"); |
| | | } |
| | | |
| | | // 创建或显示切换边界显示按钮 |
| | | if (shouye.toggleBoundaryDisplayButton == null) { |
| | | shouye.toggleBoundaryDisplayButton = shouye.createToggleBoundaryDisplayButton(); |
| | | } |
| | | |
| | | // 重置切换按钮状态(默认显示全部边界) |
| | | if (shouye.mapRenderer != null) { |
| | | shouye.mapRenderer.setShowOnlyOriginalBoundary(false); |
| | | } |
| | | shouye.updateToggleBoundaryDisplayButtonText(); |
| | | |
| | | // 隐藏其他悬浮按钮 |
| | | shouye.hideFloatingDrawingControls(); |
| | | |
| | | // 显示返回按钮和切换按钮 |
| | | shouye.pathPreviewReturnButton.setVisible(true); |
| | | shouye.toggleBoundaryDisplayButton.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); |
| | | mapRenderer.setShowOnlyOriginalBoundary(false); // 重置为显示全部边界 |
| | | } |
| | | |
| | | // 隐藏返回按钮和切换按钮 |
| | | if (pathPreviewReturnButton != null) { |
| | | pathPreviewReturnButton.setVisible(false); |
| | | } |
| | | if (toggleBoundaryDisplayButton != null) { |
| | | toggleBoundaryDisplayButton.setVisible(false); |
| | | } |
| | | |
| | | // 隐藏悬浮面板 |
| | | if (floatingButtonPanel != null) { |
| | | floatingButtonPanel.setVisible(false); |
| | | } |
| | | |
| | | visualizationPanel.revalidate(); |
| | | visualizationPanel.repaint(); |
| | | } |
| | | |
| | | /** |
| | | * 创建切换边界显示按钮 |
| | | */ |
| | | private JButton createToggleBoundaryDisplayButton() { |
| | | JButton button = new JButton("隐藏优化边界"); |
| | | button.setFont(new Font("微软雅黑", Font.PLAIN, 13)); |
| | | button.setBackground(new Color(46, 139, 87)); |
| | | button.setForeground(Color.WHITE); |
| | | button.setBorder(BorderFactory.createEmptyBorder(8, 16, 8, 16)); |
| | | button.setFocusPainted(false); |
| | | button.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
| | | button.setToolTipText("切换显示:只显示原始边界/显示全部边界"); |
| | | |
| | | button.addActionListener(e -> { |
| | | if (mapRenderer == null) { |
| | | return; |
| | | } |
| | | // 切换显示状态 |
| | | boolean currentState = mapRenderer.isShowOnlyOriginalBoundary(); |
| | | mapRenderer.setShowOnlyOriginalBoundary(!currentState); |
| | | updateToggleBoundaryDisplayButtonText(); |
| | | }); |
| | | |
| | | button.addMouseListener(new java.awt.event.MouseAdapter() { |
| | | public void mouseEntered(java.awt.event.MouseEvent e) { |
| | | button.setBackground(new Color(30, 107, 69)); |
| | | } |
| | | |
| | | public void mouseExited(java.awt.event.MouseEvent e) { |
| | | button.setBackground(new Color(46, 139, 87)); |
| | | } |
| | | }); |
| | | |
| | | return button; |
| | | } |
| | | |
| | | /** |
| | | * 更新切换边界显示按钮的文本 |
| | | */ |
| | | private void updateToggleBoundaryDisplayButtonText() { |
| | | if (toggleBoundaryDisplayButton == null || mapRenderer == null) { |
| | | return; |
| | | } |
| | | if (mapRenderer.isShowOnlyOriginalBoundary()) { |
| | | toggleBoundaryDisplayButton.setText("显示全部边界"); |
| | | } else { |
| | | toggleBoundaryDisplayButton.setText("隐藏优化边界"); |
| | | } |
| | | } |
| | | |
| | | // 测试方法 |
| | | public static void main(String[] args) { |