From a541fbdc8812337de120aad3792a2033a5dd7afe Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期四, 25 十二月 2025 12:23:01 +0800
Subject: [PATCH] 优化了首页
---
src/zhuye/Shouye.java | 140 +++++++++++++++++++++++++++++++++++++---------
1 files changed, 112 insertions(+), 28 deletions(-)
diff --git a/src/zhuye/Shouye.java b/src/zhuye/Shouye.java
index 27a166d..9d87cf7 100644
--- a/src/zhuye/Shouye.java
+++ b/src/zhuye/Shouye.java
@@ -113,10 +113,13 @@
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();
+ }
}
}
});
@@ -840,7 +843,7 @@
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) {
// 濡傛灉鍥剧墖鍔犺浇澶辫触锛屼娇鐢ㄩ粯璁ゆ枃鏈�
@@ -1206,15 +1209,15 @@
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);
@@ -1320,7 +1323,8 @@
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);
// 鎮仠鏁堟灉
@@ -2124,7 +2128,7 @@
updateStartButtonAppearance();
}
if (stopBtn != null) {
- stopBtn.setText("缁撴潫");
+ stopBtn.setText("缁撴潫鍓茶崏");
updateStopButtonIcon();
}
if (statusLabel != null) {
@@ -2167,17 +2171,16 @@
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() {
@@ -2992,10 +2995,10 @@
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);
}
}
@@ -4296,18 +4299,99 @@
pathPreviewReturnAction.run();
}
}
-
- // 娴嬭瘯鏂规硶
- public static void main(String[] args) {
- JFrame frame = new JFrame("AutoMow - 棣栭〉");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(400, 800);
- frame.setLocationRelativeTo(null);
+
+ /**
+ * 鏄剧ず杈圭晫棰勮锛堝師濮嬭竟鐣�-绱壊锛屼紭鍖栧悗杈圭晫-缁胯壊锛�
+ * @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 shouye = new Shouye();
- frame.add(shouye);
+ // 鑾峰彇鍘熷杈圭晫XY鍧愭爣
+ String originalBoundaryXY = dikuai.getBoundaryOriginalXY();
- frame.setVisible(true);
- UDPServer.startAsync();//鍚姩鏁版嵁鎺ユ敹绾跨▼
+ // 璁剧疆杈圭晫棰勮
+ shouye.mapRenderer.setBoundaryPreview(originalBoundaryXY, optimizedBoundary);
+
+ // 鍋滄缁樺埗鍓茶崏鏈哄疄鏃舵嫋灏�
+ 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;
+
+ // 鎭㈠缁樺埗鍓茶崏鏈哄疄鏃舵嫋灏�
+ if (mapRenderer != null) {
+ mapRenderer.setIdleTrailSuppressed(false);
+ }
+
+ // 娓呴櫎杈圭晫棰勮
+ if (mapRenderer != null) {
+ mapRenderer.clearBoundaryPreview();
+ }
+
+ // 闅愯棌杩斿洖鎸夐挳
+ if (pathPreviewReturnButton != null) {
+ pathPreviewReturnButton.setVisible(false);
+ }
+
+ // 闅愯棌鎮诞闈㈡澘
+ if (floatingButtonPanel != null) {
+ floatingButtonPanel.setVisible(false);
+ }
+
+ visualizationPanel.revalidate();
+ visualizationPanel.repaint();
+ }
+
}
\ No newline at end of file
--
Gitblit v1.10.0