From 55d23efc30f7db5ec2d9b8a0f04a268a10f3e855 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期二, 23 十二月 2025 16:53:25 +0800
Subject: [PATCH] 优化了地块管理页面
---
src/lujing/MowingPathGenerationPage.java | 90 +++++++++++++++++++++++++++++----------------
1 files changed, 58 insertions(+), 32 deletions(-)
diff --git a/src/lujing/MowingPathGenerationPage.java b/src/lujing/MowingPathGenerationPage.java
index de7c608..ad0dcc4 100644
--- a/src/lujing/MowingPathGenerationPage.java
+++ b/src/lujing/MowingPathGenerationPage.java
@@ -133,24 +133,37 @@
// 鍓茶崏瀹藉害
widthField = createInfoTextField(widthValue != null ? widthValue : "", true);
- contentPanel.add(createTextFieldSection("鍓茶崏瀹藉害 (鍘樼背)", widthField));
+ contentPanel.add(createTextFieldSection("鍓茶崏瀹藉害 (cm)", widthField));
// 鍓茶崏瀹夊叏璺濈锛堝彧璇绘樉绀猴級
+ // 浼樺厛浠嶥ikuai瀵硅薄鑾峰彇锛屽鏋淒ikuai涓病鏈夛紝鍐嶄粠Device鑾峰彇
String displaySafetyDistance = "鏈缃�";
- Device device = Device.getActiveDevice();
- if (device != null) {
- String safetyDistanceValue = device.getMowingSafetyDistance();
- if (safetyDistanceValue != null && !"-1".equals(safetyDistanceValue) && !safetyDistanceValue.trim().isEmpty()) {
- try {
- double distanceMeters = Double.parseDouble(safetyDistanceValue.trim());
- // 濡傛灉鍊煎ぇ浜�100锛岃涓烘槸鍘樼背锛岄渶瑕佽浆鎹负绫�
- if (distanceMeters > 100) {
- distanceMeters = distanceMeters / 100.0;
- }
- displaySafetyDistance = String.format("%.2f绫�", distanceMeters);
- } catch (NumberFormatException e) {
- displaySafetyDistance = "鏈缃�";
+ String safetyDistanceValue = null;
+
+ // 棣栧厛灏濊瘯浠嶥ikuai瀵硅薄鑾峰彇
+ if (dikuai != null) {
+ safetyDistanceValue = dikuai.getMowingSafetyDistance();
+ }
+
+ // 濡傛灉Dikuai涓病鏈夛紝浠嶥evice鑾峰彇
+ if ((safetyDistanceValue == null || "-1".equals(safetyDistanceValue) || safetyDistanceValue.trim().isEmpty())) {
+ Device device = Device.getActiveDevice();
+ if (device != null) {
+ safetyDistanceValue = device.getMowingSafetyDistance();
+ }
+ }
+
+ // 鏍煎紡鍖栨樉绀哄��
+ if (safetyDistanceValue != null && !"-1".equals(safetyDistanceValue) && !safetyDistanceValue.trim().isEmpty()) {
+ try {
+ double distanceMeters = Double.parseDouble(safetyDistanceValue.trim());
+ // 濡傛灉鍊煎ぇ浜�100锛岃涓烘槸鍘樼背锛岄渶瑕佽浆鎹负绫�
+ if (distanceMeters > 100) {
+ distanceMeters = distanceMeters / 100.0;
}
+ displaySafetyDistance = String.format(Locale.US, "%.2fm", distanceMeters);
+ } catch (NumberFormatException e) {
+ displaySafetyDistance = "鏈缃�";
}
}
contentPanel.add(createInfoValueSection("鍓茶崏瀹夊叏璺濈", displaySafetyDistance));
@@ -372,7 +385,7 @@
String rawWidthInput = widthField.getText() != null ? widthField.getText().trim() : "";
String widthSanitized = sanitizeWidthString(widthField.getText());
if (widthSanitized == null) {
- String message = rawWidthInput.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(鍘樼背)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
+ String message = rawWidthInput.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(cm)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
JOptionPane.showMessageDialog(this, message, "鎻愮ず", JOptionPane.WARNING_MESSAGE);
return;
}
@@ -459,7 +472,7 @@
String widthStr = sanitizeWidthString(widthCmInput);
if (widthStr == null) {
if (showMessages) {
- String message = rawWidth.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(鍘樼背)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
+ String message = rawWidth.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(cm)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
JOptionPane.showMessageDialog(parentComponent, message, "鎻愮ず", JOptionPane.WARNING_MESSAGE);
}
return null;
@@ -664,25 +677,38 @@
/**
* 鑾峰彇瀹夊叏璺濈瀛楃涓诧紙绫筹級
+ * 浼樺厛浠嶥ikuai瀵硅薄鑾峰彇锛屽鏋淒ikuai涓病鏈夛紝鍐嶄粠Device鑾峰彇
*/
private String getSafetyDistanceString() {
- Device device = Device.getActiveDevice();
- if (device != null) {
- String safetyDistanceValue = device.getMowingSafetyDistance();
- if (safetyDistanceValue != null && !"-1".equals(safetyDistanceValue) && !safetyDistanceValue.trim().isEmpty()) {
- try {
- double distanceMeters = Double.parseDouble(safetyDistanceValue.trim());
- // 濡傛灉鍊煎ぇ浜�100锛岃涓烘槸鍘樼背锛岄渶瑕佽浆鎹负绫�
- if (distanceMeters > 100) {
- distanceMeters = distanceMeters / 100.0;
- }
- return BigDecimal.valueOf(distanceMeters)
- .setScale(3, RoundingMode.HALF_UP)
- .stripTrailingZeros()
- .toPlainString();
- } catch (NumberFormatException e) {
- // 瑙f瀽澶辫触锛岃繑鍥瀗ull锛屼娇鐢ㄩ粯璁ゅ��
+ String safetyDistanceValue = null;
+
+ // 棣栧厛灏濊瘯浠嶥ikuai瀵硅薄鑾峰彇
+ if (dikuai != null) {
+ safetyDistanceValue = dikuai.getMowingSafetyDistance();
+ }
+
+ // 濡傛灉Dikuai涓病鏈夛紝浠嶥evice鑾峰彇
+ if ((safetyDistanceValue == null || "-1".equals(safetyDistanceValue) || safetyDistanceValue.trim().isEmpty())) {
+ Device device = Device.getActiveDevice();
+ if (device != null) {
+ safetyDistanceValue = device.getMowingSafetyDistance();
+ }
+ }
+
+ // 鏍煎紡鍖栧苟杩斿洖
+ if (safetyDistanceValue != null && !"-1".equals(safetyDistanceValue) && !safetyDistanceValue.trim().isEmpty()) {
+ try {
+ double distanceMeters = Double.parseDouble(safetyDistanceValue.trim());
+ // 濡傛灉鍊煎ぇ浜�100锛岃涓烘槸鍘樼背锛岄渶瑕佽浆鎹负绫�
+ if (distanceMeters > 100) {
+ distanceMeters = distanceMeters / 100.0;
}
+ return BigDecimal.valueOf(distanceMeters)
+ .setScale(3, RoundingMode.HALF_UP)
+ .stripTrailingZeros()
+ .toPlainString();
+ } catch (NumberFormatException e) {
+ // 瑙f瀽澶辫触锛岃繑鍥瀗ull锛屼娇鐢ㄩ粯璁ゅ��
}
}
return null;
--
Gitblit v1.10.0