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 | 159 ++++++++--------------------------------------------
1 files changed, 25 insertions(+), 134 deletions(-)
diff --git a/src/zhuye/Shouye.java b/src/zhuye/Shouye.java
index 6ac960d..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();
+ }
}
}
});
@@ -131,10 +134,8 @@
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;
@@ -577,9 +578,9 @@
if (setsys.isManualBoundaryDrawingMode()) {
setsys.setManualBoundaryDrawingMode(false);
setsys.updateProperty("manualBoundaryDrawingMode", "false");
- // 鍏抽棴MapRenderer涓殑鎵嬪姩缁樺埗杈圭晫妯″紡锛堣繖浼氭竻闄ら紶鏍囦綅缃拰杈圭晫鐐癸級
+ // 娓呯┖鎵嬪姩缁樺埗鐨勮竟鐣岀偣
if (mapRenderer != null) {
- mapRenderer.setManualBoundaryDrawingMode(false);
+ mapRenderer.clearManualBoundaryPoints();
}
modeChanged = true;
}
@@ -842,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) {
// 濡傛灉鍥剧墖鍔犺浇澶辫触锛屼娇鐢ㄩ粯璁ゆ枃鏈�
@@ -1208,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);
@@ -1322,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);
// 鎮仠鏁堟灉
@@ -2126,7 +2128,7 @@
updateStartButtonAppearance();
}
if (stopBtn != null) {
- stopBtn.setText("缁撴潫");
+ stopBtn.setText("缁撴潫鍓茶崏");
updateStopButtonIcon();
}
if (statusLabel != null) {
@@ -2169,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() {
@@ -2994,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);
}
}
@@ -3240,13 +3241,6 @@
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)));
@@ -4318,32 +4312,12 @@
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);
@@ -4362,23 +4336,11 @@
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) {
@@ -4408,28 +4370,20 @@
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) {
@@ -4439,68 +4393,5 @@
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) {
- 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();//鍚姩鏁版嵁鎺ユ敹绾跨▼
- }
}
\ No newline at end of file
--
Gitblit v1.10.0