From 5d6d890cfd10466d5d14ff5177adcc888baaa0e4 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期三, 17 十二月 2025 17:46:13 +0800
Subject: [PATCH] 新增了边界距离显示优化了设置页面布局
---
src/set/Sets.java | 232 +++++++++++++++++++++++++----
src/set/Setsys.java | 15 +
src/zhuye/MapRenderer.java | 42 ++++-
src/zhuye/pointandnumber.java | 5
set.properties | 9
src/bianjie/BoundaryLengthDrawer.java | 135 ++++++++++++++++
src/zhuye/Shouye.java | 5
7 files changed, 395 insertions(+), 48 deletions(-)
diff --git a/set.properties b/set.properties
index b09d665..d6499ab 100644
--- a/set.properties
+++ b/set.properties
@@ -1,16 +1,17 @@
#Mower Configuration Properties - Updated
-#Wed Dec 17 16:39:38 CST 2025
+#Wed Dec 17 17:45:29 CST 2025
appVersion=-1
+boundaryLengthVisible=false
currentWorkLandNumber=LAND1
cuttingWidth=200
firmwareVersion=-1
handheldMarkerId=
idleTrailDurationSeconds=60
-mapScale=4.96
+mapScale=6.72
mowerId=1872
serialAutoConnect=true
serialBaudRate=115200
serialPortName=COM15
simCardNumber=-1
-viewCenterX=-30.79
-viewCenterY=22.28
+viewCenterX=-124.59
+viewCenterY=52.20
diff --git a/src/bianjie/BoundaryLengthDrawer.java b/src/bianjie/BoundaryLengthDrawer.java
new file mode 100644
index 0000000..9aa308b
--- /dev/null
+++ b/src/bianjie/BoundaryLengthDrawer.java
@@ -0,0 +1,135 @@
+package bianjie;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.text.DecimalFormat;
+import java.util.List;
+
+/**
+ * 杈圭晫闀垮害缁樺埗鍣�
+ * 鐢ㄤ簬鍦ㄥ湴鍥句笂鏄剧ず鍦板潡杈圭晫鐩搁偦涓ょ偣涔嬮棿鐨勮窛绂�
+ */
+public class BoundaryLengthDrawer {
+
+ private static final Color LENGTH_TEXT_COLOR = new Color(80, 80, 80); // 鐏拌壊鏂囧瓧锛屼笌缂╂斁鏂囧瓧棰滆壊涓�鑷�
+ // 涓嶈缃瓧浣擄紝浣跨敤Graphics2D鐨勯粯璁ゅ瓧浣擄紙涓庣缉鏀炬枃瀛椾竴鑷达級
+ private static final DecimalFormat DISTANCE_FORMAT = new DecimalFormat("0.00");
+
+ /**
+ * 璁$畻涓ょ偣涔嬮棿鐨勮窛绂伙紙绫筹級
+ *
+ * @param p1 绗竴涓偣
+ * @param p2 绗簩涓偣
+ * @return 璺濈锛堢背锛夛紝淇濈暀2浣嶅皬鏁�
+ */
+ public static double calculateDistance(Point2D.Double p1, Point2D.Double p2) {
+ if (p1 == null || p2 == null) {
+ return 0.0;
+ }
+ double dx = p2.x - p1.x;
+ double dy = p2.y - p1.y;
+ double distance = Math.sqrt(dx * dx + dy * dy);
+ return distance;
+ }
+
+ /**
+ * 鍦ㄥ湴鍥句笂缁樺埗杈圭晫闀垮害
+ * 鍦ㄧ浉閭讳袱涓竟鐣岀偣鐨勪腑鐐逛綅缃樉绀鸿窛绂�
+ *
+ * @param g2d Graphics2D瀵硅薄
+ * @param boundary 杈圭晫鐐瑰垪琛�
+ * @param scale 褰撳墠缂╂斁姣斾緥
+ * @param panelWidth 闈㈡澘瀹藉害
+ * @param panelHeight 闈㈡澘楂樺害
+ * @param translateX X鏂瑰悜骞崇Щ閲�
+ * @param translateY Y鏂瑰悜骞崇Щ閲�
+ */
+ public static void drawBoundaryLengths(Graphics2D g2d, List<Point2D.Double> boundary,
+ double scale, int panelWidth, int panelHeight,
+ double translateX, double translateY) {
+ if (boundary == null || boundary.size() < 2) {
+ return;
+ }
+
+ // 淇濆瓨鍘熷鍙樻崲
+ AffineTransform savedTransform = g2d.getTransform();
+
+ // 淇濆瓨褰撳墠瀛椾綋锛堜娇鐢ㄩ粯璁ゅ瓧浣擄紝涓庣缉鏀炬枃瀛椾竴鑷达級
+ Font originalFont = g2d.getFont();
+ FontMetrics fontMetrics = g2d.getFontMetrics(originalFont);
+ g2d.setColor(LENGTH_TEXT_COLOR);
+
+ // 鍒ゆ柇杈圭晫鏄惁闂悎
+ int totalPoints = boundary.size();
+ boolean closed = totalPoints > 2 && arePointsClose(
+ boundary.get(0),
+ boundary.get(totalPoints - 1)
+ );
+ int effectiveCount = closed ? totalPoints - 1 : totalPoints;
+
+ // 缁樺埗姣忕浉閭讳袱鐐逛箣闂寸殑璺濈
+ for (int i = 0; i < effectiveCount; i++) {
+ int nextIndex = (i + 1) % totalPoints;
+ Point2D.Double p1 = boundary.get(i);
+ Point2D.Double p2 = boundary.get(nextIndex);
+
+ // 璁$畻璺濈锛堢背锛�
+ double distance = calculateDistance(p1, p2);
+ if (distance <= 0) {
+ continue; // 璺宠繃璺濈涓�0鐨勭偣
+ }
+ String distanceText = DISTANCE_FORMAT.format(distance) + "m";
+
+ // 璁$畻涓偣浣嶇疆锛堜笘鐣屽潗鏍囷級
+ double midX = (p1.x + p2.x) / 2.0;
+ double midY = (p1.y + p2.y) / 2.0;
+
+ // 灏嗕笘鐣屽潗鏍囪浆鎹负灞忓箷鍧愭爣锛堜娇鐢ㄤ笌MapRenderer鐩稿悓鐨勮浆鎹㈠叕寮忥級
+ double screenX = (midX + translateX) * scale + panelWidth / 2.0;
+ double screenY = (midY + translateY) * scale + panelHeight / 2.0;
+ Point2D.Double screenPoint = new Point2D.Double(screenX, screenY);
+
+ // 淇濆瓨褰撳墠鍙樻崲锛堟鏃秅2d宸茬粡鏄師濮嬪彉鎹紝涓嶅寘鍚鍥惧彉鎹級
+ AffineTransform currentTransform = g2d.getTransform();
+
+ // 纭繚浣跨敤灞忓箷鍧愭爣绯荤粺锛堜笉闅忕缉鏀惧彉鍖栵級
+ g2d.setTransform(new AffineTransform());
+
+ // 璁$畻鏂囧瓧浣嶇疆锛堝眳涓樉绀猴級
+ int textWidth = fontMetrics.stringWidth(distanceText);
+ int textHeight = fontMetrics.getHeight();
+ int textX = (int)(screenPoint.x - textWidth / 2.0);
+ int textY = (int)(screenPoint.y + textHeight / 4.0);
+
+ // 缁樺埗璺濈鏂囧瓧
+ g2d.drawString(distanceText, textX, textY);
+
+ // 鎭㈠鍙樻崲
+ g2d.setTransform(currentTransform);
+ }
+
+ // 鎭㈠鍘熷鍙樻崲
+ g2d.setTransform(savedTransform);
+ }
+
+ /**
+ * 妫�鏌ヤ袱涓偣鏄惁鎺ヨ繎锛堢敤浜庡垽鏂竟鐣屾槸鍚﹂棴鍚堬級
+ *
+ * @param a 绗竴涓偣
+ * @param b 绗簩涓偣
+ * @return 濡傛灉涓ょ偣璺濈灏忎簬闃堝�煎垯杩斿洖true
+ */
+ private static boolean arePointsClose(Point2D.Double a, Point2D.Double b) {
+ if (a == null || b == null) {
+ return false;
+ }
+ double dx = a.x - b.x;
+ double dy = a.y - b.y;
+ double threshold = 0.05; // 5鍘樼背鐨勯槇鍊�
+ return Math.hypot(dx, dy) <= threshold;
+ }
+}
diff --git a/src/set/Sets.java b/src/set/Sets.java
index 1529e53..b81eac5 100644
--- a/src/set/Sets.java
+++ b/src/set/Sets.java
@@ -12,6 +12,7 @@
import java.awt.*;
import java.awt.event.*;
+import java.awt.geom.RoundRectangle2D;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -21,14 +22,15 @@
*/
public class Sets extends JDialog {
private static final long serialVersionUID = 1L;
- private static final int ROW_HEIGHT = 40;
- private static final int ROW_SPACING = 25;
+ private static final int ROW_HEIGHT = 50; // 澧炲姞琛岄珮浠ラ�傚簲鍒嗗壊绾�
+ private static final int ITEM_PADDING = 16; // 鍒楄〃椤瑰唴杈硅窛
// 涓婚棰滆壊
private final Color THEME_COLOR;
- private final Color BACKGROUND_COLOR = new Color(250, 250, 250);
- private final Color PANEL_BACKGROUND = new Color(255, 255, 255);
- private final Color BORDER_COLOR = new Color(220, 220, 220);
+ private final Color BACKGROUND_COLOR = new Color(245, 247, 250); // 鏇存煍鍜岀殑娴呯伆鑹茶儗鏅�
+ private final Color PANEL_BACKGROUND = new Color(255, 255, 255); // 鐧借壊闈㈡澘
+ private final Color BORDER_COLOR = new Color(233, 236, 239); // 娴呰竟妗嗚壊
+ private final Color DIVIDER_COLOR = new Color(233, 236, 239); // 鍒嗗壊绾块鑹�
// 璁剧疆椤圭粍浠�
private JLabel mowerIdLabel;
@@ -39,6 +41,7 @@
private JLabel firmwareVersionLabel;
private JLabel appVersionLabel;
private JLabel idleTrailDurationLabel;
+ private JLabel boundaryLengthVisibleLabel;
private JButton mowerIdEditBtn;
private JButton baseStationIdEditBtn;
@@ -78,30 +81,42 @@
setLocationRelativeTo(getParent());
setResizable(false);
- // 鍒涘缓涓诲唴瀹归潰鏉�
+ // 鍒涘缓涓诲唴瀹归潰鏉匡紙浣跨敤鏇存煍鍜岀殑娴呯伆鑹茶儗鏅級
JPanel mainPanel = new JPanel();
- mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
+ mainPanel.setLayout(new BorderLayout());
mainPanel.setBackground(BACKGROUND_COLOR);
mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
- // 鍒涘缓璁剧疆椤归潰鏉�
+ // 鍒涘缓璁剧疆椤归潰鏉匡紙鍦嗚鐧借壊闈㈡澘锛�
JPanel settingsPanel = createSettingsPanel();
// 娣诲姞缁勪欢鍒颁富闈㈡澘
- mainPanel.add(settingsPanel);
- mainPanel.add(Box.createVerticalGlue());
+ mainPanel.add(settingsPanel, BorderLayout.CENTER);
add(mainPanel, BorderLayout.CENTER);
}
private JPanel createSettingsPanel() {
+ // 鍒涘缓鍦嗚鐧借壊闈㈡澘瀹瑰櫒
+ JPanel container = new JPanel() {
+ @Override
+ protected void paintComponent(Graphics g) {
+ Graphics2D g2d = (Graphics2D) g.create();
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g2d.setColor(PANEL_BACKGROUND);
+ // 缁樺埗鍦嗚鐭╁舰鑳屾櫙
+ g2d.fillRoundRect(0, 0, getWidth(), getHeight(), 16, 16);
+ g2d.dispose();
+ }
+ };
+ container.setLayout(new BorderLayout());
+ container.setOpaque(false);
+
+ // 鍐呭闈㈡澘
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
- panel.setBackground(PANEL_BACKGROUND);
- panel.setBorder(BorderFactory.createCompoundBorder(
- BorderFactory.createLineBorder(BORDER_COLOR),
- BorderFactory.createEmptyBorder(20, 20, 20, 20)
- ));
+ panel.setOpaque(false);
+ panel.setBorder(BorderFactory.createEmptyBorder(8, 0, 8, 0));
// 鍓茶崏鏈虹紪鍙�
JPanel mowerIdPanel = createSettingItemPanel("鍓茶崏鏈虹紪鍙�",
@@ -137,23 +152,45 @@
formatIdleTrailDurationValue(), true);
idleTrailDurationLabel = (JLabel) idleTrailPanel.getClientProperty("valueLabel");
idleTrailEditBtn = (JButton) idleTrailPanel.getClientProperty("editButton");
+
+ // 鏄剧ず杈圭晫璺濈璁剧疆椤�
+ JPanel boundaryLengthPanel = createBoundaryLengthPanel();
+ boundaryLengthVisibleLabel = (JLabel) boundaryLengthPanel.getClientProperty("valueLabel");
JPanel feedbackPanel = createFeedbackPanel();
// APP鐗堟湰
JPanel appVersionPanel = createAppVersionPanel();
- addRowWithSpacing(panel, mowerIdPanel);
- addRowWithSpacing(panel, baseStationIdPanel);
- addRowWithSpacing(panel, handheldPanel);
- addRowWithSpacing(panel, simCardPanel);
- addRowWithSpacing(panel, baseStationSimPanel);
- addRowWithSpacing(panel, firmwarePanel);
- addRowWithSpacing(panel, idleTrailPanel);
- addRowWithSpacing(panel, feedbackPanel);
- addRowWithSpacing(panel, appVersionPanel);
+ // 娣诲姞璁剧疆椤癸紝浣跨敤鍒嗗壊绾垮垎闅�
+ addSettingItem(panel, mowerIdPanel, true);
+ addSettingItem(panel, baseStationIdPanel, true);
+ addSettingItem(panel, handheldPanel, true);
+ addSettingItem(panel, simCardPanel, true);
+ addSettingItem(panel, baseStationSimPanel, true);
+ addSettingItem(panel, firmwarePanel, true);
+ addSettingItem(panel, idleTrailPanel, true);
+ addSettingItem(panel, boundaryLengthPanel, true);
+ addSettingItem(panel, feedbackPanel, true);
+ addSettingItem(panel, appVersionPanel, false); // 鏈�鍚庝竴椤逛笉鍔犲垎鍓茬嚎
- return panel;
+ container.add(panel, BorderLayout.CENTER);
+ return container;
+ }
+
+ /**
+ * 娣诲姞璁剧疆椤癸紙甯﹀垎鍓茬嚎锛�
+ */
+ private void addSettingItem(JPanel container, JPanel itemPanel, boolean showDivider) {
+ container.add(itemPanel);
+ if (showDivider) {
+ // 娣诲姞鍒嗗壊绾�
+ JSeparator divider = new JSeparator();
+ divider.setForeground(DIVIDER_COLOR);
+ divider.setMaximumSize(new Dimension(Integer.MAX_VALUE, 1));
+ divider.setAlignmentX(Component.LEFT_ALIGNMENT);
+ container.add(divider);
+ }
}
private String formatIdleTrailDurationValue() {
@@ -164,18 +201,15 @@
return seconds + "绉�";
}
- private void addRowWithSpacing(JPanel container, JPanel row) {
- container.add(row);
- container.add(Box.createRigidArea(new Dimension(0, ROW_SPACING)));
- }
private JPanel createSettingItemPanel(String title, String value, boolean editable) {
JPanel panel = new JPanel(new GridBagLayout());
- panel.setBackground(PANEL_BACKGROUND);
+ panel.setOpaque(false); // 閫忔槑鑳屾櫙锛岀敱瀹瑰櫒缁樺埗
panel.setAlignmentX(Component.LEFT_ALIGNMENT);
panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
panel.setPreferredSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
panel.setMinimumSize(new Dimension(0, ROW_HEIGHT));
+ panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING));
GridBagConstraints gbc = new GridBagConstraints();
@@ -221,11 +255,12 @@
private JPanel createAppVersionPanel() {
JPanel panel = new JPanel(new GridBagLayout());
- panel.setBackground(PANEL_BACKGROUND);
+ panel.setOpaque(false); // 閫忔槑鑳屾櫙
panel.setAlignmentX(Component.LEFT_ALIGNMENT);
panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
panel.setPreferredSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
panel.setMinimumSize(new Dimension(0, ROW_HEIGHT));
+ panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING));
GridBagConstraints gbc = new GridBagConstraints();
@@ -265,11 +300,12 @@
private JPanel createFeedbackPanel() {
JPanel panel = new JPanel(new GridBagLayout());
- panel.setBackground(PANEL_BACKGROUND);
+ panel.setOpaque(false); // 閫忔槑鑳屾櫙
panel.setAlignmentX(Component.LEFT_ALIGNMENT);
panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
panel.setPreferredSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
panel.setMinimumSize(new Dimension(0, ROW_HEIGHT));
+ panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING));
GridBagConstraints gbc = new GridBagConstraints();
@@ -297,6 +333,125 @@
return panel;
}
+ /**
+ * 鍒涘缓鏄剧ず杈圭晫璺濈璁剧疆闈㈡澘
+ */
+ private JPanel createBoundaryLengthPanel() {
+ JPanel panel = new JPanel(new GridBagLayout());
+ panel.setOpaque(false); // 閫忔槑鑳屾櫙
+ panel.setAlignmentX(Component.LEFT_ALIGNMENT);
+ panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
+ panel.setPreferredSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
+ panel.setMinimumSize(new Dimension(0, ROW_HEIGHT));
+ panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING));
+
+ GridBagConstraints gbc = new GridBagConstraints();
+
+ JLabel titleLabel = new JLabel("鏄剧ず杈圭晫璺濈");
+ titleLabel.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 14));
+ titleLabel.setForeground(Color.BLACK);
+ titleLabel.setHorizontalAlignment(SwingConstants.RIGHT);
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.weightx = 0;
+ gbc.anchor = GridBagConstraints.EAST;
+ gbc.insets = new Insets(0, 0, 0, 12);
+ panel.add(titleLabel, gbc);
+
+ boundaryLengthVisibleLabel = new JLabel(setData.isBoundaryLengthVisible() ? "宸插紑鍚�" : "宸插叧闂�");
+ boundaryLengthVisibleLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+ boundaryLengthVisibleLabel.setForeground(Color.DARK_GRAY);
+ gbc = new GridBagConstraints();
+ gbc.gridx = 1;
+ gbc.gridy = 0;
+ gbc.weightx = 1.0;
+ gbc.anchor = GridBagConstraints.EAST;
+ panel.add(boundaryLengthVisibleLabel, gbc);
+
+ panel.putClientProperty("valueLabel", boundaryLengthVisibleLabel);
+
+ // 鍒涘缓鍒囨崲鎸夐挳锛堜娇鐢ㄥ浘鏍囷級
+ JButton toggleBtn = createBoundaryLengthToggleButton();
+ gbc = new GridBagConstraints();
+ gbc.gridx = 2;
+ gbc.gridy = 0;
+ gbc.weightx = 0;
+ gbc.anchor = GridBagConstraints.EAST;
+ panel.add(toggleBtn, gbc);
+ panel.putClientProperty("toggleButton", toggleBtn);
+
+ return panel;
+ }
+
+ /**
+ * 鍒涘缓杈圭晫璺濈鏄剧ず鍒囨崲鎸夐挳
+ */
+ private JButton createBoundaryLengthToggleButton() {
+ JButton button = new JButton();
+ button.setContentAreaFilled(false);
+ button.setBorder(null);
+ button.setFocusPainted(false);
+ button.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ button.setPreferredSize(new Dimension(32, 32));
+ button.setMinimumSize(new Dimension(32, 32));
+ button.setMaximumSize(new Dimension(32, 32));
+
+ updateBoundaryLengthToggleButton(button);
+
+ button.addActionListener(e -> toggleBoundaryLengthVisible(button));
+
+ return button;
+ }
+
+ /**
+ * 鏇存柊杈圭晫璺濈鍒囨崲鎸夐挳鍥炬爣
+ */
+ private void updateBoundaryLengthToggleButton(JButton button) {
+ boolean isVisible = setData.isBoundaryLengthVisible();
+ try {
+ String iconPath = isVisible ? "image/open.png" : "image/close.png";
+ ImageIcon icon = new ImageIcon(iconPath);
+ if (icon.getIconWidth() > 0) {
+ Image scaledImage = icon.getImage().getScaledInstance(32, 32, Image.SCALE_SMOOTH);
+ button.setIcon(new ImageIcon(scaledImage));
+ button.setText(null);
+ } else {
+ button.setIcon(null);
+ button.setText(isVisible ? "寮�" : "鍏�");
+ }
+ } catch (Exception e) {
+ button.setIcon(null);
+ button.setText(isVisible ? "寮�" : "鍏�");
+ System.err.println("鏃犳硶鍔犺浇杈圭晫璺濈鍥炬爣: " + e.getMessage());
+ }
+ }
+
+ /**
+ * 鍒囨崲杈圭晫璺濈鏄剧ず鐘舵��
+ */
+ private void toggleBoundaryLengthVisible(JButton button) {
+ boolean newValue = !setData.isBoundaryLengthVisible();
+ setData.setBoundaryLengthVisible(newValue);
+
+ // 淇濆瓨鍒伴厤缃枃浠�
+ setData.updateProperty("boundaryLengthVisible", String.valueOf(newValue));
+
+ // 鏇存柊UI
+ if (boundaryLengthVisibleLabel != null) {
+ boundaryLengthVisibleLabel.setText(newValue ? "宸插紑鍚�" : "宸插叧闂�");
+ }
+ updateBoundaryLengthToggleButton(button);
+
+ // 閫氱煡MapRenderer鏇存柊
+ Shouye shouye = Shouye.getInstance();
+ if (shouye != null) {
+ MapRenderer renderer = shouye.getMapRenderer();
+ if (renderer != null) {
+ renderer.setBoundaryLengthVisible(newValue);
+ }
+ }
+ }
+
private JButton createEditButton() {
JButton button = new JButton();
try {
@@ -412,6 +567,19 @@
idleTrailDurationLabel.setText(formatIdleTrailDurationValue());
}
+ // 鏇存柊鏄剧ず杈圭晫璺濈鐘舵��
+ if (boundaryLengthVisibleLabel != null) {
+ boundaryLengthVisibleLabel.setText(setData.isBoundaryLengthVisible() ? "宸插紑鍚�" : "宸插叧闂�");
+ }
+ // 鏇存柊鍒囨崲鎸夐挳鍥炬爣
+ JPanel boundaryLengthPanel = (JPanel) boundaryLengthVisibleLabel.getParent();
+ if (boundaryLengthPanel != null) {
+ JButton toggleBtn = (JButton) boundaryLengthPanel.getClientProperty("toggleButton");
+ if (toggleBtn != null) {
+ updateBoundaryLengthToggleButton(toggleBtn);
+ }
+ }
+
// 鏇存柊APP鐗堟湰鏄剧ず
if (appVersionLabel != null) {
appVersionLabel.setText(setData.getAppVersion() != null ?
diff --git a/src/set/Setsys.java b/src/set/Setsys.java
index 7d12a67..153ef58 100644
--- a/src/set/Setsys.java
+++ b/src/set/Setsys.java
@@ -13,6 +13,7 @@
private String firmwareVersion;
private String appVersion;
private int idleTrailDurationSeconds = DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
+ private boolean boundaryLengthVisible = false; // 榛樿鍏抽棴鏄剧ず杈圭晫璺濈
private static final String PROPERTIES_FILE = "set.properties";
@@ -86,6 +87,14 @@
public void setIdleTrailDurationSeconds(int seconds) {
this.idleTrailDurationSeconds = sanitizeIdleTrailDuration(String.valueOf(seconds));
}
+
+ public boolean isBoundaryLengthVisible() {
+ return boundaryLengthVisible;
+ }
+
+ public void setBoundaryLengthVisible(boolean visible) {
+ this.boundaryLengthVisible = visible;
+ }
/**
* 鍒濆鍖栨柟娉� - 浠巔roperties鏂囦欢璇诲彇鏁版嵁
@@ -104,6 +113,8 @@
this.firmwareVersion = "-1".equals(props.getProperty("firmwareVersion")) ? null : props.getProperty("firmwareVersion");
this.appVersion = "-1".equals(props.getProperty("appVersion")) ? null : props.getProperty("appVersion");
this.idleTrailDurationSeconds = sanitizeIdleTrailDuration(props.getProperty("idleTrailDurationSeconds"));
+ String boundaryLengthVisibleStr = props.getProperty("boundaryLengthVisible");
+ this.boundaryLengthVisible = "true".equalsIgnoreCase(boundaryLengthVisibleStr);
} catch (FileNotFoundException e) {
// 鏂囦欢涓嶅瓨鍦ㄦ椂锛岃缃墍鏈夊睘鎬т负null
@@ -145,6 +156,9 @@
this.idleTrailDurationSeconds = durationSeconds;
value = String.valueOf(durationSeconds);
break;
+ case "boundaryLengthVisible":
+ this.boundaryLengthVisible = "true".equalsIgnoreCase(value);
+ break;
case "mapScale":
// mapScale涓嶉渶瑕佸湪鍐呭瓨涓瓨鍌紝鐩存帴鏇存柊鍒版枃浠�
break;
@@ -213,6 +227,7 @@
this.firmwareVersion = null;
this.appVersion = null;
this.idleTrailDurationSeconds = DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
+ this.boundaryLengthVisible = false; // 榛樿鍏抽棴
}
/**
diff --git a/src/zhuye/MapRenderer.java b/src/zhuye/MapRenderer.java
index b83f3c8..78bbf86 100644
--- a/src/zhuye/MapRenderer.java
+++ b/src/zhuye/MapRenderer.java
@@ -74,6 +74,7 @@
private String boundaryName;
private boolean boundaryPointsVisible;
private boolean obstaclePointsVisible;
+ private boolean boundaryLengthVisible = false; // 鏄惁鏄剧ず杈圭晫璺濈锛岄粯璁ゅ叧闂�
private double boundaryPointSizeScale = 1.0d;
private boolean previewSizingEnabled;
private String currentBoundaryLandNumber;
@@ -381,7 +382,8 @@
Obstacledraw.drawObstacles(g2d, currentObstacles, scale, selectedObstacleName);
}
- if (boundaryPointsVisible && hasBoundary) {
+ // 鏄剧ず杈圭晫鐐癸紙濡傛灉杈圭晫鐐瑰彲瑙侊紝鎴栬�呰竟鐣岃窛绂诲彲瑙侊級
+ if ((boundaryPointsVisible || boundaryLengthVisible) && hasBoundary) {
// 棰勮妯″紡涓嬫樉绀哄簭鍙�
if (previewSizingEnabled) {
drawBoundaryPointsWithNumbers(g2d, currentBoundary, scale);
@@ -397,7 +399,7 @@
);
}
}
-
+
// 缁樺埗闅滅鐗╁潗鏍囩偣锛堝甫搴忓彿锛�
if (obstaclePointsVisible && hasObstacles) {
drawObstaclePointsWithNumbers(g2d, currentObstacles, scale);
@@ -413,9 +415,18 @@
drawMower(g2d);
+ // 淇濆瓨褰撳墠鍙樻崲锛堝寘鍚鍥惧彉鎹級鐢ㄤ簬鍧愭爣杞崲
+ AffineTransform currentTransformForLength = g2d.getTransform();
+
// 鎭㈠鍘熷鍙樻崲
g2d.setTransform(originalTransform);
+ // 缁樺埗杈圭晫闀垮害锛堝鏋滃惎鐢級- 鍦ㄦ仮澶嶅師濮嬪彉鎹㈠悗缁樺埗
+ if (boundaryLengthVisible && hasBoundary) {
+ bianjie.BoundaryLengthDrawer.drawBoundaryLengths(g2d, currentBoundary, scale,
+ visualizationPanel.getWidth(), visualizationPanel.getHeight(), translateX, translateY);
+ }
+
// 缁樺埗瑙嗗浘淇℃伅
drawViewInfo(g2d);
}
@@ -1690,14 +1701,10 @@
return;
}
- // 璁剧疆鐐圭殑澶у皬锛堥殢缂╂斁鍙樺寲锛�
+ // 璁剧疆鐐圭殑澶у皬锛堜笌杈圭晫绾垮搴︿竴鑷达級
+ // 杈圭晫绾垮搴︼細3 / Math.max(0.5, scale)
double scaleFactor = Math.max(0.5, scale);
- double clampedScale = boundaryPointSizeScale * (previewSizingEnabled ? PREVIEW_BOUNDARY_MARKER_SCALE : 1.0d);
- if (!Double.isFinite(clampedScale) || clampedScale <= 0.0d) {
- clampedScale = 1.0d;
- }
- double minimumDiameter = clampedScale < 1.0 ? 0.5 : 1.0;
- double markerDiameter = Math.max(minimumDiameter, (10.0 / scaleFactor) * 0.2 * clampedScale);
+ double markerDiameter = 3.0 / scaleFactor; // 涓庤竟鐣岀嚎瀹藉害涓�鑷�
double markerRadius = markerDiameter / 2.0;
// 璁剧疆瀛椾綋锛堜笌闅滅鐗╁簭鍙蜂竴鑷达紝涓嶉殢缂╂斁鍙樺寲锛�
@@ -2370,6 +2377,23 @@
this.obstaclePointsVisible = visible;
visualizationPanel.repaint();
}
+
+ /**
+ * 璁剧疆鏄惁鏄剧ず杈圭晫璺濈
+ */
+ public void setBoundaryLengthVisible(boolean visible) {
+ boundaryLengthVisible = visible;
+ if (visualizationPanel != null) {
+ visualizationPanel.repaint();
+ }
+ }
+
+ /**
+ * 鑾峰彇鏄惁鏄剧ず杈圭晫璺濈
+ */
+ public boolean isBoundaryLengthVisible() {
+ return boundaryLengthVisible;
+ }
public void setBoundaryPointSizeScale(double sizeScale) {
double normalized = (Double.isFinite(sizeScale) && sizeScale > 0.0d) ? sizeScale : 1.0d;
diff --git a/src/zhuye/Shouye.java b/src/zhuye/Shouye.java
index 44398ed..56c4e39 100644
--- a/src/zhuye/Shouye.java
+++ b/src/zhuye/Shouye.java
@@ -452,6 +452,11 @@
}
}
mapRenderer.setIdleTrailDurationSeconds(durationSeconds);
+
+ // 搴旂敤杈圭晫璺濈鏄剧ず璁剧疆
+ Setsys setsys = new Setsys();
+ setsys.initializeFromProperties();
+ mapRenderer.setBoundaryLengthVisible(setsys.isBoundaryLengthVisible());
}
private void createHeaderPanel() {
diff --git a/src/zhuye/pointandnumber.java b/src/zhuye/pointandnumber.java
index ac1df42..c716159 100644
--- a/src/zhuye/pointandnumber.java
+++ b/src/zhuye/pointandnumber.java
@@ -34,9 +34,8 @@
}
double scaleFactor = Math.max(0.5, scale); // 闃叉杩囧皬缂╂斁
- double clampedScale = diameterScale > 0 ? diameterScale : 1.0; // 闃叉闈炴硶缂╂斁
- double minimumDiameter = clampedScale < 1.0 ? 0.5 : 1.0; // 缂╁皬鏃跺厑璁告洿灏忕殑鏈�灏忓��
- double markerDiameter = Math.max(minimumDiameter, (10.0 / scaleFactor) * 0.2 * clampedScale); // 鎻忕偣鐩村緞
+ // 杈圭晫鐐圭洿寰勪笌杈圭晫绾垮搴︿竴鑷达細3 / Math.max(0.5, scale)
+ double markerDiameter = 3.0 / scaleFactor; // 鎻忕偣鐩村緞锛堜笌杈圭晫绾垮搴︿竴鑷达級
double markerRadius = markerDiameter / 2.0; // 鍗婂緞
for (int i = 0; i < effectiveCount; i++) { // 閬嶅巻鏈夋晥鐐�
--
Gitblit v1.10.0