From 3ad76f98fa8b4a9d3d95207cfb4ae4706087c964 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期四, 04 十二月 2025 19:14:15 +0800
Subject: [PATCH] 新增20251204
---
src/zhuye/Shouye.java | 186 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 179 insertions(+), 7 deletions(-)
diff --git a/src/zhuye/Shouye.java b/src/zhuye/Shouye.java
index eb353c0..b626aee 100644
--- a/src/zhuye/Shouye.java
+++ b/src/zhuye/Shouye.java
@@ -9,6 +9,7 @@
import java.awt.*;
import java.awt.event.*;
+import chuankou.dellmessage;
import dikuai.Dikuai;
import dikuai.Dikuaiguanli;
import dikuai.addzhangaiwu;
@@ -21,6 +22,8 @@
import java.util.List;
import java.util.Map;
import java.util.Locale;
+import java.util.Objects;
+import java.util.function.Consumer;
import java.awt.geom.Point2D;
/**
@@ -52,9 +55,11 @@
private JButton areaSelectBtn;
private JButton baseStationBtn;
private JButton bluetoothBtn;
+ private JLabel dataPacketCountLabel;
private JLabel mowerSpeedValueLabel;
private JLabel mowerSpeedUnitLabel;
private JLabel mowingProgressLabel;
+ private FixQualityIndicator fixQualityIndicator;
// 瀵艰埅鎸夐挳
private JButton homeNavBtn;
@@ -75,6 +80,8 @@
private BaseStationDialog baseStationDialog;
private Sets settingsDialog;
private BaseStation baseStation;
+
+ private final Consumer<String> serialLineListener = line -> SwingUtilities.invokeLater(this::updateDataPacketCountLabel);
// 鍦板浘娓叉煋鍣�
private MapRenderer mapRenderer;
@@ -124,6 +131,7 @@
instance = this;
baseStation = new BaseStation();
baseStation.load();
+ dellmessage.registerLineListener(serialLineListener);
initializeUI();
setupEventHandlers();
}
@@ -293,7 +301,7 @@
mainContentPanel.add(visualizationPanel, BorderLayout.CENTER);
- startMowerSpeedUpdates();
+ startMowerSpeedUpdates();
}
private void createControlPanel() {
@@ -681,14 +689,14 @@
return;
}
startButtonShowingPause = !startButtonShowingPause;
- if (startButtonShowingPause) {
+ if (!startButtonShowingPause) {
statusLabel.setText("浣滀笟涓�");
if (stopButtonActive) {
stopButtonActive = false;
updateStopButtonIcon();
}
if (!beginMowingSession()) {
- startButtonShowingPause = false;
+ startButtonShowingPause = true;
statusLabel.setText("寰呮満");
updateStartButtonAppearance();
return;
@@ -767,10 +775,14 @@
}
private JPanel createSpeedIndicatorPanel() {
- JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 0));
+ JPanel panel = new JPanel(new BorderLayout());
panel.setOpaque(false);
panel.setBorder(BorderFactory.createEmptyBorder(10, 20, 5, 20));
+ JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 0));
+ rightPanel.setOpaque(false);
+
+ fixQualityIndicator = new FixQualityIndicator();
mowingProgressLabel = new JLabel("--%");
mowingProgressLabel.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 12));
mowingProgressLabel.setForeground(THEME_COLOR);
@@ -783,9 +795,32 @@
mowerSpeedUnitLabel.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 9));
mowerSpeedUnitLabel.setForeground(THEME_COLOR);
- panel.add(mowingProgressLabel);
- panel.add(mowerSpeedValueLabel);
- panel.add(mowerSpeedUnitLabel);
+ dataPacketCountLabel = new JLabel("--");
+ dataPacketCountLabel.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 12));
+ dataPacketCountLabel.setForeground(THEME_COLOR);
+
+ rightPanel.add(fixQualityIndicator);
+
+ JSeparator areaSeparator = new JSeparator(SwingConstants.VERTICAL);
+ areaSeparator.setPreferredSize(new Dimension(1, 16));
+ rightPanel.add(areaSeparator);
+
+ rightPanel.add(mowingProgressLabel);
+ JSeparator speedSeparator = new JSeparator(SwingConstants.VERTICAL);
+ speedSeparator.setPreferredSize(new Dimension(1, 16));
+ rightPanel.add(speedSeparator);
+ rightPanel.add(mowerSpeedValueLabel);
+ rightPanel.add(mowerSpeedUnitLabel);
+
+ JSeparator separator = new JSeparator(SwingConstants.VERTICAL);
+ separator.setPreferredSize(new Dimension(1, 16));
+ rightPanel.add(separator);
+
+ rightPanel.add(dataPacketCountLabel);
+
+ panel.add(rightPanel, BorderLayout.EAST);
+ updateFixQualityIndicator();
+ updateDataPacketCountLabel();
return panel;
}
@@ -817,6 +852,89 @@
mowerSpeedUnitLabel.setText("km/h");
}
updateMowingProgressLabel();
+ updateFixQualityIndicator();
+ updateDataPacketCountLabel();
+ }
+
+ private void updateDataPacketCountLabel() {
+ if (dataPacketCountLabel == null) {
+ return;
+ }
+ int udpCount = UDPServer.getReceivedPacketCount();
+ int serialCount = dellmessage.getProcessedLineCount();
+ int displayCount = Math.max(udpCount, serialCount);
+
+ if (displayCount <= 0) {
+ dataPacketCountLabel.setText("--");
+ dataPacketCountLabel.setToolTipText(null);
+ } else {
+ dataPacketCountLabel.setText(String.valueOf(displayCount));
+ dataPacketCountLabel.setToolTipText(String.format("涓插彛: %d UDP: %d", serialCount, udpCount));
+ }
+ }
+
+ private void updateFixQualityIndicator() {
+ if (fixQualityIndicator == null) {
+ return;
+ }
+ Device device = Device.getGecaoji();
+ String code = null;
+ if (device != null) {
+ code = sanitizeDeviceValue(device.getPositioningStatus());
+ }
+ fixQualityIndicator.setQuality(code);
+ }
+
+ private Color resolveFixQualityColor(String code) {
+ if (code == null) {
+ return new Color(160, 160, 160);
+ }
+ switch (code) {
+ case "0":
+ return new Color(160, 160, 160);
+ case "1":
+ return new Color(52, 152, 219);
+ case "2":
+ return new Color(26, 188, 156);
+ case "3":
+ return new Color(155, 89, 182);
+ case "4":
+ return THEME_COLOR;
+ case "5":
+ return new Color(241, 196, 15);
+ case "6":
+ return new Color(231, 76, 60);
+ case "7":
+ return new Color(230, 126, 34);
+ default:
+ return new Color(95, 95, 95);
+ }
+ }
+
+ private String resolveFixQualityDescription(String code) {
+ if (code == null) {
+ return "鏈煡";
+ }
+ switch (code) {
+ case "0":
+ return "鏈畾浣�";
+ case "1":
+ return "鍗曠偣瀹氫綅";
+ case "2":
+ return "鐮佸樊鍒�";
+ case "3":
+ return "鏃犳晥PPS";
+ case "4":
+ return "鍥哄畾瑙�";
+ case "5":
+ return "娴偣瑙�";
+ case "6":
+ return "姝e湪浼扮畻";
+ case "7":
+ return "浜哄伐杈撳叆鍥哄畾鍊�";
+ default:
+ return "鍏朵粬";
+ }
}
private String sanitizeSpeedValue(String raw) {
@@ -833,6 +951,17 @@
return trimmed;
}
+ private String sanitizeDeviceValue(String raw) {
+ if (raw == null) {
+ return null;
+ }
+ String trimmed = raw.trim();
+ if (trimmed.isEmpty() || "-1".equals(trimmed) || "null".equalsIgnoreCase(trimmed)) {
+ return null;
+ }
+ return trimmed;
+ }
+
private void updateMowingProgressLabel() {
if (mowingProgressLabel == null) {
return;
@@ -1621,6 +1750,7 @@
return;
}
circleGuidanceStep = step;
+
if (step == 1) {
circleGuidanceLabel.setText("閲囬泦绗�1涓偣");
circleGuidancePrimaryButton.setText("纭绗�1鐐�");
@@ -2267,6 +2397,48 @@
return !"鏈�夋嫨鍦板潡".equals(trimmed);
}
+ private final class FixQualityIndicator extends JComponent {
+ private static final long serialVersionUID = 1L;
+ private static final int DIAMETER = 16;
+ private String currentCode;
+ private Color currentColor = new Color(160, 160, 160);
+
+ private FixQualityIndicator() {
+ setPreferredSize(new Dimension(DIAMETER, DIAMETER));
+ setMinimumSize(new Dimension(DIAMETER, DIAMETER));
+ setMaximumSize(new Dimension(DIAMETER, DIAMETER));
+ setToolTipText("鏈煡");
+ }
+
+ private void setQuality(String code) {
+ if (Objects.equals(currentCode, code)) {
+ return;
+ }
+ currentCode = code;
+ currentColor = resolveFixQualityColor(code);
+ setToolTipText(resolveFixQualityDescription(code));
+ repaint();
+ }
+
+ @Override
+ protected void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ Graphics2D g2 = (Graphics2D) g.create();
+ try {
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ int diameter = Math.min(getWidth(), getHeight()) - 2;
+ int x = (getWidth() - diameter) / 2;
+ int y = (getHeight() - diameter) / 2;
+ g2.setColor(currentColor);
+ g2.fillOval(x, y, diameter, diameter);
+ g2.setColor(new Color(255, 255, 255, 128));
+ g2.drawOval(x, y, diameter, diameter);
+ } finally {
+ g2.dispose();
+ }
+ }
+ }
+
// 娴嬭瘯鏂规硶
public static void main(String[] args) {
JFrame frame = new JFrame("AutoMow - 棣栭〉");
--
Gitblit v1.10.0