| | |
| | | import java.util.Map; |
| | | import java.util.Locale; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.function.Consumer; |
| | | // import java.util.function.Consumer; |
| | | import chuankou.DataListener; |
| | | import java.awt.geom.Point2D; |
| | | |
| | | import publicway.Gpstoxuzuobiao; |
| | |
| | | |
| | | private boolean pathPreviewActive; |
| | | |
| | | private final Consumer<String> serialLineListener = line -> { |
| | | SwingUtilities.invokeLater(() -> { |
| | | updateDataPacketCountLabel(); |
| | | // 如果收到$GNGGA数据,立即更新拖尾 |
| | | if (line != null && line.trim().startsWith("$GNGGA")) { |
| | | if (mapRenderer != null && !pathPreviewActive) { |
| | | mapRenderer.forceUpdateIdleMowerTrail(); |
| | | private final DataListener<String> serialLineListener = new DataListener<String>() { |
| | | @Override |
| | | public void accept(final String line) { |
| | | SwingUtilities.invokeLater(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | updateDataPacketCountLabel(); |
| | | // 如果收到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 static final int FLOAT_ICON_SIZE = 32; |
| | | private JButton endDrawingButton; |
| | |
| | | scheduleIdentifierCheck(); |
| | | } |
| | | |
| | | private static boolean isFinite(double d) { |
| | | return !Double.isNaN(d) && !Double.isInfinite(d); |
| | | } |
| | | |
| | | public static Shouye getInstance() { |
| | | return instance; |
| | | } |
| | |
| | | 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() { |
| | |
| | | |
| | | double lat = parseDMToDecimal(latest.getLatitude(), latest.getLatDirection()); |
| | | double lon = parseDMToDecimal(latest.getLongitude(), latest.getLonDirection()); |
| | | if (!Double.isFinite(lat) || !Double.isFinite(lon)) { |
| | | if (!isFinite(lat) || !isFinite(lon)) { |
| | | discardLatestCoordinate(latest); |
| | | lastMowerCoordinate = latest; |
| | | return; |
| | |
| | | |
| | | double[] local = convertLatLonToLocal(lat, lon, base[0], base[1]); |
| | | Point2D.Double candidate = new Point2D.Double(local[0], local[1]); |
| | | if (!Double.isFinite(candidate.x) || !Double.isFinite(candidate.y)) { |
| | | if (!isFinite(candidate.x) || !isFinite(candidate.y)) { |
| | | discardLatestCoordinate(latest); |
| | | lastMowerCoordinate = latest; |
| | | return; |
| | |
| | | |
| | | double x = parseMetersValue(device.getRealtimeX()); |
| | | double y = parseMetersValue(device.getRealtimeY()); |
| | | if (!Double.isFinite(x) || !Double.isFinite(y)) { |
| | | if (!isFinite(x) || !isFinite(y)) { |
| | | JOptionPane.showMessageDialog(this, "当前定位数据无效,请稍后再试。", "提示", JOptionPane.WARNING_MESSAGE); |
| | | return -1; |
| | | } |
| | |
| | | } |
| | | double x = parseMetersValue(device.getRealtimeX()); |
| | | double y = parseMetersValue(device.getRealtimeY()); |
| | | if (!Double.isFinite(x) || !Double.isFinite(y)) { |
| | | if (!isFinite(x) || !isFinite(y)) { |
| | | return false; |
| | | } |
| | | return isDuplicateHandheldPoint(x, y); |
| | |
| | | } |
| | | double x = parseMetersValue(device.getRealtimeX()); |
| | | double y = parseMetersValue(device.getRealtimeY()); |
| | | return Double.isFinite(x) && Double.isFinite(y); |
| | | return isFinite(x) && isFinite(y); |
| | | } |
| | | |
| | | private boolean isDuplicateHandheldPoint(double x, double y) { |
| | |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | double lat = parseDMToDecimal(latest.getLatitude(), latest.getLatDirection()); |
| | | double lon = parseDMToDecimal(latest.getLongitude(), latest.getLonDirection()); |
| | | if (!Double.isFinite(lat) || !Double.isFinite(lon)) { |
| | | if (!isFinite(lat) || !isFinite(lon)) { |
| | | JOptionPane.showMessageDialog(this, "采集点坐标无效,请重新采集。", "提示", JOptionPane.WARNING_MESSAGE); |
| | | return false; |
| | | } |
| | |
| | | } |
| | | double baseLat = parseDMToDecimal(parts[0], parts[1]); |
| | | double baseLon = parseDMToDecimal(parts[2], parts[3]); |
| | | if (!Double.isFinite(baseLat) || !Double.isFinite(baseLon)) { |
| | | if (!isFinite(baseLat) || !isFinite(baseLon)) { |
| | | return null; |
| | | } |
| | | return new double[]{baseLat, baseLon}; |
| | |
| | | double centerX = (x1Sq * (y2 - y3) + x2Sq * (y3 - y1) + x3Sq * (y1 - y2)) / d; |
| | | double centerY = (x1Sq * (x3 - x2) + x2Sq * (x1 - x3) + x3Sq * (x2 - x1)) / d; |
| | | double radius = Math.hypot(centerX - x1, centerY - y1); |
| | | if (!Double.isFinite(centerX) || !Double.isFinite(centerY) || !Double.isFinite(radius)) { |
| | | if (!isFinite(centerX) || !isFinite(centerY) || !isFinite(radius)) { |
| | | return null; |
| | | } |
| | | if (radius < 0.05) { |
| | |
| | | updateCurrentAreaName(displayName); |
| | | |
| | | showPathPreviewReturnControls(); |
| | | |
| | | // 自动将视图中心对准地块几何中心 |
| | | if (mapRenderer != null) { |
| | | SwingUtilities.invokeLater(() -> { |
| | | mapRenderer.centerViewOnBoundary(); |
| | | }); |
| | | } |
| | | |
| | | visualizationPanel.revalidate(); |
| | | visualizationPanel.repaint(); |
| | | return true; |
| | |
| | | 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();//启动数据接收线程 |
| | | } |
| | | } |