From 13d032241e1a2938a8be4f64c9171e1240e9ea1e Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期一, 22 十二月 2025 18:50:42 +0800
Subject: [PATCH] 新增了边界管理页面和首页边界虚线功能
---
src/dikuai/Dikuaiguanli.java | 1755 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 1,601 insertions(+), 154 deletions(-)
diff --git a/src/dikuai/Dikuaiguanli.java b/src/dikuai/Dikuaiguanli.java
index a01435e..ce8aafb 100644
--- a/src/dikuai/Dikuaiguanli.java
+++ b/src/dikuai/Dikuaiguanli.java
@@ -6,9 +6,11 @@
import java.awt.datatransfer.*;
import java.awt.datatransfer.StringSelection;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.math.BigDecimal;
-import ui.UIConfig;
-import ui.UIUtils;
+import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
@@ -16,12 +18,20 @@
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Objects;
+import java.util.Properties;
+import lujing.Lunjingguihua;
+import lujing.MowingPathGenerationPage;
+import publicway.Fuzhibutton;
+import publicway.Lookbutton;
+import publicway.buttonset;
import zhangaiwu.AddDikuai;
import zhangaiwu.Obstacledge;
import zhuye.MapRenderer;
import zhuye.Shouye;
import zhuye.Coordinate;
+import gecaoji.Device;
/**
* 鍦板潡绠$悊闈㈡澘 - 鍗$墖寮忓竷灞�璁捐
@@ -56,12 +66,14 @@
private JButton addLandBtn;
private static String currentWorkLandNumber;
+ private static final String WORK_LAND_KEY = "currentWorkLandNumber";
+ private static final String PROPERTIES_FILE = "set.properties";
private static final Map<String, Boolean> boundaryPointVisibility = new HashMap<>();
private ImageIcon workSelectedIcon;
private ImageIcon workUnselectedIcon;
private ImageIcon boundaryVisibleIcon;
private ImageIcon boundaryHiddenIcon;
- private static final int BOUNDARY_TOGGLE_ICON_SIZE = 48;
+ private static final int BOUNDARY_TOGGLE_ICON_SIZE = 24;
private Map<String, ObstacleSummary> obstacleSummaryCache = Collections.emptyMap();
public Dikuaiguanli(String landNumber) {
@@ -155,7 +167,7 @@
for (Dikuai dikuai : allDikuai.values()) {
JPanel card = createDikuaiCard(dikuai);
cardsPanel.add(card);
- cardsPanel.add(Box.createRigidArea(new Dimension(0, 15)));
+ cardsPanel.add(Box.createRigidArea(new Dimension(0, 10)));
}
}
@@ -203,8 +215,27 @@
headerPanel.add(nameLabel, BorderLayout.WEST);
+ // 鍙充晶鍖哄煙锛氱姸鎬佹枃瀛� + 鎸夐挳
+ JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
+ rightPanel.setBackground(CARD_BACKGROUND);
+ rightPanel.setOpaque(false);
+
+ // 鐘舵�佹枃瀛楁爣绛撅紙鏍规嵁鏄惁閫変腑鏄剧ず/闅愯棌锛�
+ JLabel statusLabel = new JLabel("宸茶缃负褰撳墠鍦板潡");
+ statusLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 13));
+ statusLabel.setForeground(PRIMARY_COLOR);
+ boolean isCurrent = dikuai.getLandNumber() != null && dikuai.getLandNumber().equals(currentWorkLandNumber);
+ statusLabel.setVisible(isCurrent);
+
JButton workToggleBtn = createWorkToggleButton(dikuai);
- headerPanel.add(workToggleBtn, BorderLayout.EAST);
+
+ // 灏嗙姸鎬佹爣绛惧拰鎸夐挳鍏宠仈锛屼互渚垮湪鎸夐挳鐘舵�佸彉鍖栨椂鏇存柊鏍囩
+ workToggleBtn.putClientProperty("statusLabel", statusLabel);
+
+ rightPanel.add(statusLabel);
+ rightPanel.add(workToggleBtn);
+
+ headerPanel.add(rightPanel, BorderLayout.EAST);
card.add(headerPanel, BorderLayout.NORTH);
@@ -216,12 +247,12 @@
// 鍦板潡缂栧彿
contentPanel.add(createCardInfoItem("鍦板潡缂栧彿:", getDisplayValue(dikuai.getLandNumber(), "鏈煡")));
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
-
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
+
// 娣诲姞鏃堕棿
contentPanel.add(createCardInfoItem("娣诲姞鏃堕棿:", getDisplayValue(dikuai.getCreateTime(), "鏈煡")));
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
-
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
+
// 鍦板潡闈㈢Н
String landArea = dikuai.getLandArea();
if (landArea != null && !landArea.equals("-1")) {
@@ -230,79 +261,135 @@
landArea = "鏈煡";
}
contentPanel.add(createCardInfoItem("鍦板潡闈㈢Н:", landArea));
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
-
- // 杩斿洖鐐瑰潗鏍囷紙甯︿慨鏀规寜閽級
- contentPanel.add(createCardInfoItemWithButton("杩斿洖鐐瑰潗鏍�:",
- getDisplayValue(dikuai.getReturnPointCoordinates(), "鏈缃�"),
- "淇敼", e -> editReturnPoint(dikuai)));
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
-
- // 鍦板潡杈圭晫鍧愭爣锛堝甫鏄剧ず椤剁偣鎸夐挳锛�
- JPanel boundaryPanel = createBoundaryInfoItem(dikuai,
- getTruncatedValue(dikuai.getBoundaryCoordinates(), 12, "鏈缃�"));
- setInfoItemTooltip(boundaryPanel, dikuai.getBoundaryCoordinates());
- contentPanel.add(boundaryPanel);
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
-
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
+
+ JPanel mowingPatternPanel = createCardInfoItem("鍓茶崏妯″紡:",
+ formatMowingPatternForDisplay(dikuai.getMowingPattern()));
+ configureInteractiveLabel(getInfoItemTitleLabel(mowingPatternPanel),
+ () -> editMowingPattern(dikuai),
+ "鐐瑰嚮鏌ョ湅/缂栬緫鍓茶崏妯″紡");
+ contentPanel.add(mowingPatternPanel);
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
+
+ // 鍓茶崏鏈哄壊鍒�瀹藉害
+ String mowingBladeWidthValue = dikuai.getMowingBladeWidth();
+ String displayBladeWidth = "鏈缃�";
+ if (mowingBladeWidthValue != null && !"-1".equals(mowingBladeWidthValue) && !mowingBladeWidthValue.trim().isEmpty()) {
+ try {
+ double bladeWidthMeters = Double.parseDouble(mowingBladeWidthValue.trim());
+ double bladeWidthCm = bladeWidthMeters * 100.0;
+ displayBladeWidth = String.format("%.2f鍘樼背", bladeWidthCm);
+ } catch (NumberFormatException e) {
+ displayBladeWidth = "鏈缃�";
+ }
+ }
+ JPanel mowingBladeWidthPanel = createCardInfoItem("鍓茶崏鏈哄壊鍒�瀹藉害:", displayBladeWidth);
+ contentPanel.add(mowingBladeWidthPanel);
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
+
+ String mowingWidthValue = dikuai.getMowingWidth();
+ String displayWidth = "鏈缃�";
+ if (mowingWidthValue != null && !"-1".equals(mowingWidthValue) && !mowingWidthValue.trim().isEmpty()) {
+ displayWidth = mowingWidthValue + "鍘樼背";
+ }
+ JPanel mowingWidthPanel = createCardInfoItem("鍓茶崏瀹藉害:", displayWidth);
+ contentPanel.add(mowingWidthPanel);
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
+
+ // 鍓茶崏瀹夊叏璺濈
+ String displaySafetyDistance = "鏈缃�";
+ String safetyDistanceValue = dikuai.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 = "鏈缃�";
+ }
+ }
+ JPanel mowingSafetyDistancePanel = createCardInfoItem("鍓茶崏瀹夊叏璺濈:", displaySafetyDistance);
+ contentPanel.add(mowingSafetyDistancePanel);
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
+
+ // 寰�杩旂偣璺緞锛堝甫鏌ョ湅鍥炬爣鎸夐挳锛�
+ JPanel returnPathPanel = createCardInfoItemWithIconButton("寰�杩旂偣璺緞:",
+ createViewButton(e -> editReturnPath(dikuai)));
+ configureInteractiveLabel(getInfoItemTitleLabel(returnPathPanel),
+ () -> editReturnPath(dikuai),
+ "鐐瑰嚮鏌ョ湅/缂栬緫寰�杩旂偣璺緞");
+ contentPanel.add(returnPathPanel);
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
+
ObstacleSummary obstacleSummary = getObstacleSummaryFromCache(dikuai.getLandNumber());
JPanel obstaclePanel = createCardInfoItemWithButton("闅滅鐗�:",
obstacleSummary.buildDisplayValue(),
"鏂板",
e -> addNewObstacle(dikuai));
setInfoItemTooltip(obstaclePanel, obstacleSummary.buildTooltip());
+ // 璁╅殰纰嶇墿鏍囬鍙偣鍑伙紝鎵撳紑闅滅鐗╃鐞嗛〉闈�
+ configureInteractiveLabel(getInfoItemTitleLabel(obstaclePanel),
+ () -> showObstacleManagementPage(dikuai),
+ "鐐瑰嚮鏌ョ湅/绠$悊闅滅鐗�");
contentPanel.add(obstaclePanel);
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
+
+ // 鍦板潡杈圭晫鍧愭爣锛堝甫鏌ョ湅鎸夐挳锛�
+ JPanel boundaryPanel = createCardInfoItemWithIconButton("鍦板潡杈圭晫:",
+ createViewButton(e -> editBoundaryCoordinates(dikuai)));
+ configureInteractiveLabel(getInfoItemTitleLabel(boundaryPanel),
+ () -> editBoundaryCoordinates(dikuai),
+ "鐐瑰嚮鏌ョ湅/缂栬緫鍦板潡杈圭晫鍧愭爣");
+ contentPanel.add(boundaryPanel);
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
// 璺緞鍧愭爣锛堝甫鏌ョ湅鎸夐挳锛�
- JPanel pathPanel = createCardInfoItemWithButton("璺緞鍧愭爣:",
- getTruncatedValue(dikuai.getPlannedPath(), 12, "鏈缃�"),
- "澶嶅埗", e -> copyCoordinatesAction("璺緞鍧愭爣", dikuai.getPlannedPath()));
- setInfoItemTooltip(pathPanel, dikuai.getPlannedPath());
+ JPanel pathPanel = createCardInfoItemWithIconButton("璺緞鍧愭爣:",
+ createViewButton(e -> editPlannedPath(dikuai)));
+ configureInteractiveLabel(getInfoItemTitleLabel(pathPanel),
+ () -> editPlannedPath(dikuai),
+ "鐐瑰嚮鏌ョ湅/缂栬緫璺緞鍧愭爣");
contentPanel.add(pathPanel);
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
- JPanel baseStationPanel = createCardInfoItemWithButton("鍩虹珯鍧愭爣:",
- getTruncatedValue(dikuai.getBaseStationCoordinates(), 12, "鏈缃�"),
- "澶嶅埗", e -> copyCoordinatesAction("鍩虹珯鍧愭爣", dikuai.getBaseStationCoordinates()));
- setInfoItemTooltip(baseStationPanel, dikuai.getBaseStationCoordinates());
- contentPanel.add(baseStationPanel);
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
+ JPanel baseStationPanel = createCardInfoItemWithIconButton("鍩虹珯鍧愭爣:",
+ createViewButton(e -> editBaseStationCoordinates(dikuai)));
+ configureInteractiveLabel(getInfoItemTitleLabel(baseStationPanel),
+ () -> editBaseStationCoordinates(dikuai),
+ "鐐瑰嚮鏌ョ湅/缂栬緫鍩虹珯鍧愭爣");
+ contentPanel.add(baseStationPanel);
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
- JPanel boundaryOriginalPanel = createCardInfoItemWithButton("杈圭晫鍘熷鍧愭爣:",
- getTruncatedValue(dikuai.getBoundaryOriginalCoordinates(), 12, "鏈缃�"),
- "澶嶅埗", e -> copyCoordinatesAction("杈圭晫鍘熷鍧愭爣", dikuai.getBoundaryOriginalCoordinates()));
- setInfoItemTooltip(boundaryOriginalPanel, dikuai.getBoundaryOriginalCoordinates());
- contentPanel.add(boundaryOriginalPanel);
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
-
- JPanel mowingPatternPanel = createCardInfoItemWithButton("鍓茶崏妯″紡:",
- getTruncatedValue(dikuai.getMowingPattern(), 12, "鏈缃�"),
- "澶嶅埗", e -> copyCoordinatesAction("鍓茶崏妯″紡", dikuai.getMowingPattern()));
- setInfoItemTooltip(mowingPatternPanel, dikuai.getMowingPattern());
- contentPanel.add(mowingPatternPanel);
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
-
- String mowingWidthValue = dikuai.getMowingWidth();
- String widthSource = null;
- if (mowingWidthValue != null && !"-1".equals(mowingWidthValue) && !mowingWidthValue.trim().isEmpty()) {
- widthSource = mowingWidthValue + "鍘樼背";
- }
- String displayWidth = getTruncatedValue(widthSource, 12, "鏈缃�");
- JPanel mowingWidthPanel = createCardInfoItemWithButton("鍓茶崏瀹藉害:",
- displayWidth,
- "缂栬緫", e -> editMowingWidth(dikuai));
- setInfoItemTooltip(mowingWidthPanel, widthSource);
- contentPanel.add(mowingWidthPanel);
+ JPanel completedTrackPanel = createCardInfoItemWithButton("宸插畬鎴愬壊鑽夎矾寰�:",
+ getTruncatedValue(dikuai.getMowingTrack(), 12, "鏈褰�"),
+ createViewButton(e -> showCompletedMowingTrackDialog(dikuai)));
+ setInfoItemTooltip(completedTrackPanel, dikuai.getMowingTrack());
+ configureInteractiveLabel(getInfoItemTitleLabel(completedTrackPanel),
+ () -> showCompletedMowingTrackDialog(dikuai),
+ "鐐瑰嚮鏌ョ湅瀹屾垚鐨勫壊鑽夎矾寰勮褰�");
+ contentPanel.add(completedTrackPanel);
card.add(contentPanel, BorderLayout.CENTER);
JButton deleteBtn = createDeleteButton();
deleteBtn.addActionListener(e -> deleteDikuai(dikuai));
+ JButton generatePathBtn = createPrimaryFooterButton("璺緞瑙勫垝");
+ generatePathBtn.addActionListener(e -> showPathPlanningPage(dikuai));
+
+ JButton navigationPreviewBtn = createPrimaryFooterButton("瀵艰埅棰勮");
+ navigationPreviewBtn.addActionListener(e -> startNavigationPreview(dikuai));
+
JPanel footerPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
footerPanel.setBackground(CARD_BACKGROUND);
footerPanel.setBorder(BorderFactory.createEmptyBorder(15, 0, 0, 0));
+ footerPanel.add(generatePathBtn);
+ footerPanel.add(Box.createHorizontalStrut(12));
+ footerPanel.add(navigationPreviewBtn);
+ footerPanel.add(Box.createHorizontalStrut(12));
footerPanel.add(deleteBtn);
card.add(footerPanel, BorderLayout.SOUTH);
@@ -324,6 +411,7 @@
itemPanel.add(labelComp, BorderLayout.WEST);
itemPanel.add(valueComp, BorderLayout.EAST);
+ itemPanel.putClientProperty("titleLabel", labelComp);
return itemPanel;
}
@@ -331,7 +419,10 @@
private JPanel createCardInfoItemWithButton(String label, String value, String buttonText, ActionListener listener) {
JPanel itemPanel = new JPanel(new BorderLayout());
itemPanel.setBackground(CARD_BACKGROUND);
- itemPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
+ // 澧炲姞楂樺害浠ョ‘淇濇寜閽畬鏁存樉绀猴紙鎸夐挳楂樺害绾�24-28鍍忕礌锛屽姞涓婁笂涓嬭竟璺濓級
+ itemPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 35));
+ itemPanel.setPreferredSize(new Dimension(Integer.MAX_VALUE, 30));
+ itemPanel.setMinimumSize(new Dimension(0, 28));
JLabel labelComp = new JLabel(label);
labelComp.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
@@ -339,13 +430,14 @@
JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
rightPanel.setBackground(CARD_BACKGROUND);
+ // 娣诲姞鍨傜洿鍐呰竟璺濅互纭繚鎸夐挳涓嶈瑁佸壀
+ rightPanel.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
JLabel valueComp = new JLabel(value);
valueComp.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
valueComp.setForeground(TEXT_COLOR);
- JButton button = createSmallButton(buttonText);
- button.addActionListener(listener);
+ JButton button = createSmallLinkButton(buttonText, listener);
rightPanel.add(valueComp);
rightPanel.add(button);
@@ -353,40 +445,137 @@
itemPanel.add(labelComp, BorderLayout.WEST);
itemPanel.add(rightPanel, BorderLayout.CENTER);
itemPanel.putClientProperty("valueLabel", valueComp);
+ itemPanel.putClientProperty("titleLabel", labelComp);
return itemPanel;
}
- private JPanel createBoundaryInfoItem(Dikuai dikuai, String displayValue) {
+ private JPanel createCardInfoItemWithButton(String label, String value, JButton button) {
+ JPanel itemPanel = new JPanel(new BorderLayout());
+ itemPanel.setBackground(CARD_BACKGROUND);
+ // 澧炲姞楂樺害浠ョ‘淇濇寜閽畬鏁存樉绀猴紙鎸夐挳楂樺害绾�24-28鍍忕礌锛屽姞涓婁笂涓嬭竟璺濓級
+ itemPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 35));
+ itemPanel.setPreferredSize(new Dimension(Integer.MAX_VALUE, 30));
+ itemPanel.setMinimumSize(new Dimension(0, 28));
+
+ JLabel labelComp = new JLabel(label);
+ labelComp.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+ labelComp.setForeground(LIGHT_TEXT);
+
+ JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
+ rightPanel.setBackground(CARD_BACKGROUND);
+ // 娣诲姞鍨傜洿鍐呰竟璺濅互纭繚鎸夐挳涓嶈瑁佸壀
+ rightPanel.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
+
+ JLabel valueComp = new JLabel(value);
+ valueComp.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+ valueComp.setForeground(TEXT_COLOR);
+
+ rightPanel.add(valueComp);
+ rightPanel.add(button);
+
+ itemPanel.add(labelComp, BorderLayout.WEST);
+ itemPanel.add(rightPanel, BorderLayout.CENTER);
+ itemPanel.putClientProperty("valueLabel", valueComp);
+ itemPanel.putClientProperty("titleLabel", labelComp);
+
+ return itemPanel;
+ }
+
+ private JPanel createCardInfoItemWithButtonOnly(String label, String buttonText, ActionListener listener) {
+ JPanel itemPanel = new JPanel(new BorderLayout());
+ itemPanel.setBackground(CARD_BACKGROUND);
+ // 澧炲姞楂樺害浠ョ‘淇濇寜閽畬鏁存樉绀猴紙鎸夐挳楂樺害绾�24-28鍍忕礌锛屽姞涓婁笂涓嬭竟璺濓級
+ itemPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 35));
+ itemPanel.setPreferredSize(new Dimension(Integer.MAX_VALUE, 30));
+ itemPanel.setMinimumSize(new Dimension(0, 28));
+
+ JLabel labelComp = new JLabel(label);
+ labelComp.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+ labelComp.setForeground(LIGHT_TEXT);
+
+ JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
+ rightPanel.setBackground(CARD_BACKGROUND);
+ // 娣诲姞鍨傜洿鍐呰竟璺濅互纭繚鎸夐挳涓嶈瑁佸壀
+ rightPanel.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
+
+ JButton button = createSmallLinkButton(buttonText, listener);
+
+ rightPanel.add(button);
+
+ itemPanel.add(labelComp, BorderLayout.WEST);
+ itemPanel.add(rightPanel, BorderLayout.CENTER);
+ itemPanel.putClientProperty("titleLabel", labelComp);
+
+ return itemPanel;
+ }
+
+ private JPanel createCardInfoItemWithIconButton(String label, JButton button) {
+ JPanel itemPanel = new JPanel(new BorderLayout());
+ itemPanel.setBackground(CARD_BACKGROUND);
+ // 澧炲姞楂樺害浠ョ‘淇濇寜閽畬鏁存樉绀猴紙鎸夐挳楂樺害绾�24-28鍍忕礌锛屽姞涓婁笂涓嬭竟璺濓級
+ itemPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 35));
+ itemPanel.setPreferredSize(new Dimension(Integer.MAX_VALUE, 30));
+ itemPanel.setMinimumSize(new Dimension(0, 28));
+
+ JLabel labelComp = new JLabel(label);
+ labelComp.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+ labelComp.setForeground(LIGHT_TEXT);
+
+ JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
+ rightPanel.setBackground(CARD_BACKGROUND);
+ // 娣诲姞鍨傜洿鍐呰竟璺濅互纭繚鎸夐挳涓嶈瑁佸壀
+ rightPanel.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
+
+ rightPanel.add(button);
+
+ itemPanel.add(labelComp, BorderLayout.WEST);
+ itemPanel.add(rightPanel, BorderLayout.CENTER);
+ itemPanel.putClientProperty("titleLabel", labelComp);
+
+ return itemPanel;
+ }
+
+ private JPanel createBoundaryInfoItem(Dikuai dikuai) {
JPanel itemPanel = new JPanel(new BorderLayout());
itemPanel.setBackground(CARD_BACKGROUND);
- int rowHeight = Math.max(36, BOUNDARY_TOGGLE_ICON_SIZE + 12);
+ // 澧炲姞楂樺害浠ョ‘淇濇寜閽笅杈圭紭瀹屾暣鏄剧ず锛堟寜閽珮搴�28锛屽姞涓婁笂涓嬭竟璺濓級
+ int rowHeight = Math.max(30, BOUNDARY_TOGGLE_ICON_SIZE + 8);
Dimension rowDimension = new Dimension(Integer.MAX_VALUE, rowHeight);
itemPanel.setMaximumSize(rowDimension);
itemPanel.setPreferredSize(rowDimension);
- itemPanel.setMinimumSize(new Dimension(0, 32));
+ itemPanel.setMinimumSize(new Dimension(0, 28));
JLabel labelComp = new JLabel("鍦板潡杈圭晫:");
labelComp.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
labelComp.setForeground(LIGHT_TEXT);
- int verticalPadding = Math.max(0, (rowHeight - BOUNDARY_TOGGLE_ICON_SIZE) / 2);
+ // 纭繚鎸夐挳鏈夎冻澶熺殑涓婁笅杈硅窛锛岄伩鍏嶄笅杈圭紭琚鍓�
+ int verticalPadding = Math.max(2, (rowHeight - BOUNDARY_TOGGLE_ICON_SIZE) / 2);
JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
rightPanel.setBackground(CARD_BACKGROUND);
rightPanel.setBorder(BorderFactory.createEmptyBorder(verticalPadding, 0, verticalPadding, 0));
- JLabel valueComp = new JLabel(displayValue);
- valueComp.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
- valueComp.setForeground(TEXT_COLOR);
+ // 鐘舵�佹彁绀烘枃瀛楁爣绛�
+ JLabel statusLabel = new JLabel();
+ statusLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 13));
+ statusLabel.setForeground(LIGHT_TEXT);
JButton toggleButton = createBoundaryToggleButton(dikuai);
+ // 灏嗙姸鎬佹爣绛惧拰鎸夐挳鍏宠仈锛屼互渚垮湪鎸夐挳鐘舵�佸彉鍖栨椂鏇存柊鏍囩
+ toggleButton.putClientProperty("statusLabel", statusLabel);
- rightPanel.add(valueComp);
+ // 鍒濆鍖栫姸鎬佹枃瀛�
+ String landNumber = dikuai.getLandNumber();
+ boolean isVisible = boundaryPointVisibility.getOrDefault(landNumber, false);
+ updateBoundaryStatusLabel(statusLabel, isVisible);
+
+ rightPanel.add(statusLabel);
rightPanel.add(toggleButton);
itemPanel.add(labelComp, BorderLayout.WEST);
itemPanel.add(rightPanel, BorderLayout.CENTER);
- itemPanel.putClientProperty("valueLabel", valueComp);
+ itemPanel.putClientProperty("titleLabel", labelComp);
return itemPanel;
}
@@ -400,7 +589,7 @@
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
button.setMargin(new Insets(0, 0, 0, 0));
button.setIconTextGap(0);
- button.setPreferredSize(new Dimension(56, 56));
+ button.setPreferredSize(new Dimension(28, 28));
String landNumber = dikuai.getLandNumber();
boolean isVisible = boundaryPointVisibility.getOrDefault(landNumber, false);
@@ -428,6 +617,24 @@
button.setOpaque(true);
}
button.setToolTipText(active ? "闅愯棌杈圭晫鐐瑰簭鍙�" : "鏄剧ず杈圭晫鐐瑰簭鍙�");
+
+ // 鏇存柊鐘舵�佹彁绀烘枃瀛�
+ Object statusLabelObj = button.getClientProperty("statusLabel");
+ if (statusLabelObj instanceof JLabel) {
+ JLabel statusLabel = (JLabel) statusLabelObj;
+ updateBoundaryStatusLabel(statusLabel, active);
+ }
+ }
+
+ private void updateBoundaryStatusLabel(JLabel statusLabel, boolean active) {
+ if (statusLabel == null) {
+ return;
+ }
+ if (active) {
+ statusLabel.setText("宸插紑鍚竟鐣岀偣鏄剧ず");
+ } else {
+ statusLabel.setText("宸插叧闂竟鐣岀偣鏄剧ず");
+ }
}
private void ensureBoundaryToggleIconsLoaded() {
@@ -470,6 +677,7 @@
boolean isCurrent = currentWorkLandNumber != null && currentWorkLandNumber.equals(landNumber);
if (isCurrent) {
renderer.setBoundaryPointsVisible(desiredState);
+ renderer.setBoundaryPointSizeScale(desiredState ? 0.5d : 1.0d);
}
}
}
@@ -485,6 +693,991 @@
}
}
+ private JLabel getInfoItemTitleLabel(JPanel itemPanel) {
+ if (itemPanel == null) {
+ return null;
+ }
+ Object titleComp = itemPanel.getClientProperty("titleLabel");
+ return titleComp instanceof JLabel ? (JLabel) titleComp : null;
+ }
+
+ private void configureInteractiveLabel(JLabel label, Runnable onClick, String tooltip) {
+ if (label == null || onClick == null) {
+ return;
+ }
+ Color originalColor = label.getForeground();
+ label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
+ if (tooltip != null && !tooltip.trim().isEmpty()) {
+ label.setToolTipText(tooltip);
+ }
+ label.addMouseListener(new MouseAdapter() {
+ public void mouseClicked(MouseEvent e) {
+ if (SwingUtilities.isLeftMouseButton(e)) {
+ onClick.run();
+ }
+ }
+
+ public void mouseEntered(MouseEvent e) {
+ label.setForeground(PRIMARY_COLOR);
+ }
+
+ public void mouseExited(MouseEvent e) {
+ label.setForeground(originalColor);
+ }
+ });
+ }
+
+ private String prepareCoordinateForEditor(String value) {
+ if (value == null) {
+ return "";
+ }
+ String trimmed = value.trim();
+ if (trimmed.isEmpty() || "-1".equals(trimmed)) {
+ return "";
+ }
+ return trimmed;
+ }
+
+ private String normalizeCoordinateInput(String input) {
+ if (input == null) {
+ return "-1";
+ }
+ String trimmed = input.trim();
+ return trimmed.isEmpty() ? "-1" : trimmed;
+ }
+
+ private String promptCoordinateEditing(String title, String initialValue) {
+ return promptCoordinateEditing(title, initialValue, null);
+ }
+
+ private String promptCoordinateEditing(String title, String initialValue, Dikuai dikuai) {
+ // 鍒ゆ柇鏄惁鏄線杩旂偣璺緞瀵硅瘽妗�
+ boolean isReturnPathDialog = title != null && title.contains("寰�杩旂偣璺緞");
+
+ if (isReturnPathDialog) {
+ Window owner = SwingUtilities.getWindowAncestor(this);
+ Wangfanpathpage page = new Wangfanpathpage(owner, title, initialValue, dikuai);
+ page.setVisible(true);
+ return page.getResult();
+ }
+
+ JTextArea textArea = new JTextArea(prepareCoordinateForEditor(initialValue));
+ textArea.setLineWrap(true);
+ textArea.setWrapStyleWord(true);
+ textArea.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 13));
+ textArea.setCaretPosition(0);
+ textArea.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
+
+ JScrollPane scrollPane = new JScrollPane(textArea);
+ // 濡傛灉鏄線杩旂偣璺緞瀵硅瘽妗嗭紝楂樺害璋冩暣涓洪�傚簲涓や釜鏂囨湰鍩�
+ scrollPane.setPreferredSize(new Dimension(360, isReturnPathDialog ? 100 : 240));
+
+ Window owner = SwingUtilities.getWindowAncestor(this);
+ JDialog dialog;
+ if (owner instanceof Frame) {
+ dialog = new JDialog((Frame) owner, title, true);
+ } else if (owner instanceof Dialog) {
+ dialog = new JDialog((Dialog) owner, title, true);
+ } else {
+ dialog = new JDialog((Frame) null, title, true);
+ }
+ dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+
+ JPanel contentPanel = new JPanel();
+ contentPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
+
+ if (isReturnPathDialog) {
+ contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
+ // 鍑忓皬杈硅窛浠ュ鍔犳枃鏈煙瀹藉害 (98%宸﹀彸)
+ contentPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
+
+ // 1. 鍘熷寰�杩旇矾寰勫潗鏍囧尯鍩�
+ String rawCoords = dikuai != null ? prepareCoordinateForEditor(dikuai.getReturnPathRawCoordinates()) : "";
+ int rawCount = 0;
+ if (rawCoords != null && !rawCoords.isEmpty() && !"-1".equals(rawCoords)) {
+ rawCount = rawCoords.split(";").length;
+ }
+
+ JPanel rawHeaderPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
+ rawHeaderPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
+ rawHeaderPanel.setBackground(BACKGROUND_COLOR);
+ rawHeaderPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+
+ JLabel rawTitleLabel = new JLabel("鍘熷寰�杩旇矾寰勫潗鏍� (" + rawCount + "鐐�) ");
+ rawTitleLabel.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 14));
+ rawHeaderPanel.add(rawTitleLabel);
+
+ // 鍘熷鍧愭爣澶嶅埗鎸夐挳
+ final String finalRawCoords = rawCoords;
+ JButton rawCopyBtn = Fuzhibutton.createCopyButton(
+ () -> {
+ if (finalRawCoords == null || finalRawCoords.isEmpty() || "-1".equals(finalRawCoords)) return null;
+ return finalRawCoords;
+ },
+ "澶嶅埗",
+ new Color(230, 250, 240)
+ );
+ rawCopyBtn.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
+ rawCopyBtn.setPreferredSize(new Dimension(50, 24));
+ rawCopyBtn.setMargin(new Insets(0,0,0,0));
+ rawHeaderPanel.add(rawCopyBtn);
+
+ contentPanel.add(rawHeaderPanel);
+ contentPanel.add(Box.createVerticalStrut(5));
+
+ JTextArea rawTextArea = new JTextArea(rawCoords);
+ rawTextArea.setLineWrap(true);
+ rawTextArea.setWrapStyleWord(true);
+ rawTextArea.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 13));
+ rawTextArea.setEditable(false); // 鍘熷鍧愭爣閫氬父涓嶅彲缂栬緫
+ rawTextArea.setRows(4);
+ rawTextArea.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
+
+ JScrollPane rawScroll = new JScrollPane(rawTextArea);
+ rawScroll.setAlignmentX(Component.LEFT_ALIGNMENT);
+ // 璁剧疆鏈�澶у搴﹀厑璁告墿灞曪紝棣栭�夊搴﹂�備腑
+ rawScroll.setPreferredSize(new Dimension(300, 100));
+ rawScroll.setMaximumSize(new Dimension(Integer.MAX_VALUE, 100));
+ contentPanel.add(rawScroll);
+
+ contentPanel.add(Box.createVerticalStrut(15));
+
+ // 2. 浼樺寲鍚庡線杩旇矾寰勫潗鏍囧尯鍩�
+ String optCoords = prepareCoordinateForEditor(initialValue);
+ int optCount = 0;
+ if (optCoords != null && !optCoords.isEmpty() && !"-1".equals(optCoords)) {
+ optCount = optCoords.split(";").length;
+ }
+
+ JPanel optHeaderPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
+ optHeaderPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
+ optHeaderPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+
+ JLabel optTitleLabel = new JLabel("浼樺寲鍚庡線杩旇矾寰勫潗鏍� (" + optCount + "鐐�) ");
+ optTitleLabel.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 14));
+ optHeaderPanel.add(optTitleLabel);
+
+ // 浼樺寲鍧愭爣澶嶅埗鎸夐挳 - 鍔ㄦ�佽幏鍙栨枃鏈煙鍐呭
+ JButton optCopyBtn = Fuzhibutton.createCopyButton(
+ () -> {
+ String text = textArea.getText();
+ if (text == null || text.trim().isEmpty() || "-1".equals(text.trim())) return null;
+ return text;
+ },
+ "澶嶅埗",
+ new Color(230, 250, 240)
+ );
+ optCopyBtn.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
+ optCopyBtn.setPreferredSize(new Dimension(50, 24));
+ optCopyBtn.setMargin(new Insets(0,0,0,0));
+ optHeaderPanel.add(optCopyBtn);
+
+ contentPanel.add(optHeaderPanel);
+ contentPanel.add(Box.createVerticalStrut(5));
+
+ // 浣跨敤浼犲叆鐨� textArea (宸插垵濮嬪寲涓� initialValue)
+ textArea.setRows(4);
+ scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT);
+ scrollPane.setPreferredSize(new Dimension(300, 100));
+ scrollPane.setMaximumSize(new Dimension(Integer.MAX_VALUE, 100));
+ contentPanel.add(scrollPane);
+
+ } else {
+ contentPanel.setLayout(new BorderLayout());
+ contentPanel.add(scrollPane, BorderLayout.CENTER);
+ }
+
+ JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
+
+ JButton okButton;
+ JButton cancelButton;
+ JButton copyButton = null; // 鍒濆鍖栦负null
+
+ if (isReturnPathDialog) {
+ // 寰�杩旂偣璺緞瀵硅瘽妗嗭細浣跨敤 buttonset 椋庢牸鐨勭‘瀹氭寜閽紝鍥炬爣鎸夐挳
+ okButton = buttonset.createStyledButton("鍘荤粯鍒�", new Color(70, 130, 220));
+
+ // 鍙栨秷鎸夐挳浣跨敤 closepage.png 鍥炬爣
+ cancelButton = new JButton();
+ ImageIcon closeIcon = loadIcon("image/closepage.png", 25, 25);
+ if (closeIcon != null) {
+ cancelButton.setIcon(closeIcon);
+ } else {
+ cancelButton.setText("鍏抽棴");
+ }
+ cancelButton.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 11));
+ cancelButton.setForeground(PRIMARY_COLOR);
+ cancelButton.setBorder(BorderFactory.createEmptyBorder());
+ cancelButton.setContentAreaFilled(false);
+ cancelButton.setFocusPainted(false);
+ cancelButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ cancelButton.addMouseListener(new MouseAdapter() {
+ public void mouseEntered(MouseEvent e) { cancelButton.setOpaque(true); cancelButton.setBackground(new Color(255, 240, 240)); }
+ public void mouseExited(MouseEvent e) { cancelButton.setOpaque(false); }
+ });
+
+ // 浣跨敤 Fuzhibutton 鍒涘缓澶嶅埗鎸夐挳 (杩欓噷涓嶅啀闇�瑕佸簳閮ㄧ殑澶嶅埗鎸夐挳锛屽洜涓轰笂闈㈠凡缁忔湁浜�)
+ // copyButton = ...
+
+ } else {
+ // 鍏朵粬瀵硅瘽妗嗕繚鎸佸師鏈夋牱寮�
+ okButton = new JButton("纭畾");
+ cancelButton = new JButton("鍙栨秷");
+ copyButton = new JButton("澶嶅埗");
+
+ // 鍏朵粬瀵硅瘽妗嗙殑澶嶅埗鎸夐挳閫昏緫
+ copyButton.addActionListener(e -> {
+ String text = textArea.getText();
+ if (text == null) {
+ text = "";
+ }
+ String trimmed = text.trim();
+ if (trimmed.isEmpty() || "-1".equals(trimmed)) {
+ JOptionPane.showMessageDialog(dialog, title + " 鏈缃�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+ return;
+ }
+ try {
+ StringSelection selection = new StringSelection(text);
+ Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+ clipboard.setContents(selection, selection);
+ JOptionPane.showMessageDialog(dialog, title + " 宸插鍒跺埌鍓创鏉�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+ } catch (Exception ex) {
+ JOptionPane.showMessageDialog(dialog, "澶嶅埗澶辫触: " + ex.getMessage(), "閿欒", JOptionPane.ERROR_MESSAGE);
+ }
+ });
+ }
+
+ final boolean[] confirmed = new boolean[] {false};
+ final String[] resultHolder = new String[1];
+
+ okButton.addActionListener(e -> {
+ if (isReturnPathDialog) {
+ // 寰�杩旂偣璺緞瀵硅瘽妗嗭細鏍囪涓烘墦寮�缁樺埗椤甸潰
+ // 濡傛灉鏂囨湰鍩熶腑宸茬粡鏈夊潗鏍囷紝琛ㄧず瑕侀噸鏂扮粯鍒�
+ String currentText = textArea.getText();
+ if (currentText != null && !currentText.trim().isEmpty() && !"-1".equals(currentText.trim())) {
+ // 鏈夊潗鏍囷紝琛ㄧず閲嶆柊缁樺埗
+ resultHolder[0] = "__OPEN_DRAW_PAGE_REFRESH__";
+ } else {
+ // 娌℃湁鍧愭爣锛屾甯哥粯鍒�
+ resultHolder[0] = "__OPEN_DRAW_PAGE__";
+ }
+ confirmed[0] = true;
+ dialog.dispose();
+ } else {
+ resultHolder[0] = textArea.getText();
+ confirmed[0] = true;
+ dialog.dispose();
+ }
+ });
+
+ cancelButton.addActionListener(e -> dialog.dispose());
+
+ buttonPanel.add(okButton);
+ buttonPanel.add(cancelButton);
+ if (copyButton != null) {
+ buttonPanel.add(copyButton);
+ }
+
+ contentPanel.add(buttonPanel, isReturnPathDialog ? null : BorderLayout.SOUTH);
+ if (isReturnPathDialog) {
+ // 瀵逛簬 BoxLayout锛岀洿鎺ユ坊鍔犲埌搴曢儴
+ JPanel bottomWrapper = new JPanel(new BorderLayout());
+ bottomWrapper.add(buttonPanel, BorderLayout.EAST);
+ contentPanel.add(bottomWrapper);
+ }
+ dialog.setContentPane(contentPanel);
+ dialog.getRootPane().setDefaultButton(okButton);
+ dialog.pack();
+
+ // 濡傛灉鏄線杩旂偣璺緞瀵硅瘽妗嗭紝璁剧疆瀹藉害涓洪椤电殑90%锛岄珮搴︿繚鎸佷笉鍙�
+ if (isReturnPathDialog) {
+ Shouye shouye = Shouye.getInstance();
+ if (shouye != null && shouye.getWidth() > 0) {
+ int homeWidth = shouye.getWidth();
+ int dialogWidth = (int)(homeWidth * 0.9);
+ Dimension currentSize = dialog.getSize();
+ dialog.setSize(dialogWidth, currentSize.height);
+ }
+ }
+
+ dialog.setLocationRelativeTo(this);
+ dialog.setVisible(true);
+
+ return confirmed[0] ? resultHolder[0] : null;
+ }
+
+ private boolean saveFieldAndRefresh(Dikuai dikuai, String fieldName, String value) {
+ if (dikuai == null || fieldName == null || dikuai.getLandNumber() == null) {
+ return false;
+ }
+ if (!Dikuai.updateField(dikuai.getLandNumber(), fieldName, value)) {
+ return false;
+ }
+ Dikuai.updateField(dikuai.getLandNumber(), "updateTime", getCurrentTime());
+ Dikuai.saveToProperties();
+ boolean isCurrent = dikuai.getLandNumber().equals(currentWorkLandNumber);
+ loadDikuaiData();
+ if (isCurrent) {
+ setCurrentWorkLand(dikuai.getLandNumber(), dikuai.getLandName());
+ }
+ return true;
+ }
+
+ private void editBoundaryCoordinates(Dikuai dikuai) {
+ if (dikuai == null) {
+ return;
+ }
+ Window owner = SwingUtilities.getWindowAncestor(this);
+
+ // 鑾峰彇鍦板潡绠$悊瀵硅瘽妗嗭紝鍑嗗鍦ㄦ墦寮�杈圭晫缂栬緫椤甸潰鏃跺叧闂�
+ Window managementWindow = null;
+ if (owner instanceof JDialog) {
+ managementWindow = owner;
+ }
+
+ // 鎵撳紑杈圭晫缂栬緫椤甸潰
+ Dikuanbianjipage page = new Dikuanbianjipage(owner, "鍦板潡杈圭晫绠$悊椤甸潰", dikuai.getBoundaryCoordinates(), dikuai);
+ page.setVisible(true);
+
+ // 鍏抽棴鍦板潡绠$悊椤甸潰
+ if (managementWindow != null) {
+ managementWindow.dispose();
+ }
+
+ // 鑾峰彇缂栬緫缁撴灉骞朵繚瀛�
+ String edited = page.getResult();
+ if (edited == null) {
+ return;
+ }
+ String normalized = normalizeCoordinateInput(edited);
+ if (!saveFieldAndRefresh(dikuai, "boundaryCoordinates", normalized)) {
+ JOptionPane.showMessageDialog(null, "鏃犳硶鏇存柊鍦板潡杈圭晫鍧愭爣", "閿欒", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ String message = "-1".equals(normalized) ? "鍦板潡杈圭晫鍧愭爣宸叉竻绌�" : "鍦板潡杈圭晫鍧愭爣宸叉洿鏂�";
+ JOptionPane.showMessageDialog(null, message, "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+ }
+
+ private void editPlannedPath(Dikuai dikuai) {
+ if (dikuai == null) {
+ return;
+ }
+ String edited = promptCoordinateEditing("鏌ョ湅 / 缂栬緫璺緞鍧愭爣", dikuai.getPlannedPath());
+ if (edited == null) {
+ return;
+ }
+ String normalized = normalizeCoordinateInput(edited);
+ if (!saveFieldAndRefresh(dikuai, "plannedPath", normalized)) {
+ JOptionPane.showMessageDialog(this, "鏃犳硶鏇存柊璺緞鍧愭爣", "閿欒", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ String message = "-1".equals(normalized) ? "璺緞鍧愭爣宸叉竻绌�" : "璺緞鍧愭爣宸叉洿鏂�";
+ JOptionPane.showMessageDialog(this, message, "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+ }
+
+ private void editBaseStationCoordinates(Dikuai dikuai) {
+ if (dikuai == null) {
+ return;
+ }
+ String edited = promptCoordinateEditing("鏌ョ湅 / 缂栬緫鍩虹珯鍧愭爣", dikuai.getBaseStationCoordinates());
+ if (edited == null) {
+ return;
+ }
+ String normalized = normalizeCoordinateInput(edited);
+ if (!saveFieldAndRefresh(dikuai, "baseStationCoordinates", normalized)) {
+ JOptionPane.showMessageDialog(this, "鏃犳硶鏇存柊鍩虹珯鍧愭爣", "閿欒", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ String message = "-1".equals(normalized) ? "鍩虹珯鍧愭爣宸叉竻绌�" : "鍩虹珯鍧愭爣宸叉洿鏂�";
+ JOptionPane.showMessageDialog(this, message, "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+ }
+
+
+ private void editMowingPattern(Dikuai dikuai) {
+ if (dikuai == null) {
+ return;
+ }
+ String current = sanitizeValueOrNull(dikuai.getMowingPattern());
+ String normalized = normalizeExistingMowingPattern(current);
+ JRadioButton parallelBtn = new JRadioButton("骞宠绾� (parallel)");
+ JRadioButton spiralBtn = new JRadioButton("铻烘棆褰� (spiral)");
+
+ ButtonGroup group = new ButtonGroup();
+ group.add(parallelBtn);
+ group.add(spiralBtn);
+
+ if ("spiral".equals(normalized)) {
+ spiralBtn.setSelected(true);
+ } else {
+ parallelBtn.setSelected(true);
+ }
+
+ JPanel panel = new JPanel();
+ panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+ panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
+ panel.add(new JLabel("璇烽�夋嫨鍓茶崏妯″紡:"));
+ panel.add(Box.createVerticalStrut(8));
+ panel.add(parallelBtn);
+ panel.add(Box.createVerticalStrut(4));
+ panel.add(spiralBtn);
+
+ int option = JOptionPane.showConfirmDialog(this, panel, "缂栬緫鍓茶崏妯″紡", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
+ if (option != JOptionPane.OK_OPTION) {
+ return;
+ }
+
+ String selectedValue = parallelBtn.isSelected() ? "parallel" : "spiral";
+ if (!saveFieldAndRefresh(dikuai, "mowingPattern", selectedValue)) {
+ JOptionPane.showMessageDialog(this, "鏃犳硶鏇存柊鍓茶崏妯″紡", "閿欒", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ JOptionPane.showMessageDialog(this, "鍓茶崏妯″紡宸叉洿鏂�", "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+ }
+
+ private String normalizeExistingMowingPattern(String value) {
+ if (value == null) {
+ return "parallel";
+ }
+ String trimmed = value.trim().toLowerCase();
+ if (trimmed.isEmpty() || "-1".equals(trimmed)) {
+ return "parallel";
+ }
+ switch (trimmed) {
+ case "1":
+ case "spiral":
+ case "铻烘棆":
+ case "铻烘棆妯″紡":
+ return "spiral";
+ case "0":
+ case "parallel":
+ case "骞宠":
+ case "骞宠妯″紡":
+ default:
+ if (trimmed.contains("铻烘棆")) {
+ return "spiral";
+ }
+ if (trimmed.contains("spiral")) {
+ return "spiral";
+ }
+ if (trimmed.contains("parallel")) {
+ return "parallel";
+ }
+ if (trimmed.contains("骞宠")) {
+ return "parallel";
+ }
+ return "parallel";
+ }
+ }
+
+ private String sanitizeValueOrNull(String value) {
+ if (value == null) {
+ return null;
+ }
+ String trimmed = value.trim();
+ if (trimmed.isEmpty() || "-1".equals(trimmed)) {
+ return null;
+ }
+ return trimmed;
+ }
+
+ /**
+ * 鍚姩瀵艰埅棰勮
+ */
+ private void startNavigationPreview(Dikuai dikuai) {
+ if (dikuai == null) {
+ return;
+ }
+
+ Window owner = SwingUtilities.getWindowAncestor(this);
+
+ // 鑾峰彇鍦板潡绠$悊瀵硅瘽妗嗭紝鍑嗗鍦ㄦ墦寮�瀵艰埅棰勮鏃跺叧闂�
+ Window managementWindow = null;
+ if (owner instanceof JDialog) {
+ managementWindow = owner;
+ }
+
+ // 鍏抽棴鍦板潡绠$悊椤甸潰
+ if (managementWindow != null) {
+ managementWindow.dispose();
+ }
+
+ // 鍚姩瀵艰埅棰勮
+ daohangyulan.getInstance().startNavigationPreview(dikuai);
+ }
+
+ /**
+ * 鏄剧ず璺緞瑙勫垝椤甸潰
+ */
+ private void showPathPlanningPage(Dikuai dikuai) {
+ if (dikuai == null) {
+ return;
+ }
+
+ Window owner = SwingUtilities.getWindowAncestor(this);
+
+ // 鑾峰彇鍦板潡绠$悊瀵硅瘽妗嗭紝鍑嗗鍦ㄦ墦寮�璺緞瑙勫垝椤甸潰鏃跺叧闂�
+ Window managementWindow = null;
+ if (owner instanceof JDialog) {
+ managementWindow = owner;
+ }
+
+ // 鑾峰彇鍦板潡鍩烘湰鏁版嵁
+ String baseStationValue = prepareCoordinateForEditor(dikuai.getBaseStationCoordinates());
+ String boundaryValue = prepareCoordinateForEditor(dikuai.getBoundaryCoordinates());
+ List<Obstacledge.Obstacle> configuredObstacles = getConfiguredObstacles(dikuai);
+ String obstacleValue = determineInitialObstacleValue(dikuai, configuredObstacles);
+ String widthValue = sanitizeWidthString(dikuai.getMowingWidth());
+ if (widthValue != null) {
+ try {
+ double widthCm = Double.parseDouble(widthValue);
+ widthValue = formatWidthForStorage(widthCm);
+ } catch (NumberFormatException ignored) {
+ // 淇濇寔鍘熷瀛楃涓诧紝绋嶅悗鏍¢獙鎻愮ず
+ }
+ }
+ String modeValue = sanitizeValueOrNull(dikuai.getMowingPattern());
+ String existingPath = prepareCoordinateForEditor(dikuai.getPlannedPath());
+
+ // 鍒涘缓淇濆瓨鍥炶皟鎺ュ彛瀹炵幇
+ MowingPathGenerationPage.PathSaveCallback callback = new MowingPathGenerationPage.PathSaveCallback() {
+ @Override
+ public boolean saveBaseStationCoordinates(Dikuai dikuai, String value) {
+ return saveFieldAndRefresh(dikuai, "baseStationCoordinates", value);
+ }
+
+ @Override
+ public boolean saveBoundaryCoordinates(Dikuai dikuai, String value) {
+ return saveFieldAndRefresh(dikuai, "boundaryCoordinates", value);
+ }
+
+ @Override
+ public boolean saveObstacleCoordinates(Dikuai dikuai, String baseStationValue, String obstacleValue) {
+ return persistObstaclesForLand(dikuai, baseStationValue, obstacleValue);
+ }
+
+ @Override
+ public boolean saveMowingWidth(Dikuai dikuai, String value) {
+ return saveFieldAndRefresh(dikuai, "mowingWidth", value);
+ }
+
+ @Override
+ public boolean savePlannedPath(Dikuai dikuai, String value) {
+ return saveFieldAndRefresh(dikuai, "plannedPath", value);
+ }
+ };
+
+ // 鏄剧ず璺緞瑙勫垝椤甸潰
+ MowingPathGenerationPage dialog = new MowingPathGenerationPage(
+ owner,
+ dikuai,
+ baseStationValue,
+ boundaryValue,
+ obstacleValue,
+ widthValue,
+ modeValue,
+ existingPath,
+ callback
+ );
+
+ // 鍏抽棴鍦板潡绠$悊椤甸潰
+ if (managementWindow != null) {
+ managementWindow.dispose();
+ }
+
+ dialog.setVisible(true);
+ }
+
+
+ private void generateMowingPath(Dikuai dikuai) {
+ if (dikuai == null) {
+ return;
+ }
+ String baseStationValue = prepareCoordinateForEditor(dikuai.getBaseStationCoordinates());
+ String boundaryValue = prepareCoordinateForEditor(dikuai.getBoundaryCoordinates());
+ List<Obstacledge.Obstacle> configuredObstacles = getConfiguredObstacles(dikuai);
+ String obstacleValue = determineInitialObstacleValue(dikuai, configuredObstacles);
+ String widthValue = sanitizeWidthString(dikuai.getMowingWidth());
+ if (widthValue != null) {
+ try {
+ double widthCm = Double.parseDouble(widthValue);
+ widthValue = formatWidthForStorage(widthCm);
+ } catch (NumberFormatException ignored) {
+ // 淇濇寔鍘熷瀛楃涓诧紝绋嶅悗鏍¢獙鎻愮ず
+ }
+ }
+ String modeValue = sanitizeValueOrNull(dikuai.getMowingPattern());
+ String initialGenerated = attemptMowingPathPreview(
+ boundaryValue,
+ obstacleValue,
+ widthValue,
+ modeValue,
+ this,
+ false
+ );
+ showMowingPathDialog(dikuai, baseStationValue, boundaryValue, obstacleValue, widthValue, modeValue, initialGenerated);
+ }
+
+ private void showMowingPathDialog(
+ Dikuai dikuai,
+ String baseStationValue,
+ String boundaryValue,
+ String obstacleValue,
+ String widthValue,
+ String modeValue,
+ String initialGeneratedPath) {
+ Window owner = SwingUtilities.getWindowAncestor(this);
+
+ // 鍒涘缓淇濆瓨鍥炶皟鎺ュ彛瀹炵幇
+ MowingPathGenerationPage.PathSaveCallback callback = new MowingPathGenerationPage.PathSaveCallback() {
+ @Override
+ public boolean saveBaseStationCoordinates(Dikuai dikuai, String value) {
+ return saveFieldAndRefresh(dikuai, "baseStationCoordinates", value);
+ }
+
+ @Override
+ public boolean saveBoundaryCoordinates(Dikuai dikuai, String value) {
+ return saveFieldAndRefresh(dikuai, "boundaryCoordinates", value);
+ }
+
+ @Override
+ public boolean saveObstacleCoordinates(Dikuai dikuai, String baseStationValue, String obstacleValue) {
+ return persistObstaclesForLand(dikuai, baseStationValue, obstacleValue);
+ }
+
+ @Override
+ public boolean saveMowingWidth(Dikuai dikuai, String value) {
+ return saveFieldAndRefresh(dikuai, "mowingWidth", value);
+ }
+
+ @Override
+ public boolean savePlannedPath(Dikuai dikuai, String value) {
+ return saveFieldAndRefresh(dikuai, "plannedPath", value);
+ }
+ };
+
+ // 浣跨敤鏂扮殑鐙珛椤甸潰绫�
+ MowingPathGenerationPage dialog = new MowingPathGenerationPage(
+ owner,
+ dikuai,
+ baseStationValue,
+ boundaryValue,
+ obstacleValue,
+ widthValue,
+ modeValue,
+ initialGeneratedPath,
+ callback
+ );
+
+ dialog.setVisible(true);
+ }
+
+ private String attemptMowingPathPreview(
+ String boundaryInput,
+ String obstacleInput,
+ String widthCmInput,
+ String modeInput,
+ Component parentComponent,
+ boolean showMessages) {
+ String boundary = sanitizeValueOrNull(boundaryInput);
+ if (boundary == null) {
+ if (showMessages) {
+ JOptionPane.showMessageDialog(parentComponent, "褰撳墠鍦板潡鏈缃竟鐣屽潗鏍囷紝鏃犳硶鐢熸垚璺緞", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ }
+ return null;
+ }
+ String rawWidth = widthCmInput != null ? widthCmInput.trim() : "";
+ String widthStr = sanitizeWidthString(widthCmInput);
+ if (widthStr == null) {
+ if (showMessages) {
+ String message = rawWidth.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(鍘樼背)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
+ JOptionPane.showMessageDialog(parentComponent, message, "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ }
+ return null;
+ }
+ double widthCm;
+ try {
+ widthCm = Double.parseDouble(widthStr);
+ } catch (NumberFormatException ex) {
+ if (showMessages) {
+ JOptionPane.showMessageDialog(parentComponent, "鍓茶崏瀹藉害鏍煎紡涓嶆纭�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ }
+ return null;
+ }
+ if (widthCm <= 0) {
+ if (showMessages) {
+ JOptionPane.showMessageDialog(parentComponent, "鍓茶崏瀹藉害蹇呴』澶т簬0", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ }
+ return null;
+ }
+ double widthMeters = widthCm / 100.0d;
+ String plannerWidth = BigDecimal.valueOf(widthMeters)
+ .setScale(3, RoundingMode.HALF_UP)
+ .stripTrailingZeros()
+ .toPlainString();
+ String obstacles = sanitizeValueOrNull(obstacleInput);
+ if (obstacles != null) {
+ obstacles = obstacles.replace("\r\n", " ").replace('\r', ' ').replace('\n', ' ');
+ }
+ String mode = normalizeExistingMowingPattern(modeInput);
+ try {
+ String generated = Lunjingguihua.generatePathFromStrings(boundary, obstacles, plannerWidth, mode);
+ String trimmed = generated != null ? generated.trim() : "";
+ if (trimmed.isEmpty()) {
+ if (showMessages) {
+ JOptionPane.showMessageDialog(parentComponent, "鏈敓鎴愭湁鏁堢殑鍓茶崏璺緞锛岃妫�鏌ュ湴鍧楁暟鎹�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+ }
+ return null;
+ }
+ if (showMessages) {
+ JOptionPane.showMessageDialog(parentComponent, "鍓茶崏璺緞宸茬敓鎴�", "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+ }
+ return trimmed;
+ } catch (IllegalArgumentException ex) {
+ if (showMessages) {
+ JOptionPane.showMessageDialog(parentComponent, "鐢熸垚鍓茶崏璺緞澶辫触: " + ex.getMessage(), "閿欒", JOptionPane.ERROR_MESSAGE);
+ }
+ } catch (Exception ex) {
+ if (showMessages) {
+ JOptionPane.showMessageDialog(parentComponent, "鐢熸垚鍓茶崏璺緞鏃跺彂鐢熷紓甯�: " + ex.getMessage(), "閿欒", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ return null;
+ }
+
+ private JTextArea createInfoTextArea(String text, boolean editable, int rows) {
+ JTextArea area = new JTextArea(text);
+ area.setEditable(editable);
+ area.setLineWrap(true);
+ area.setWrapStyleWord(true);
+ area.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 13));
+ area.setRows(Math.max(rows, 2));
+ area.setCaretPosition(0);
+ area.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
+ area.setBackground(editable ? WHITE : new Color(245, 245, 245));
+ return area;
+ }
+
+ private JPanel createTextAreaSection(String title, JTextArea textArea) {
+ JPanel section = new JPanel(new BorderLayout(0, 6));
+ section.setBackground(BACKGROUND_COLOR);
+ section.setAlignmentX(Component.LEFT_ALIGNMENT);
+
+ JLabel titleLabel = new JLabel(title);
+ titleLabel.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 14));
+ titleLabel.setForeground(TEXT_COLOR);
+ section.add(titleLabel, BorderLayout.NORTH);
+
+ JScrollPane scrollPane = new JScrollPane(textArea);
+ scrollPane.setBorder(BorderFactory.createLineBorder(BORDER_COLOR));
+ scrollPane.getVerticalScrollBar().setUnitIncrement(12);
+ section.add(scrollPane, BorderLayout.CENTER);
+
+ section.setBorder(BorderFactory.createEmptyBorder(4, 0, 12, 0));
+ return section;
+ }
+
+ private JTextField createInfoTextField(String text, boolean editable) {
+ JTextField field = new JTextField(text);
+ field.setEditable(editable);
+ field.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 13));
+ field.setForeground(TEXT_COLOR);
+ field.setBackground(editable ? WHITE : new Color(245, 245, 245));
+ field.setCaretPosition(0);
+ field.setBorder(BorderFactory.createEmptyBorder(4, 6, 4, 6));
+ field.setFocusable(true);
+ field.setOpaque(true);
+ return field;
+ }
+
+ private JPanel createTextFieldSection(String title, JTextField textField) {
+ JPanel section = new JPanel(new BorderLayout(0, 6));
+ section.setBackground(BACKGROUND_COLOR);
+ section.setAlignmentX(Component.LEFT_ALIGNMENT);
+
+ JLabel titleLabel = new JLabel(title);
+ titleLabel.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 14));
+ titleLabel.setForeground(TEXT_COLOR);
+ section.add(titleLabel, BorderLayout.NORTH);
+
+ JPanel fieldWrapper = new JPanel(new BorderLayout());
+ fieldWrapper.setBackground(textField.isEditable() ? WHITE : new Color(245, 245, 245));
+ fieldWrapper.setBorder(BorderFactory.createLineBorder(BORDER_COLOR));
+ fieldWrapper.add(textField, BorderLayout.CENTER);
+ section.add(fieldWrapper, BorderLayout.CENTER);
+
+ section.setBorder(BorderFactory.createEmptyBorder(4, 0, 12, 0));
+ return section;
+ }
+
+ private JPanel createInfoValueSection(String title, String value) {
+ JPanel section = new JPanel();
+ section.setLayout(new BoxLayout(section, BoxLayout.X_AXIS));
+ section.setBackground(BACKGROUND_COLOR);
+ section.setAlignmentX(Component.LEFT_ALIGNMENT);
+ section.setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 0));
+
+ JLabel titleLabel = new JLabel(title + ":");
+ titleLabel.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 14));
+ titleLabel.setForeground(TEXT_COLOR);
+ section.add(titleLabel);
+ section.add(Box.createHorizontalStrut(8));
+
+ JLabel valueLabel = new JLabel(value);
+ valueLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+ valueLabel.setForeground(TEXT_COLOR);
+ section.add(valueLabel);
+
+ section.add(Box.createHorizontalGlue());
+ return section;
+ }
+
+ private String formatMowingPatternForDisplay(String patternValue) {
+ String sanitized = sanitizeValueOrNull(patternValue);
+ if (sanitized == null) {
+ return "鏈缃�";
+ }
+ String normalized = normalizeExistingMowingPattern(sanitized);
+ if ("parallel".equals(normalized)) {
+ return "骞宠妯″紡 (parallel)";
+ }
+ if ("spiral".equals(normalized)) {
+ return "铻烘棆妯″紡 (spiral)";
+ }
+ return sanitized;
+ }
+
+ private String formatMowingPatternForDialog(String patternValue) {
+ String sanitized = sanitizeValueOrNull(patternValue);
+ if (sanitized == null) {
+ return "鏈缃�";
+ }
+ String normalized = normalizeExistingMowingPattern(sanitized);
+ if ("parallel".equals(normalized)) {
+ return "骞宠妯″紡 (parallel)";
+ }
+ if ("spiral".equals(normalized)) {
+ return "铻烘棆妯″紡 (spiral)";
+ }
+ return sanitized;
+ }
+
+ private List<Obstacledge.Obstacle> getConfiguredObstacles(Dikuai dikuai) {
+ if (dikuai == null) {
+ return Collections.emptyList();
+ }
+ List<Obstacledge.Obstacle> obstacles = loadObstaclesFromConfig(dikuai.getLandNumber());
+ if (obstacles == null) {
+ return Collections.emptyList();
+ }
+ return obstacles;
+ }
+
+ private String determineInitialObstacleValue(Dikuai dikuai, List<Obstacledge.Obstacle> configuredObstacles) {
+ if (configuredObstacles != null && !configuredObstacles.isEmpty()) {
+ String payload = Obstacledge.buildPlannerPayload(configuredObstacles);
+ if (payload != null && !payload.trim().isEmpty()) {
+ return payload;
+ }
+ }
+ return "";
+ }
+
+ private String sanitizeWidthString(String input) {
+ if (input == null) {
+ return null;
+ }
+ String trimmed = input.trim();
+ if (trimmed.isEmpty() || "-1".equals(trimmed)) {
+ return null;
+ }
+ String cleaned = trimmed.replaceAll("[^0-9.+-]", "");
+ return cleaned.isEmpty() ? null : cleaned;
+ }
+
+ private String formatWidthForStorage(double widthCm) {
+ return BigDecimal.valueOf(widthCm)
+ .setScale(2, RoundingMode.HALF_UP)
+ .stripTrailingZeros()
+ .toPlainString();
+ }
+
+ private boolean persistObstaclesForLand(Dikuai dikuai, String baseStationValue, String obstaclePayload) {
+ if (dikuai == null || dikuai.getLandNumber() == null) {
+ return false;
+ }
+ String landNumber = dikuai.getLandNumber().trim();
+ try {
+ File configFile = new File("Obstacledge.properties");
+ Obstacledge.ConfigManager manager = new Obstacledge.ConfigManager();
+ if (configFile.exists()) {
+ if (!manager.loadFromFile(configFile.getAbsolutePath())) {
+ return false;
+ }
+ }
+
+ Obstacledge.Plot plot = manager.getPlotById(landNumber);
+ if (plot == null) {
+ plot = new Obstacledge.Plot(landNumber);
+ manager.addPlot(plot);
+ }
+
+ applyBaseStationValue(plot, baseStationValue, dikuai.getBaseStationCoordinates());
+
+ List<Obstacledge.Obstacle> obstacles;
+ if (obstaclePayload == null || "-1".equals(obstaclePayload.trim())) {
+ obstacles = new ArrayList<>();
+ } else {
+ obstacles = Obstacledge.parsePlannerPayload(obstaclePayload, landNumber);
+ }
+ plot.setObstacles(obstacles);
+
+ if (!manager.saveToFile(configFile.getAbsolutePath())) {
+ return false;
+ }
+
+ obstacleSummaryCache = loadObstacleSummaries();
+ boolean isCurrent = landNumber.equals(currentWorkLandNumber);
+ loadDikuaiData();
+ if (isCurrent) {
+ setCurrentWorkLand(landNumber, dikuai.getLandName());
+ }
+ return true;
+ } catch (Exception ex) {
+ System.err.println("淇濆瓨闅滅鐗╅厤缃け璐�: " + ex.getMessage());
+ return false;
+ }
+ }
+
+ private void applyBaseStationValue(Obstacledge.Plot plot, String baseStationValue, String fallbackValue) {
+ if (plot == null) {
+ return;
+ }
+ String sanitized = sanitizeBaseStationValue(baseStationValue);
+ if (sanitized == null) {
+ sanitized = sanitizeBaseStationValue(fallbackValue);
+ }
+ if (sanitized == null) {
+ return;
+ }
+ try {
+ plot.setBaseStationString(sanitized);
+ } catch (Exception ex) {
+ System.err.println("鏇存柊闅滅鐗╅厤缃腑鐨勫熀绔欏潗鏍囧け璐�: " + ex.getMessage());
+ }
+ }
+
+ private String sanitizeBaseStationValue(String value) {
+ if (value == null) {
+ return null;
+ }
+ String trimmed = value.trim();
+ if (trimmed.isEmpty() || "-1".equals(trimmed)) {
+ return null;
+ }
+ return trimmed.replaceAll("\\s+", "");
+ }
+
private String getDisplayValue(String value, String defaultValue) {
if (value == null || value.equals("-1") || value.trim().isEmpty()) {
return defaultValue;
@@ -503,87 +1696,122 @@
return value;
}
- private JButton createSmallButton(String text) {
- JButton button = new JButton(text);
- button.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
- button.setBackground(PRIMARY_COLOR);
- button.setForeground(WHITE);
- button.setBorder(BorderFactory.createEmptyBorder(2, 10, 2, 10));
- button.setMargin(new Insets(0, 0, 0, 0));
- button.setFocusPainted(false);
- button.setCursor(new Cursor(Cursor.HAND_CURSOR));
-
- // 鎮仠鏁堟灉
- button.addMouseListener(new MouseAdapter() {
- public void mouseEntered(MouseEvent e) {
- button.setBackground(PRIMARY_DARK);
- }
- public void mouseExited(MouseEvent e) {
- button.setBackground(PRIMARY_COLOR);
- }
+ /**
+ * 鍒涘缓绫讳技浜庨摼鎺ョ殑灏忔寜閽�
+ */
+ private JButton createSmallLinkButton(String text, ActionListener listener) {
+ JButton btn = new JButton(text);
+ btn.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 11));
+ btn.setForeground(PRIMARY_COLOR);
+ btn.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(PRIMARY_COLOR, 1, true),
+ BorderFactory.createEmptyBorder(2, 6, 2, 6)
+ ));
+ btn.setContentAreaFilled(false);
+ btn.setFocusPainted(false);
+ btn.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ btn.addMouseListener(new MouseAdapter() {
+ public void mouseEntered(MouseEvent e) { btn.setOpaque(true); btn.setBackground(new Color(230, 250, 240)); }
+ public void mouseExited(MouseEvent e) { btn.setOpaque(false); }
});
+ if (listener != null) {
+ btn.addActionListener(listener);
+ }
+ return btn;
+ }
- return button;
+ private JButton createSmallButton(String text) {
+ return createSmallLinkButton(text, null);
+ }
+
+ private JButton createSmallButton(String text, Color backgroundColor, Color hoverColor) {
+ // 瀵逛簬闇�瑕佷笉鍚岄鑹茬殑鎸夐挳锛屼娇鐢ㄥ疄蹇冮鏍�
+ Color baseColor = backgroundColor == null ? PRIMARY_COLOR : backgroundColor;
+ return createStyledButton(text, baseColor, true);
}
private JButton createActionButton(String text, Color color) {
- JButton button = new JButton(text);
- button.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
- button.setBackground(color);
- button.setForeground(WHITE);
- button.setBorder(BorderFactory.createEmptyBorder(8, 16, 8, 16));
- button.setFocusPainted(false);
- button.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ return createStyledButton(text, color, true); // 瀹炲績椋庢牸
+ }
- // 鎮仠鏁堟灉
- button.addMouseListener(new MouseAdapter() {
- public void mouseEntered(MouseEvent e) {
- if (color == RED_COLOR) {
- button.setBackground(RED_DARK);
+ /**
+ * 鍒涘缓鐜颁唬椋庢牸鎸夐挳 (瀹炲績/杞粨)
+ */
+ private JButton createStyledButton(String text, Color baseColor, boolean filled) {
+ JButton btn = new JButton(text) {
+ @Override
+ protected void paintComponent(Graphics g) {
+ Graphics2D g2 = (Graphics2D) g.create();
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+
+ boolean isPressed = getModel().isPressed();
+ boolean isRollover = getModel().isRollover();
+
+ if (filled) {
+ if (isPressed) g2.setColor(baseColor.darker());
+ else if (isRollover) g2.setColor(baseColor.brighter());
+ else g2.setColor(baseColor);
+ g2.fillRoundRect(0, 0, getWidth(), getHeight(), 8, 8);
+ g2.setColor(Color.WHITE);
} else {
- button.setBackground(PRIMARY_DARK);
+ g2.setColor(CARD_BACKGROUND); // 鑳屾櫙
+ g2.fillRoundRect(0, 0, getWidth(), getHeight(), 8, 8);
+
+ if (isPressed) g2.setColor(baseColor.darker());
+ else if (isRollover) g2.setColor(baseColor);
+ else g2.setColor(new Color(200, 200, 200)); // 榛樿杈规鐏�
+
+ g2.setStroke(new BasicStroke(1.2f));
+ g2.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 8, 8);
+ g2.setColor(isRollover ? baseColor : TEXT_COLOR);
}
+
+ FontMetrics fm = g2.getFontMetrics();
+ int x = (getWidth() - fm.stringWidth(getText())) / 2;
+ int y = (getHeight() - fm.getHeight()) / 2 + fm.getAscent();
+ g2.drawString(getText(), x, y);
+
+ g2.dispose();
}
- public void mouseExited(MouseEvent e) {
- if (color == RED_COLOR) {
- button.setBackground(RED_COLOR);
- } else {
- button.setBackground(PRIMARY_COLOR);
- }
- }
- });
-
- return button;
+ };
+ btn.setFocusPainted(false);
+ btn.setContentAreaFilled(false);
+ btn.setBorderPainted(false);
+ btn.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ btn.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 12));
+ return btn;
}
private JButton createDeleteButton() {
- JButton button = new JButton("鍒犻櫎");
- button.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
- button.setBackground(RED_COLOR);
- button.setForeground(WHITE);
- button.setBorder(BorderFactory.createEmptyBorder(6, 12, 6, 12));
- button.setFocusPainted(false);
- button.setCursor(new Cursor(Cursor.HAND_CURSOR));
-
- ImageIcon deleteIcon = loadIcon("image/delete.png", 16, 16);
+ JButton button = new JButton();
+ ImageIcon deleteIcon = loadIcon("image/delete.png", 25, 25);
if (deleteIcon != null) {
button.setIcon(deleteIcon);
- button.setIconTextGap(6);
+ } else {
+ button.setText("鍒犻櫎");
}
-
- // 鎮仠鏁堟灉
+ button.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 11));
+ button.setForeground(RED_COLOR);
+ button.setBorder(BorderFactory.createEmptyBorder());
+ button.setContentAreaFilled(false);
+ button.setFocusPainted(false);
+ button.setCursor(new Cursor(Cursor.HAND_CURSOR));
button.addMouseListener(new MouseAdapter() {
- public void mouseEntered(MouseEvent e) {
- button.setBackground(RED_DARK);
- }
- public void mouseExited(MouseEvent e) {
- button.setBackground(RED_COLOR);
- }
+ public void mouseEntered(MouseEvent e) { button.setOpaque(true); button.setBackground(new Color(255, 240, 240)); }
+ public void mouseExited(MouseEvent e) { button.setOpaque(false); }
});
-
return button;
}
+ private JButton createViewButton(ActionListener listener) {
+ // 浣跨敤 Lookbutton 绫诲垱寤烘煡鐪嬫寜閽�
+ return Lookbutton.createViewButton(listener, new Color(230, 250, 240));
+ }
+
+ private JButton createPrimaryFooterButton(String text) {
+ return createStyledButton(text, PRIMARY_COLOR, true); // 瀹炲績椋庢牸
+ }
+
private JButton createWorkToggleButton(Dikuai dikuai) {
JButton button = new JButton();
button.setContentAreaFilled(false);
@@ -611,6 +1839,13 @@
button.setText(isCurrent ? "褰撳墠鍦板潡" : "璁句负褰撳墠");
}
button.setToolTipText(isCurrent ? "鍙栨秷褰撳墠浣滀笟鍦板潡" : "璁句负褰撳墠浣滀笟鍦板潡");
+
+ // 鏇存柊鐘舵�佹枃瀛楁爣绛剧殑鏄剧ず/闅愯棌
+ Object statusLabelObj = button.getClientProperty("statusLabel");
+ if (statusLabelObj instanceof JLabel) {
+ JLabel statusLabel = (JLabel) statusLabelObj;
+ statusLabel.setVisible(isCurrent);
+ }
}
private void ensureWorkIconsLoaded() {
@@ -648,10 +1883,19 @@
}
public static void setCurrentWorkLand(String landNumber, String landName) {
- currentWorkLandNumber = landNumber;
+ String sanitizedLandNumber = sanitizeLandNumber(landNumber);
+ boolean changed = !Objects.equals(currentWorkLandNumber, sanitizedLandNumber);
+ if (!changed) {
+ String persisted = readPersistedWorkLandNumber();
+ if (!Objects.equals(persisted, sanitizedLandNumber)) {
+ changed = true;
+ }
+ }
+ currentWorkLandNumber = sanitizedLandNumber;
+
Dikuai dikuai = null;
- if (landNumber != null) {
- dikuai = Dikuai.getDikuai(landNumber);
+ if (sanitizedLandNumber != null) {
+ dikuai = Dikuai.getDikuai(sanitizedLandNumber);
if (dikuai != null && (landName == null || "-1".equals(landName) || landName.trim().isEmpty())) {
landName = dikuai.getLandName();
}
@@ -662,27 +1906,34 @@
Shouye shouye = Shouye.getInstance();
if (shouye != null) {
- if (landNumber == null) {
+ if (sanitizedLandNumber == null) {
shouye.updateCurrentAreaName(null);
} else {
shouye.updateCurrentAreaName(landName);
}
MapRenderer renderer = shouye.getMapRenderer();
if (renderer != null) {
+ renderer.applyLandMetadata(dikuai);
String boundary = (dikuai != null) ? dikuai.getBoundaryCoordinates() : null;
String plannedPath = (dikuai != null) ? dikuai.getPlannedPath() : null;
- String obstacles = (dikuai != null) ? dikuai.getObstacleCoordinates() : null;
- List<Obstacledge.Obstacle> configuredObstacles = (landNumber != null) ? loadObstaclesFromConfig(landNumber) : null;
- renderer.setCurrentBoundary(boundary, landNumber, landNumber == null ? null : landName);
- renderer.setCurrentPlannedPath(plannedPath);
- if (configuredObstacles != null) {
- renderer.setCurrentObstacles(configuredObstacles, landNumber);
- } else {
- renderer.setCurrentObstacles(obstacles, landNumber);
+ List<Obstacledge.Obstacle> configuredObstacles = (sanitizedLandNumber != null) ? loadObstaclesFromConfig(sanitizedLandNumber) : Collections.emptyList();
+ if (configuredObstacles == null) {
+ configuredObstacles = Collections.emptyList();
}
- boolean showBoundaryPoints = landNumber != null && boundaryPointVisibility.getOrDefault(landNumber, false);
+ renderer.setCurrentBoundary(boundary, sanitizedLandNumber, sanitizedLandNumber == null ? null : landName);
+ renderer.setCurrentPlannedPath(plannedPath);
+ renderer.setCurrentObstacles(configuredObstacles, sanitizedLandNumber);
+ boolean showBoundaryPoints = sanitizedLandNumber != null && boundaryPointVisibility.getOrDefault(sanitizedLandNumber, false);
renderer.setBoundaryPointsVisible(showBoundaryPoints);
+ renderer.setBoundaryPointSizeScale(showBoundaryPoints ? 0.5d : 1.0d);
+ // 閫�鍑洪瑙堝悗锛屼笉鏄剧ず闅滅鐗╃偣锛堥殰纰嶇墿鐐瑰彧鍦ㄩ瑙堟椂鏄剧ず锛�
+ renderer.setObstaclePointsVisible(false);
}
+ shouye.refreshMowingIndicators();
+ }
+
+ if (changed) {
+ persistCurrentWorkLand(sanitizedLandNumber);
}
}
@@ -690,6 +1941,62 @@
return currentWorkLandNumber;
}
+ public static String getPersistedWorkLandNumber() {
+ return readPersistedWorkLandNumber();
+ }
+
+ private static String sanitizeLandNumber(String landNumber) {
+ if (landNumber == null) {
+ return null;
+ }
+ String trimmed = landNumber.trim();
+ if (trimmed.isEmpty() || "-1".equals(trimmed)) {
+ return null;
+ }
+ return trimmed;
+ }
+
+ private static void persistCurrentWorkLand(String landNumber) {
+ synchronized (Dikuaiguanli.class) {
+ Properties props = new Properties();
+ try (FileInputStream in = new FileInputStream(PROPERTIES_FILE)) {
+ props.load(in);
+ } catch (IOException ignored) {
+ // Use empty defaults when the configuration file is missing.
+ }
+
+ if (landNumber == null) {
+ props.setProperty(WORK_LAND_KEY, "-1");
+ } else {
+ props.setProperty(WORK_LAND_KEY, landNumber);
+ }
+
+ try (FileOutputStream out = new FileOutputStream(PROPERTIES_FILE)) {
+ props.store(out, "Current work land selection updated");
+ } catch (IOException ex) {
+ System.err.println("鏃犳硶淇濆瓨褰撳墠浣滀笟鍦板潡: " + ex.getMessage());
+ }
+ }
+ }
+
+ private static String readPersistedWorkLandNumber() {
+ Properties props = new Properties();
+ try (FileInputStream in = new FileInputStream(PROPERTIES_FILE)) {
+ props.load(in);
+ String value = props.getProperty(WORK_LAND_KEY);
+ if (value == null) {
+ return null;
+ }
+ String trimmed = value.trim();
+ if (trimmed.isEmpty() || "-1".equals(trimmed)) {
+ return null;
+ }
+ return trimmed;
+ } catch (IOException ex) {
+ return null;
+ }
+ }
+
private ImageIcon loadIcon(String path, int width, int height) {
try {
ImageIcon rawIcon = new ImageIcon(path);
@@ -719,13 +2026,77 @@
});
}
- private void editReturnPoint(Dikuai dikuai) {
- FanhuiDialog fd = new FanhuiDialog(SwingUtilities.getWindowAncestor(this), dikuai);
- fd.setVisible(true);
- // 濡傛灉瀵硅瘽妗嗗凡鏇存柊鏁版嵁锛屽埛鏂版樉绀�
- if (fd.isUpdated()) {
- loadDikuaiData();
+ private void editReturnPath(Dikuai dikuai) {
+ if (dikuai == null) {
+ return;
}
+ String edited = promptCoordinateEditing("鏌ョ湅 / 缂栬緫寰�杩旂偣璺緞", dikuai.getReturnPathCoordinates(), dikuai);
+ if (edited == null) {
+ return;
+ }
+ // 妫�鏌ユ槸鍚︽槸鐗规畩鏍囪锛岃〃绀虹偣鍑讳簡"鍘荤粯鍒�"鎸夐挳
+ if ("__OPEN_DRAW_PAGE__".equals(edited) || "__OPEN_DRAW_PAGE_REFRESH__".equals(edited)) {
+ // 鑾峰彇鍦板潡绠$悊瀵硅瘽妗�
+ Window owner = SwingUtilities.getWindowAncestor(this);
+ Window managementWindow = null;
+ if (owner instanceof JDialog) {
+ managementWindow = owner;
+ }
+
+ // 鑾峰彇鍦板潡绠$悊瀵硅瘽妗嗙殑鐖剁獥鍙o紙涓荤獥鍙o級锛屼綔涓虹粯鍒堕〉闈㈢殑鐖剁獥鍙�
+ Window drawPageOwner = null;
+ if (managementWindow != null) {
+ drawPageOwner = managementWindow.getOwner();
+ }
+ if (drawPageOwner == null && owner != null) {
+ drawPageOwner = owner.getOwner();
+ }
+ if (drawPageOwner == null) {
+ drawPageOwner = owner;
+ }
+
+ // 鍏堝叧闂湴鍧楃鐞嗛〉闈�
+ if (managementWindow != null) {
+ managementWindow.dispose();
+ }
+
+ // 鐒跺悗鎵撳紑缁樺埗椤甸潰锛屽鏋滄槸閲嶆柊缁樺埗锛屼紶閫掓爣璁�
+ boolean isRefresh = "__OPEN_DRAW_PAGE_REFRESH__".equals(edited);
+ Huizhiwanfanpath.showDrawReturnPathDialog(drawPageOwner, dikuai, isRefresh);
+ return;
+ }
+ String normalized = normalizeCoordinateInput(edited);
+ if (!saveFieldAndRefresh(dikuai, "returnPathCoordinates", normalized)) {
+ JOptionPane.showMessageDialog(this, "鏃犳硶鏇存柊寰�杩旂偣璺緞", "閿欒", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ String message = "-1".equals(normalized) ? "寰�杩旂偣璺緞宸叉竻绌�" : "寰�杩旂偣璺緞宸叉洿鏂�";
+ JOptionPane.showMessageDialog(this, message, "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+ }
+
+ /**
+ * 鏄剧ず闅滅鐗╃鐞嗛〉闈�
+ */
+ private void showObstacleManagementPage(Dikuai dikuai) {
+ if (dikuai == null) {
+ return;
+ }
+ Window owner = SwingUtilities.getWindowAncestor(this);
+
+ // 鑾峰彇鍦板潡绠$悊瀵硅瘽妗嗭紝鍑嗗鍦ㄦ墦寮�闅滅鐗╃鐞嗛〉闈㈡椂鍏抽棴
+ Window managementWindow = null;
+ if (owner instanceof JDialog) {
+ managementWindow = owner;
+ }
+
+ ObstacleManagementPage managementPage = new ObstacleManagementPage(owner, dikuai);
+
+ // 鍏抽棴鍦板潡绠$悊椤甸潰
+ if (managementWindow != null) {
+ managementWindow.dispose();
+ }
+
+ managementPage.setVisible(true);
}
private void addNewObstacle(Dikuai dikuai) {
@@ -743,6 +2114,80 @@
loadDikuaiData();
}
+ private void showCompletedMowingTrackDialog(Dikuai dikuai) {
+ if (dikuai == null) {
+ return;
+ }
+ Window owner = SwingUtilities.getWindowAncestor(this);
+ JDialog dialog = new JDialog(owner, "宸插畬鎴愮殑鍓茶崏璺緞鍧愭爣", Dialog.ModalityType.APPLICATION_MODAL);
+ dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+ dialog.setLayout(new BorderLayout());
+ dialog.getContentPane().setBackground(WHITE);
+
+ String normalizedTrack = prepareCoordinateForEditor(dikuai.getMowingTrack());
+ boolean hasTrack = normalizedTrack != null && !normalizedTrack.isEmpty();
+
+ JTextArea textArea = new JTextArea(hasTrack ? normalizedTrack : "");
+ textArea.setEditable(false);
+ textArea.setLineWrap(true);
+ textArea.setWrapStyleWord(true);
+ textArea.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 13));
+ textArea.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
+ textArea.setCaretPosition(0);
+
+ JScrollPane scrollPane = new JScrollPane(textArea);
+ scrollPane.setPreferredSize(new Dimension(342, 240));
+ scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 12, 0, 12));
+
+ JLabel statusLabel = new JLabel(hasTrack ? "褰撳墠宸蹭繚瀛樺畬鎴愮殑鍓茶崏璺緞璁板綍銆�" : "褰撳墠鏆傛棤瀹屾垚鐨勫壊鑽夎矾寰勮褰曘��");
+ statusLabel.setBorder(BorderFactory.createEmptyBorder(12, 12, 6, 12));
+ statusLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
+ statusLabel.setForeground(hasTrack ? TEXT_COLOR : LIGHT_TEXT);
+
+ JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 8, 0));
+ buttonPanel.setBackground(WHITE);
+ buttonPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
+
+ JButton deleteButton = createSmallButton("鍒犻櫎璁板綍", RED_COLOR, RED_DARK);
+ deleteButton.setEnabled(hasTrack);
+ JButton closeButton = createSmallButton("鍏抽棴", PRIMARY_COLOR, PRIMARY_DARK);
+
+ deleteButton.addActionListener(e -> {
+ String latestTrack = prepareCoordinateForEditor(dikuai.getMowingTrack());
+ if (latestTrack == null || latestTrack.isEmpty()) {
+ JOptionPane.showMessageDialog(dialog, "褰撳墠娌℃湁鍙垹闄ょ殑杞ㄨ抗璁板綍銆�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+ return;
+ }
+ int choice = JOptionPane.showConfirmDialog(dialog, "纭畾瑕佸垹闄ゅ凡瀹屾垚鐨勫壊鑽夎矾寰勮褰曞悧锛�", "纭鍒犻櫎", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
+ if (choice != JOptionPane.YES_OPTION) {
+ return;
+ }
+ if (saveFieldAndRefresh(dikuai, "mowingTrack", "-1")) {
+ dikuai.setMowingTrack("-1");
+ textArea.setText("");
+ statusLabel.setText("褰撳墠鏆傛棤瀹屾垚鐨勫壊鑽夎矾寰勮褰曘��");
+ statusLabel.setForeground(LIGHT_TEXT);
+ deleteButton.setEnabled(false);
+ JOptionPane.showMessageDialog(dialog, "宸插垹闄ゅ畬鎴愯矾寰勮褰�", "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+ } else {
+ JOptionPane.showMessageDialog(dialog, "鍒犻櫎澶辫触锛岃绋嶅悗閲嶈瘯銆�", "閿欒", JOptionPane.ERROR_MESSAGE);
+ }
+ });
+
+ closeButton.addActionListener(e -> dialog.dispose());
+
+ buttonPanel.add(deleteButton);
+ buttonPanel.add(closeButton);
+
+ dialog.add(statusLabel, BorderLayout.NORTH);
+ dialog.add(scrollPane, BorderLayout.CENTER);
+ dialog.add(buttonPanel, BorderLayout.SOUTH);
+ dialog.pack();
+ dialog.setMinimumSize(new Dimension(378, 320));
+ dialog.setLocationRelativeTo(owner);
+ dialog.setVisible(true);
+ }
+
private Map<String, ObstacleSummary> loadObstacleSummaries() {
Map<String, ObstacleSummary> summaries = new HashMap<>();
try {
@@ -1024,4 +2469,6 @@
return new ArrayList<>(names);
}
}
+
+
}
\ No newline at end of file
--
Gitblit v1.10.0