| | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | |
| | | private JButton saveManualBoundaryButton; // 保存手动绘制边界的按钮 |
| | | private String previewRestoreLandNumber; |
| | | private String previewRestoreLandName; |
| | | private Dikuai currentBoundaryPreviewDikuai; // 当前边界预览的地块引用 |
| | | private boolean drawingPaused; |
| | | private ImageIcon pauseIcon; |
| | | private ImageIcon pauseActiveIcon; |
| | |
| | | try { |
| | | ImageIcon settingsIcon = new ImageIcon("image/sets.png"); |
| | | // 调整图片大小以适应按钮 |
| | | Image scaledImage = settingsIcon.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH); |
| | | Image scaledImage = settingsIcon.getImage().getScaledInstance(25, 25, Image.SCALE_SMOOTH); |
| | | settingsBtn.setIcon(new ImageIcon(scaledImage)); |
| | | } catch (Exception e) { |
| | | // 如果图片加载失败,使用默认文本 |
| | |
| | | controlPanel = new JPanel(new BorderLayout()); |
| | | controlPanel.setBackground(PANEL_BACKGROUND); |
| | | controlPanel.setBorder(BorderFactory.createEmptyBorder(15, 20, 15, 20)); |
| | | controlPanel.setPreferredSize(new Dimension(0, 100)); |
| | | controlPanel.setPreferredSize(new Dimension(0, 80)); |
| | | |
| | | JPanel buttonPanel = new JPanel(new GridLayout(1, 2, 20, 0)); |
| | | buttonPanel.setBackground(PANEL_BACKGROUND); |
| | | |
| | | startBtn = createControlButton("暂停", THEME_COLOR); |
| | | startBtn = createControlButton("暂停割草", THEME_COLOR); |
| | | updateStartButtonAppearance(); |
| | | |
| | | stopBtn = createControlButton("结束", Color.ORANGE); |
| | | stopBtn = createControlButton("结束割草", Color.ORANGE); |
| | | updateStopButtonIcon(); |
| | | |
| | | buttonPanel.add(startBtn); |
| | |
| | | button.setFont(new Font("微软雅黑", Font.BOLD, 16)); |
| | | button.setBackground(color); |
| | | button.setForeground(Color.WHITE); |
| | | button.setBorder(BorderFactory.createEmptyBorder(15, 0, 15, 0)); |
| | | button.setPreferredSize(new Dimension(0, 50)); |
| | | button.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0)); |
| | | button.setFocusPainted(false); |
| | | |
| | | // 悬停效果 |
| | |
| | | updateStartButtonAppearance(); |
| | | } |
| | | if (stopBtn != null) { |
| | | stopBtn.setText("结束"); |
| | | stopBtn.setText("结束割草"); |
| | | updateStopButtonIcon(); |
| | | } |
| | | if (statusLabel != null) { |
| | |
| | | if (startBtn == null) { |
| | | return; |
| | | } |
| | | String iconPath = startButtonShowingPause ? "image/start0.png" : "image/start1.png"; |
| | | startBtn.setText(startButtonShowingPause ? "暂停" : "开始"); |
| | | applyButtonIcon(startBtn, iconPath); |
| | | startBtn.setText(startButtonShowingPause ? "暂停割草" : "开始割草"); |
| | | startBtn.setIcon(null); |
| | | } |
| | | |
| | | private void updateStopButtonIcon() { |
| | | if (stopBtn == null) { |
| | | return; |
| | | } |
| | | String iconPath = stopButtonActive ? "image/stop1.png" : "image/stop0.png"; |
| | | applyButtonIcon(stopBtn, iconPath); |
| | | stopBtn.setText("结束割草"); |
| | | stopBtn.setIcon(null); |
| | | } |
| | | |
| | | private void toggleBluetoothConnection() { |
| | |
| | | |
| | | private void ensureBluetoothIconsLoaded() { |
| | | if (bluetoothIcon == null) { |
| | | bluetoothIcon = loadScaledIcon("image/blue.png", 28, 28); |
| | | bluetoothIcon = loadScaledIcon("image/blue.png", 25, 25); |
| | | } |
| | | if (bluetoothLinkedIcon == null) { |
| | | bluetoothLinkedIcon = loadScaledIcon("image/bluelink.png", 28, 28); |
| | | bluetoothLinkedIcon = loadScaledIcon("image/bluelink.png", 25, 25); |
| | | } |
| | | } |
| | | |
| | |
| | | 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); |
| | |
| | | private void exitBoundaryPreview() { |
| | | pathPreviewActive = false; |
| | | |
| | | // 清除当前地块引用 |
| | | currentBoundaryPreviewDikuai = null; |
| | | |
| | | // 恢复绘制割草机实时拖尾 |
| | | if (mapRenderer != null) { |
| | | mapRenderer.setIdleTrailSuppressed(false); |
| | |
| | | // 清除边界预览 |
| | | if (mapRenderer != null) { |
| | | mapRenderer.clearBoundaryPreview(); |
| | | mapRenderer.setBoundaryPreviewUpdateCallback(null); |
| | | } |
| | | |
| | | // 隐藏返回按钮 |
| | |
| | | visualizationPanel.repaint(); |
| | | } |
| | | |
| | | // 测试方法 |
| | | public static void main(String[] args) { |
| | | JFrame frame = new JFrame("AutoMow - 首页"); |
| | | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| | | frame.setSize(400, 800); |
| | | frame.setLocationRelativeTo(null); |
| | | |
| | | Shouye shouye = new Shouye(); |
| | | frame.add(shouye); |
| | | |
| | | frame.setVisible(true); |
| | | UDPServer.startAsync();//启动数据接收线程 |
| | | } |
| | | } |