| | |
| | | import java.awt.event.*; |
| | | |
| | | import chuankou.dellmessage; |
| | | import chuankou.sendmessage; |
| | | import chuankou.SerialPortService; |
| | | import dikuai.Dikuai; |
| | | import dikuai.Dikuaiguanli; |
| | | import dikuai.addzhangaiwu; |
| | | import gecaoji.Device; |
| | | import gecaoji.Gecaoji; |
| | | import gecaoji.MowerBoundaryChecker; |
| | | import set.Sets; |
| | | import set.debug; |
| | | import udpdell.UDPServer; |
| | | import zhangaiwu.AddDikuai; |
| | | import yaokong.Control04; |
| | |
| | | private JLabel statusLabel; |
| | | private JLabel speedLabel; // 速度显示标签 |
| | | private JLabel areaNameLabel; |
| | | |
| | | // 边界警告相关 |
| | | private Timer boundaryWarningTimer; // 边界警告检查定时器 |
| | | private Timer warningBlinkTimer; // 警告图标闪烁定时器 |
| | | private boolean isMowerOutsideBoundary = false; // 割草机是否在边界外 |
| | | private boolean warningIconVisible = true; // 警告图标显示状态(用于闪烁) |
| | | |
| | | // 以割草机为中心视图模式 |
| | | private boolean centerOnMowerMode = false; // 是否处于以割草机为中心的模式 |
| | | |
| | | // 当前选中的导航按钮 |
| | | private JButton currentNavButton; |
| | |
| | | private Sets settingsDialog; |
| | | private BaseStation baseStation; |
| | | |
| | | private final Consumer<String> serialLineListener = line -> SwingUtilities.invokeLater(this::updateDataPacketCountLabel); |
| | | |
| | | // 地图渲染器 |
| | | private MapRenderer mapRenderer; |
| | | |
| | | private final Consumer<String> serialLineListener = line -> { |
| | | SwingUtilities.invokeLater(() -> { |
| | | updateDataPacketCountLabel(); |
| | | // 如果收到$GNGGA数据,立即更新拖尾 |
| | | if (line != null && line.trim().startsWith("$GNGGA")) { |
| | | if (mapRenderer != null) { |
| | | mapRenderer.forceUpdateIdleMowerTrail(); |
| | | } |
| | | } |
| | | }); |
| | | }; |
| | | private static final int FLOAT_ICON_SIZE = 32; |
| | | private JButton endDrawingButton; |
| | | private JButton drawingPauseButton; |
| | |
| | | |
| | | initializeDefaultAreaSelection(); |
| | | refreshMapForSelectedArea(); |
| | | |
| | | // 启动边界警告检查定时器 |
| | | startBoundaryWarningTimer(); |
| | | } |
| | | |
| | | private void scheduleIdentifierCheck() { |
| | |
| | | SwingUtilities.invokeLater(() -> { |
| | | Shouye.this.checkIdentifiersAndPromptIfNeeded(); |
| | | Shouye.this.showInitialMowerSelfCheckDialogIfNeeded(); |
| | | // 设置窗口关闭监听器,在关闭时保存缩放比例 |
| | | setupWindowCloseListener(); |
| | | }); |
| | | } |
| | | } |
| | | }; |
| | | addHierarchyListener(listener); |
| | | } |
| | | |
| | | /** |
| | | * 设置窗口关闭监听器,在窗口关闭时保存当前缩放比例 |
| | | */ |
| | | private void setupWindowCloseListener() { |
| | | Window window = SwingUtilities.getWindowAncestor(this); |
| | | if (window != null && window instanceof JFrame) { |
| | | JFrame frame = (JFrame) window; |
| | | frame.addWindowListener(new WindowAdapter() { |
| | | @Override |
| | | public void windowClosing(WindowEvent e) { |
| | | // 保存当前缩放比例 |
| | | saveCurrentScale(); |
| | | // 停止边界警告定时器 |
| | | if (boundaryWarningTimer != null && boundaryWarningTimer.isRunning()) { |
| | | boundaryWarningTimer.stop(); |
| | | } |
| | | // 停止闪烁定时器 |
| | | if (warningBlinkTimer != null && warningBlinkTimer.isRunning()) { |
| | | warningBlinkTimer.stop(); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 保存当前地图缩放比例和视图中心坐标到配置文件 |
| | | */ |
| | | public void saveCurrentScale() { |
| | | if (mapRenderer != null) { |
| | | double currentScale = mapRenderer.getScale(); |
| | | double translateX = mapRenderer.getTranslateX(); |
| | | double translateY = mapRenderer.getTranslateY(); |
| | | Setsys setsys = new Setsys(); |
| | | // 保留2位小数 |
| | | setsys.updateProperty("mapScale", String.format("%.2f", currentScale)); |
| | | setsys.updateProperty("viewCenterX", String.format("%.2f", translateX)); |
| | | setsys.updateProperty("viewCenterY", String.format("%.2f", translateY)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 启动边界警告检查定时器 |
| | | */ |
| | | private void startBoundaryWarningTimer() { |
| | | // 边界检查定时器:每500ms检查一次割草机是否在边界内 |
| | | boundaryWarningTimer = new Timer(500, e -> { |
| | | checkMowerBoundaryStatus(); |
| | | // 同时更新蓝牙图标状态 |
| | | updateBluetoothButtonIcon(); |
| | | }); |
| | | boundaryWarningTimer.setInitialDelay(0); |
| | | boundaryWarningTimer.start(); |
| | | |
| | | // 闪烁定时器:每1秒切换一次警告图标显示状态 |
| | | warningBlinkTimer = new Timer(1000, e -> { |
| | | if (isMowerOutsideBoundary) { |
| | | warningIconVisible = !warningIconVisible; |
| | | if (visualizationPanel != null) { |
| | | visualizationPanel.repaint(); |
| | | } |
| | | } |
| | | }); |
| | | warningBlinkTimer.setInitialDelay(0); |
| | | warningBlinkTimer.start(); |
| | | } |
| | | |
| | | /** |
| | | * 切换以割草机为中心的模式 |
| | | */ |
| | | private void toggleCenterOnMowerMode() { |
| | | centerOnMowerMode = !centerOnMowerMode; |
| | | |
| | | if (centerOnMowerMode) { |
| | | // 开启模式:立即将视图中心移动到割草机位置 |
| | | updateViewToCenterOnMower(); |
| | | } |
| | | // 关闭模式时不需要做任何操作,用户已经可以自由移动地图 |
| | | |
| | | // 更新图标显示(重绘以切换图标) |
| | | if (visualizationPanel != null) { |
| | | visualizationPanel.repaint(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 更新视图中心到割草机位置 |
| | | */ |
| | | private void updateViewToCenterOnMower() { |
| | | if (mapRenderer == null) { |
| | | return; |
| | | } |
| | | |
| | | Gecaoji mower = mapRenderer.getMower(); |
| | | if (mower != null && mower.hasValidPosition()) { |
| | | Point2D.Double mowerPosition = mower.getPosition(); |
| | | if (mowerPosition != null) { |
| | | // 获取当前缩放比例 |
| | | double currentScale = mapRenderer.getScale(); |
| | | // 设置视图变换,使割草机位置对应到屏幕中心 |
| | | // translateX = -mowerX, translateY = -mowerY 可以让割草机在屏幕中心 |
| | | mapRenderer.setViewTransform(currentScale, -mowerPosition.x, -mowerPosition.y); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 检查割草机边界状态 |
| | | */ |
| | | private void checkMowerBoundaryStatus() { |
| | | // 如果处于以割草机为中心的模式,实时更新视图中心 |
| | | if (centerOnMowerMode) { |
| | | updateViewToCenterOnMower(); |
| | | } |
| | | |
| | | // 检查是否在作业中 |
| | | if (statusLabel == null || !"作业中".equals(statusLabel.getText())) { |
| | | // 不在作业中,重置状态 |
| | | if (isMowerOutsideBoundary) { |
| | | isMowerOutsideBoundary = false; |
| | | warningIconVisible = true; |
| | | if (visualizationPanel != null) { |
| | | visualizationPanel.repaint(); |
| | | } |
| | | } |
| | | return; |
| | | } |
| | | |
| | | // 在作业中,检查是否在边界内 |
| | | if (mapRenderer == null) { |
| | | return; |
| | | } |
| | | |
| | | // 获取当前边界 |
| | | List<Point2D.Double> boundary = mapRenderer.getCurrentBoundary(); |
| | | if (boundary == null || boundary.size() < 3) { |
| | | // 没有边界,重置状态 |
| | | if (isMowerOutsideBoundary) { |
| | | isMowerOutsideBoundary = false; |
| | | warningIconVisible = true; |
| | | if (visualizationPanel != null) { |
| | | visualizationPanel.repaint(); |
| | | } |
| | | } |
| | | return; |
| | | } |
| | | |
| | | // 获取割草机位置 |
| | | Gecaoji mower = mapRenderer.getMower(); |
| | | if (mower == null || !mower.hasValidPosition()) { |
| | | // 无法获取位置,重置状态 |
| | | if (isMowerOutsideBoundary) { |
| | | isMowerOutsideBoundary = false; |
| | | warningIconVisible = true; |
| | | if (visualizationPanel != null) { |
| | | visualizationPanel.repaint(); |
| | | } |
| | | } |
| | | return; |
| | | } |
| | | |
| | | Point2D.Double mowerPosition = mower.getPosition(); |
| | | if (mowerPosition == null) { |
| | | return; |
| | | } |
| | | |
| | | // 使用 MowerBoundaryChecker 检查是否在边界内 |
| | | boolean isInside = MowerBoundaryChecker.isInsideBoundaryPoints( |
| | | boundary, |
| | | mowerPosition.x, |
| | | mowerPosition.y |
| | | ); |
| | | |
| | | // 更新状态 |
| | | boolean wasOutside = isMowerOutsideBoundary; |
| | | isMowerOutsideBoundary = !isInside; |
| | | |
| | | // 如果状态改变,立即重绘 |
| | | if (wasOutside != isMowerOutsideBoundary) { |
| | | warningIconVisible = true; |
| | | if (visualizationPanel != null) { |
| | | visualizationPanel.repaint(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void showInitialMowerSelfCheckDialogIfNeeded() { |
| | | // 已移除进入主页时的自检提示(按用户要求删除) |
| | |
| | | } |
| | | } |
| | | mapRenderer.setIdleTrailDurationSeconds(durationSeconds); |
| | | |
| | | // 应用边界距离显示设置 |
| | | Setsys setsys = new Setsys(); |
| | | setsys.initializeFromProperties(); |
| | | mapRenderer.setBoundaryLengthVisible(setsys.isBoundaryLengthVisible()); |
| | | } |
| | | |
| | | private void createHeaderPanel() { |
| | |
| | | |
| | | // 可视化区域 - 使用MapRenderer进行绘制 |
| | | visualizationPanel = new JPanel() { |
| | | private ImageIcon gecaojiIcon1 = null; // 默认图标 |
| | | private ImageIcon gecaojiIcon2 = null; // 以割草机为中心模式图标 |
| | | private static final int GECAOJI_ICON_X = 37; |
| | | private static final int GECAOJI_ICON_Y = 10; |
| | | private static final int GECAOJI_ICON_SIZE = 20; |
| | | |
| | | { |
| | | // 加载割草机图标,大小20x20像素 |
| | | gecaojiIcon1 = loadScaledIcon("image/gecaojishijiao1.png", GECAOJI_ICON_SIZE, GECAOJI_ICON_SIZE); |
| | | gecaojiIcon2 = loadScaledIcon("image/gecaojishijiao2.png", GECAOJI_ICON_SIZE, GECAOJI_ICON_SIZE); |
| | | } |
| | | |
| | | /** |
| | | * 检查鼠标位置是否在割草机图标区域内 |
| | | */ |
| | | private boolean isMouseOnGecaojiIcon(Point mousePoint) { |
| | | return mousePoint.x >= GECAOJI_ICON_X && |
| | | mousePoint.x <= GECAOJI_ICON_X + GECAOJI_ICON_SIZE && |
| | | mousePoint.y >= GECAOJI_ICON_Y && |
| | | mousePoint.y <= GECAOJI_ICON_Y + GECAOJI_ICON_SIZE; |
| | | } |
| | | |
| | | @Override |
| | | public String getToolTipText(MouseEvent event) { |
| | | // 如果鼠标在割草机图标区域内,显示提示文字 |
| | | if (isMouseOnGecaojiIcon(event.getPoint())) { |
| | | // 根据当前模式显示不同的提示文字 |
| | | return centerOnMowerMode ? "取消以割草机为中心" : "以割草机为中心"; |
| | | } |
| | | // 不在图标上时返回null,不显示工具提示框 |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | protected void paintComponent(Graphics g) { |
| | | super.paintComponent(g); |
| | |
| | | if (mapRenderer != null) { |
| | | mapRenderer.renderMap(g); |
| | | } |
| | | |
| | | // 检查是否需要显示警告图标 |
| | | if (isMowerOutsideBoundary && warningIconVisible) { |
| | | // 绘制红色三角形警告图标(带叹号) |
| | | drawWarningIcon(g, GECAOJI_ICON_X, GECAOJI_ICON_Y, GECAOJI_ICON_SIZE); |
| | | } else { |
| | | // 根据模式选择不同的图标 |
| | | ImageIcon iconToDraw = centerOnMowerMode ? gecaojiIcon2 : gecaojiIcon1; |
| | | if (iconToDraw != null) { |
| | | // 绘制割草机图标 |
| | | // 水平方向与速度指示器对齐(x=37) |
| | | // 垂直方向与卫星状态图标对齐(y=10,速度指示器面板顶部边距10像素,使图标中心对齐) |
| | | g.drawImage(iconToDraw.getImage(), GECAOJI_ICON_X, GECAOJI_ICON_Y, null); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 绘制红色三角形警告图标(带叹号) |
| | | */ |
| | | private void drawWarningIcon(Graphics g, int x, int y, int size) { |
| | | Graphics2D g2d = (Graphics2D) g.create(); |
| | | g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
| | | |
| | | // 绘制红色三角形 |
| | | int[] xPoints = {x + size / 2, x, x + size}; |
| | | int[] yPoints = {y, y + size, y + size}; |
| | | g2d.setColor(Color.RED); |
| | | g2d.fillPolygon(xPoints, yPoints, 3); |
| | | |
| | | // 绘制白色边框 |
| | | g2d.setColor(Color.WHITE); |
| | | g2d.setStroke(new BasicStroke(1.5f)); |
| | | g2d.drawPolygon(xPoints, yPoints, 3); |
| | | |
| | | // 绘制白色叹号 |
| | | g2d.setColor(Color.WHITE); |
| | | g2d.setFont(new Font("Arial", Font.BOLD, size * 3 / 4)); |
| | | FontMetrics fm = g2d.getFontMetrics(); |
| | | String exclamation = "!"; |
| | | int textWidth = fm.stringWidth(exclamation); |
| | | int textHeight = fm.getAscent(); |
| | | g2d.drawString(exclamation, x + (size - textWidth) / 2, y + (size + textHeight) / 2 - 2); |
| | | |
| | | g2d.dispose(); |
| | | } |
| | | }; |
| | | visualizationPanel.setLayout(new BorderLayout()); |
| | | |
| | | // 添加鼠标点击监听器,检测是否点击了割草机图标 |
| | | visualizationPanel.addMouseListener(new MouseAdapter() { |
| | | @Override |
| | | public void mouseClicked(MouseEvent e) { |
| | | if (SwingUtilities.isLeftMouseButton(e)) { |
| | | Point clickPoint = e.getPoint(); |
| | | // 检查是否点击了割草机图标区域(37, 10, 20, 20) |
| | | if (clickPoint.x >= 37 && clickPoint.x <= 57 && |
| | | clickPoint.y >= 10 && clickPoint.y <= 30) { |
| | | // 切换以割草机为中心的模式 |
| | | toggleCenterOnMowerMode(); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | |
| | | JPanel speedIndicatorPanel = createSpeedIndicatorPanel(); |
| | | visualizationPanel.add(speedIndicatorPanel, BorderLayout.NORTH); |
| | | |
| | | // 创建功能按钮面板(放在左上角) |
| | | // 创建功能按钮面板 |
| | | JPanel functionButtonsPanel = new JPanel(); |
| | | functionButtonsPanel.setLayout(new BoxLayout(functionButtonsPanel, BoxLayout.Y_AXIS)); |
| | | functionButtonsPanel.setOpaque(false); |
| | |
| | | } |
| | | }); |
| | | ensureBluetoothIconsLoaded(); |
| | | bluetoothConnected = Bluelink.isConnected(); |
| | | ImageIcon initialIcon = bluetoothConnected ? bluetoothLinkedIcon : bluetoothIcon; |
| | | // 根据串口连接状态显示图标 |
| | | SerialPortService service = sendmessage.getActiveService(); |
| | | boolean serialConnected = (service != null && service.isOpen()); |
| | | ImageIcon initialIcon = serialConnected ? bluetoothLinkedIcon : bluetoothIcon; |
| | | if (initialIcon != null) { |
| | | button.setIcon(initialIcon); |
| | | } else { |
| | | button.setText(bluetoothConnected ? "已连" : "蓝牙"); |
| | | button.setText(serialConnected ? "已连" : "蓝牙"); |
| | | } |
| | | return button; |
| | | } |
| | |
| | | } |
| | | startButtonShowingPause = !startButtonShowingPause; |
| | | if (!startButtonShowingPause) { |
| | | statusLabel.setText("作业中"); |
| | | if (stopButtonActive) { |
| | | stopButtonActive = false; |
| | | updateStopButtonIcon(); |
| | | } |
| | | if (!beginMowingSession()) { |
| | | // 检查割草机是否在作业地块边界范围内 |
| | | if (!checkMowerInBoundary()) { |
| | | startButtonShowingPause = true; |
| | | statusLabel.setText("待机"); |
| | | updateStartButtonAppearance(); |
| | | return; |
| | | } |
| | | Control04.sendStartCommandIfDebugSerialOpen(); |
| | | |
| | | statusLabel.setText("作业中"); |
| | | if (stopButtonActive) { |
| | | stopButtonActive = false; |
| | | updateStopButtonIcon(); |
| | | } |
| | | if (!beginMowingSession()) { |
| | | startButtonShowingPause = true; |
| | | statusLabel.setText("待机"); |
| | | updateStartButtonAppearance(); |
| | | return; |
| | | } |
| | | } else { |
| | | statusLabel.setText("暂停中"); |
| | | pauseMowingSession(); |
| | | Control04.sendPauseCommandIfDebugSerialOpen(); |
| | | } |
| | | updateStartButtonAppearance(); |
| | | } |
| | | |
| | | /** |
| | | * 检查割草机是否在当前选中的作业地块边界范围内 |
| | | * @return 如果割草机在边界内返回true,否则返回false并显示提示 |
| | | */ |
| | | private boolean checkMowerInBoundary() { |
| | | if (mapRenderer == null) { |
| | | return true; // 如果没有地图渲染器,跳过检查 |
| | | } |
| | | |
| | | // 获取当前边界 |
| | | List<Point2D.Double> boundary = mapRenderer.getCurrentBoundary(); |
| | | if (boundary == null || boundary.size() < 3) { |
| | | return true; // 如果没有边界或边界点不足,跳过检查 |
| | | } |
| | | |
| | | // 获取割草机位置 |
| | | Gecaoji mower = mapRenderer.getMower(); |
| | | if (mower == null || !mower.hasValidPosition()) { |
| | | showCustomMessageDialog("无法获取割草机位置,请检查设备连接", "提示"); |
| | | return false; |
| | | } |
| | | |
| | | Point2D.Double mowerPosition = mower.getPosition(); |
| | | if (mowerPosition == null) { |
| | | showCustomMessageDialog("无法获取割草机位置,请检查设备连接", "提示"); |
| | | return false; |
| | | } |
| | | |
| | | // 使用 MowerBoundaryChecker 检查是否在边界内 |
| | | boolean isInside = MowerBoundaryChecker.isInsideBoundaryPoints( |
| | | boundary, |
| | | mowerPosition.x, |
| | | mowerPosition.y |
| | | ); |
| | | |
| | | if (!isInside) { |
| | | showCustomMessageDialog("请将割草机开到作业地块内然后点击开始作业", "提示"); |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 显示自定义消息对话框,使用 buttonset 创建确定按钮 |
| | | * @param message 消息内容 |
| | | * @param title 对话框标题 |
| | | */ |
| | | private void showCustomMessageDialog(String message, String title) { |
| | | Window parentWindow = SwingUtilities.getWindowAncestor(this); |
| | | JDialog dialog = new JDialog(parentWindow, title, Dialog.ModalityType.APPLICATION_MODAL); |
| | | dialog.setLayout(new BorderLayout(20, 20)); |
| | | dialog.setResizable(false); |
| | | |
| | | // 内容面板 |
| | | JPanel contentPanel = new JPanel(new BorderLayout(0, 15)); |
| | | contentPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20)); |
| | | contentPanel.setBackground(Color.WHITE); |
| | | |
| | | // 消息标签 |
| | | JLabel messageLabel = new JLabel("<html><div style='text-align: center;'>" + message + "</div></html>"); |
| | | messageLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14)); |
| | | messageLabel.setHorizontalAlignment(SwingConstants.CENTER); |
| | | contentPanel.add(messageLabel, BorderLayout.CENTER); |
| | | |
| | | // 按钮面板 |
| | | JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 0)); |
| | | buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); |
| | | buttonPanel.setOpaque(false); |
| | | |
| | | // 使用 buttonset 创建确定按钮 |
| | | JButton okButton = buttonset.createStyledButton("确定", THEME_COLOR); |
| | | okButton.addActionListener(e -> dialog.dispose()); |
| | | buttonPanel.add(okButton); |
| | | |
| | | contentPanel.add(buttonPanel, BorderLayout.SOUTH); |
| | | dialog.add(contentPanel, BorderLayout.CENTER); |
| | | |
| | | dialog.pack(); |
| | | dialog.setLocationRelativeTo(this); |
| | | dialog.setVisible(true); |
| | | } |
| | | |
| | | private void handleStopAction() { |
| | | if (handheldCaptureInlineUiActive) { |
| | | handleHandheldFinishAction(); |
| | |
| | | statusLabel.setText("已结束"); |
| | | startButtonShowingPause = false; |
| | | stopMowingSession(); |
| | | Control04.sendStopCommandIfDebugSerialOpen(); |
| | | } else { |
| | | statusLabel.setText("待机"); |
| | | startButtonShowingPause = true; |
| | |
| | | if (bluetoothBtn == null) { |
| | | return; |
| | | } |
| | | if (Bluelink.isConnected()) { |
| | | Bluelink.disconnect(); |
| | | bluetoothConnected = false; |
| | | } else { |
| | | boolean success = Bluelink.connect(); |
| | | if (success) { |
| | | bluetoothConnected = true; |
| | | } else { |
| | | bluetoothConnected = false; |
| | | JOptionPane.showMessageDialog(this, "蓝牙连接失败,请重试", "提示", JOptionPane.WARNING_MESSAGE); |
| | | } |
| | | } |
| | | updateBluetoothButtonIcon(); |
| | | // 弹出系统调试页面 |
| | | showDebugDialog(); |
| | | } |
| | | |
| | | private void showDebugDialog() { |
| | | Window parentWindow = SwingUtilities.getWindowAncestor(this); |
| | | debug debugDialog = new debug(parentWindow, THEME_COLOR); |
| | | debugDialog.setLocationRelativeTo(this); // 居中显示在首页 |
| | | debugDialog.setVisible(true); |
| | | } |
| | | |
| | | private void updateBluetoothButtonIcon() { |
| | |
| | | return; |
| | | } |
| | | ensureBluetoothIconsLoaded(); |
| | | bluetoothConnected = Bluelink.isConnected(); |
| | | ImageIcon icon = bluetoothConnected ? bluetoothLinkedIcon : bluetoothIcon; |
| | | // 根据串口连接状态显示图标 |
| | | SerialPortService service = sendmessage.getActiveService(); |
| | | boolean serialConnected = (service != null && service.isOpen()); |
| | | ImageIcon icon = serialConnected ? bluetoothLinkedIcon : bluetoothIcon; |
| | | if (icon != null) { |
| | | bluetoothBtn.setIcon(icon); |
| | | bluetoothBtn.setText(null); |
| | | } else { |
| | | bluetoothBtn.setText(bluetoothConnected ? "已连" : "蓝牙"); |
| | | bluetoothBtn.setText(serialConnected ? "已连" : "蓝牙"); |
| | | } |
| | | } |
| | | |
| | |
| | | String obstacles, |
| | | String plannedPath, |
| | | Runnable returnAction) { |
| | | if (mapRenderer == null || !isMeaningfulValue(plannedPath)) { |
| | | if (mapRenderer == null) { |
| | | return false; |
| | | } |
| | | // 允许没有路径的预览(例如障碍物预览),只要有返回回调即可 |
| | | if (!isMeaningfulValue(plannedPath) && returnAction == null) { |
| | | return false; |
| | | } |
| | | |
| | |
| | | |
| | | mapRenderer.setCurrentBoundary(boundary, landNumber, landName); |
| | | mapRenderer.setCurrentObstacles(obstacles, landNumber); |
| | | mapRenderer.setCurrentPlannedPath(plannedPath); |
| | | // 只有在有路径时才设置路径 |
| | | if (isMeaningfulValue(plannedPath)) { |
| | | mapRenderer.setCurrentPlannedPath(plannedPath); |
| | | } else { |
| | | mapRenderer.setCurrentPlannedPath(null); |
| | | } |
| | | mapRenderer.clearHandheldBoundaryPreview(); |
| | | mapRenderer.setBoundaryPointSizeScale(1.0d); |
| | | mapRenderer.setBoundaryPointsVisible(isMeaningfulValue(boundary)); |
| | | // 启用障碍物边界点显示 |
| | | mapRenderer.setObstaclePointsVisible(isMeaningfulValue(obstacles)); |
| | | |
| | | String displayName = isMeaningfulValue(landName) ? landName : landNumber; |
| | | updateCurrentAreaName(displayName); |