From a3b05960fe629e9006b45d61618b01f724e757fd Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 19 十二月 2025 17:41:08 +0800
Subject: [PATCH] 美化了地块管理的排版
---
src/zhuye/Shouye.java | 425 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 420 insertions(+), 5 deletions(-)
diff --git a/src/zhuye/Shouye.java b/src/zhuye/Shouye.java
index 44398ed..1dbc337 100644
--- a/src/zhuye/Shouye.java
+++ b/src/zhuye/Shouye.java
@@ -80,6 +80,8 @@
private JLabel statusLabel;
private JLabel speedLabel; // 閫熷害鏄剧ず鏍囩
private JLabel areaNameLabel;
+ private JLabel drawingBoundaryLabel; // 姝e湪缁樺埗杈圭晫鐘舵�佹爣绛�
+ private JLabel navigationPreviewLabel; // 瀵艰埅棰勮妯″紡鏍囩
// 杈圭晫璀﹀憡鐩稿叧
private Timer boundaryWarningTimer; // 杈圭晫璀﹀憡妫�鏌ュ畾鏃跺櫒
@@ -125,6 +127,8 @@
private JButton pathPreviewReturnButton;
private boolean pathPreviewActive;
private Runnable pathPreviewReturnAction;
+ private JButton settingsReturnButton; // 杩斿洖绯荤粺璁剧疆椤甸潰鐨勬偓娴寜閽�
+ private JButton saveManualBoundaryButton; // 淇濆瓨鎵嬪姩缁樺埗杈圭晫鐨勬寜閽�
private String previewRestoreLandNumber;
private String previewRestoreLandName;
private boolean drawingPaused;
@@ -452,6 +456,251 @@
}
}
mapRenderer.setIdleTrailDurationSeconds(durationSeconds);
+
+ // 搴旂敤杈圭晫璺濈鏄剧ず璁剧疆鍜屾祴閲忔ā寮忚缃�
+ Setsys setsys = new Setsys();
+ setsys.initializeFromProperties();
+ mapRenderer.setBoundaryLengthVisible(setsys.isBoundaryLengthVisible());
+ // 鍒濆鍖栨祴閲忔ā寮�
+ boolean measurementEnabled = setsys.isMeasurementModeEnabled();
+ mapRenderer.setMeasurementMode(measurementEnabled);
+ if (measurementEnabled) {
+ celiangmoshi.start();
+ } else {
+ celiangmoshi.stop();
+ }
+ // 鍒濆鍖栨墜鍔ㄧ粯鍒惰竟鐣屾ā寮�
+ boolean manualBoundaryDrawingEnabled = setsys.isManualBoundaryDrawingMode();
+ if (mapRenderer != null) {
+ mapRenderer.setManualBoundaryDrawingMode(manualBoundaryDrawingEnabled);
+ }
+ // 鏇存柊杩斿洖璁剧疆鎸夐挳鐨勬樉绀虹姸鎬�
+ updateSettingsReturnButtonVisibility();
+ }
+
+ /**
+ * 鏇存柊杩斿洖绯荤粺璁剧疆鎸夐挳鐨勬樉绀虹姸鎬�
+ * 褰撴墜鍔ㄧ粯鍒惰竟鐣屾ā寮忋�佹樉绀鸿竟鐣岃窛绂绘垨寮�鍚祴閲忔ā寮忎换涓�寮�鍚椂鏄剧ず
+ */
+ public void updateSettingsReturnButtonVisibility() {
+ Setsys setsys = new Setsys();
+ setsys.initializeFromProperties();
+
+ boolean manualBoundaryDrawingEnabled = setsys.isManualBoundaryDrawingMode();
+ boolean shouldShow = manualBoundaryDrawingEnabled
+ || setsys.isBoundaryLengthVisible()
+ || setsys.isMeasurementModeEnabled();
+
+ if (shouldShow) {
+ showSettingsReturnButton();
+ // 濡傛灉鎵嬪姩缁樺埗杈圭晫妯″紡寮�鍚紝鏄剧ず淇濆瓨鎸夐挳
+ if (manualBoundaryDrawingEnabled) {
+ showSaveManualBoundaryButton();
+ } else {
+ hideSaveManualBoundaryButton();
+ }
+ } else {
+ hideSettingsReturnButton();
+ hideSaveManualBoundaryButton();
+ }
+ }
+
+ /**
+ * 鏄剧ず杩斿洖绯荤粺璁剧疆鎸夐挳
+ */
+ private void showSettingsReturnButton() {
+ ensureFloatingButtonInfrastructure();
+ if (settingsReturnButton == null) {
+ settingsReturnButton = createFloatingTextButton("杩斿洖");
+ settingsReturnButton.setToolTipText("杩斿洖绯荤粺璁剧疆");
+ settingsReturnButton.addActionListener(e -> {
+ // 鍏抽棴鎵�鏈夌浉鍏虫ā寮�
+ Setsys setsys = new Setsys();
+ setsys.initializeFromProperties();
+
+ boolean modeChanged = false;
+
+ // 鍏抽棴鎵嬪姩缁樺埗杈圭晫妯″紡
+ if (setsys.isManualBoundaryDrawingMode()) {
+ setsys.setManualBoundaryDrawingMode(false);
+ setsys.updateProperty("manualBoundaryDrawingMode", "false");
+ // 娓呯┖鎵嬪姩缁樺埗鐨勮竟鐣岀偣
+ if (mapRenderer != null) {
+ mapRenderer.clearManualBoundaryPoints();
+ }
+ modeChanged = true;
+ }
+
+ // 鍏抽棴鏄剧ず杈圭晫璺濈
+ if (setsys.isBoundaryLengthVisible()) {
+ setsys.setBoundaryLengthVisible(false);
+ setsys.updateProperty("boundaryLengthVisible", "false");
+ if (mapRenderer != null) {
+ mapRenderer.setBoundaryLengthVisible(false);
+ }
+ modeChanged = true;
+ }
+
+ // 鍏抽棴娴嬮噺妯″紡
+ if (setsys.isMeasurementModeEnabled()) {
+ setsys.setMeasurementModeEnabled(false);
+ setsys.updateProperty("measurementModeEnabled", "false");
+ if (mapRenderer != null) {
+ mapRenderer.setMeasurementMode(false);
+ }
+ celiangmoshi.stop();
+ modeChanged = true;
+ }
+
+ // 濡傛灉鍏抽棴浜嗕换浣曟ā寮忥紝绔嬪嵆闅愯棌杩斿洖鎸夐挳骞跺埛鏂扮晫闈�
+ if (modeChanged) {
+ // 绔嬪嵆闅愯棌杩斿洖鎸夐挳
+ if (settingsReturnButton != null) {
+ settingsReturnButton.setVisible(false);
+ }
+ // 鏇存柊鎸夐挳鍒楋紙绉婚櫎杩斿洖鎸夐挳锛�
+ rebuildFloatingButtonColumn();
+ // 濡傛灉鎵�鏈夋寜閽兘闅愯棌浜嗭紝闅愯棌鎮诞鎸夐挳闈㈡澘
+ if (floatingButtonPanel != null && floatingButtonColumn != null
+ && floatingButtonColumn.getComponentCount() == 0) {
+ floatingButtonPanel.setVisible(false);
+ }
+ // 鍒锋柊鐣岄潰
+ if (visualizationPanel != null) {
+ visualizationPanel.revalidate();
+ visualizationPanel.repaint();
+ }
+ }
+
+ // 鏇存柊杩斿洖鎸夐挳鏄剧ず鐘舵�侊紙纭繚鐘舵�佸悓姝ワ級
+ updateSettingsReturnButtonVisibility();
+
+ // 鎵撳紑绯荤粺璁剧疆椤甸潰
+ showSettingsDialog();
+ });
+ }
+ settingsReturnButton.setVisible(true);
+ // 闅愯棌缁樺埗鐩稿叧鐨勬寜閽紙鏆傚仠銆佺粨鏉熺粯鍒讹級
+ if (drawingPauseButton != null) {
+ drawingPauseButton.setVisible(false);
+ }
+ if (endDrawingButton != null) {
+ endDrawingButton.setVisible(false);
+ }
+ if (floatingButtonPanel != null) {
+ floatingButtonPanel.setVisible(true);
+ if (floatingButtonPanel.getParent() != visualizationPanel) {
+ visualizationPanel.add(floatingButtonPanel, BorderLayout.SOUTH);
+ }
+ }
+ rebuildFloatingButtonColumn();
+ }
+
+ /**
+ * 闅愯棌杩斿洖绯荤粺璁剧疆鎸夐挳
+ */
+ private void hideSettingsReturnButton() {
+ if (settingsReturnButton != null) {
+ settingsReturnButton.setVisible(false);
+ }
+ rebuildFloatingButtonColumn();
+ if (floatingButtonPanel != null && floatingButtonColumn != null
+ && floatingButtonColumn.getComponentCount() == 0) {
+ floatingButtonPanel.setVisible(false);
+ }
+ }
+
+ /**
+ * 鏄剧ず淇濆瓨鎵嬪姩缁樺埗杈圭晫鎸夐挳
+ */
+ private void showSaveManualBoundaryButton() {
+ ensureFloatingButtonInfrastructure();
+ if (saveManualBoundaryButton == null) {
+ saveManualBoundaryButton = createFloatingTextButton("淇濆瓨");
+ saveManualBoundaryButton.setToolTipText("淇濆瓨鎵嬪姩缁樺埗鐨勮竟鐣�");
+ saveManualBoundaryButton.addActionListener(e -> saveManualBoundary());
+ }
+ saveManualBoundaryButton.setVisible(true);
+ if (floatingButtonPanel != null) {
+ floatingButtonPanel.setVisible(true);
+ if (floatingButtonPanel.getParent() != visualizationPanel) {
+ visualizationPanel.add(floatingButtonPanel, BorderLayout.SOUTH);
+ }
+ }
+ rebuildFloatingButtonColumn();
+ }
+
+ /**
+ * 闅愯棌淇濆瓨鎵嬪姩缁樺埗杈圭晫鎸夐挳
+ */
+ private void hideSaveManualBoundaryButton() {
+ if (saveManualBoundaryButton != null) {
+ saveManualBoundaryButton.setVisible(false);
+ }
+ rebuildFloatingButtonColumn();
+ if (floatingButtonPanel != null && floatingButtonColumn != null
+ && floatingButtonColumn.getComponentCount() == 0) {
+ floatingButtonPanel.setVisible(false);
+ }
+ }
+
+ /**
+ * 淇濆瓨鎵嬪姩缁樺埗鐨勮竟鐣屽埌鏂囦欢
+ */
+ private void saveManualBoundary() {
+ if (mapRenderer == null) {
+ JOptionPane.showMessageDialog(this, "鍦板浘娓叉煋鍣ㄦ湭鍒濆鍖�", "閿欒", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ List<Point2D.Double> points = mapRenderer.getManualBoundaryPoints();
+ if (points == null || points.isEmpty()) {
+ JOptionPane.showMessageDialog(this, "娌℃湁鍙繚瀛樼殑杈圭晫鐐癸紝璇峰厛鍦ㄥ湴鍥句笂鐐瑰嚮缁樺埗杈圭晫", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+
+ // 鏋勫缓鍧愭爣瀛楃涓诧細x1,y1;x2,y2;...;xn,yn锛堝崟浣嶏細绫筹紝绮剧‘鍒板皬鏁扮偣鍚�2浣嶏級
+ StringBuilder coordinates = new StringBuilder();
+ for (int i = 0; i < points.size(); i++) {
+ Point2D.Double point = points.get(i);
+ if (i > 0) {
+ coordinates.append(";");
+ }
+ coordinates.append(String.format(Locale.US, "%.2f,%.2f", point.x, point.y));
+ }
+
+ // 淇濆瓨鍒� properties 鏂囦欢
+ try {
+ java.util.Properties props = new java.util.Properties();
+ java.io.File file = new java.io.File("shoudongbianjie.properties");
+
+ // 濡傛灉鏂囦欢瀛樺湪锛屽厛鍔犺浇鐜版湁鍐呭
+ if (file.exists()) {
+ try (java.io.FileInputStream input = new java.io.FileInputStream(file)) {
+ props.load(input);
+ }
+ }
+
+ // 淇濆瓨鍧愭爣
+ props.setProperty("boundaryCoordinates", coordinates.toString());
+ props.setProperty("pointCount", String.valueOf(points.size()));
+
+ // 鍐欏洖鏂囦欢
+ try (java.io.FileOutputStream output = new java.io.FileOutputStream(file)) {
+ props.store(output, "鎵嬪姩缁樺埗杈圭晫鍧愭爣 - 鏍煎紡: x1,y1;x2,y2;...;xn,yn (鍗曚綅:绫�,绮剧‘鍒板皬鏁扮偣鍚�2浣�)");
+ }
+
+ JOptionPane.showMessageDialog(this,
+ String.format("杈圭晫宸蹭繚瀛樻垚鍔燂紒\n鍏� %d 涓偣", points.size()),
+ "淇濆瓨鎴愬姛",
+ JOptionPane.INFORMATION_MESSAGE);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ JOptionPane.showMessageDialog(this,
+ "淇濆瓨澶辫触: " + ex.getMessage(),
+ "閿欒",
+ JOptionPane.ERROR_MESSAGE);
+ }
}
private void createHeaderPanel() {
@@ -498,14 +747,28 @@
// 娣诲姞閫熷害鏄剧ず鏍囩
speedLabel = new JLabel("");
- speedLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
- speedLabel.setForeground(Color.GRAY);
- speedLabel.setVisible(false); // 榛樿闅愯棌
+ speedLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
+ speedLabel.setForeground(Color.GRAY);
+ speedLabel.setVisible(false); // 榛樿闅愯棌
+
+ // 姝e湪缁樺埗杈圭晫鐘舵�佹爣绛�
+ drawingBoundaryLabel = new JLabel("姝e湪缁樺埗杈圭晫");
+ drawingBoundaryLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+ drawingBoundaryLabel.setForeground(new Color(46, 139, 87));
+ drawingBoundaryLabel.setVisible(false); // 榛樿闅愯棌
+
+ // 瀵艰埅棰勮妯″紡鏍囩
+ navigationPreviewLabel = new JLabel("褰撳墠瀵艰埅棰勮妯″紡");
+ navigationPreviewLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+ navigationPreviewLabel.setForeground(new Color(46, 139, 87));
+ navigationPreviewLabel.setVisible(false); // 榛樿闅愯棌
// 灏嗙姸鎬佷笌閫熷害鏀惧湪鍚屼竴琛岋紝鏄剧ず鍦ㄥ湴鍧楀悕绉颁笅闈竴琛�
JPanel statusRow = new JPanel(new FlowLayout(FlowLayout.LEFT, 8, 0));
statusRow.setOpaque(false);
statusRow.add(statusLabel);
+ statusRow.add(drawingBoundaryLabel);
+ statusRow.add(navigationPreviewLabel);
statusRow.add(speedLabel);
// 宸﹀榻愭爣绛句笌鐘舵�佽锛岀‘淇濆畠浠湪 BoxLayout 涓潬宸︽樉绀�
@@ -1141,7 +1404,7 @@
if (parentWindow != null) {
// 浣跨敤 yaokong 鍖呬腑鐨� RemoteControlDialog 瀹炵幇
remoteDialog = new yaokong.RemoteControlDialog(this, THEME_COLOR, speedLabel);
- } else {
+ } else {/* */
remoteDialog = new yaokong.RemoteControlDialog((JFrame) null, THEME_COLOR, speedLabel);
}
}
@@ -2780,6 +3043,16 @@
circleDialogMode = false;
hideCircleGuidancePanel();
enterDrawingControlMode();
+
+ // 闅愯棌杩斿洖璁剧疆鎸夐挳锛堝鏋滄樉绀虹粯鍒舵寜閽紝鍒欎笉搴旇鏄剧ず杩斿洖鎸夐挳锛�
+ if (settingsReturnButton != null) {
+ settingsReturnButton.setVisible(false);
+ }
+
+ // 鏄剧ず"姝e湪缁樺埗杈圭晫"鎻愮ず
+ if (drawingBoundaryLabel != null) {
+ drawingBoundaryLabel.setVisible(true);
+ }
boolean enableCircleGuidance = drawingShape != null
&& "circle".equalsIgnoreCase(drawingShape.trim());
@@ -2889,6 +3162,20 @@
floatingButtonColumn.add(pathPreviewReturnButton);
added = true;
}
+ if (saveManualBoundaryButton != null && saveManualBoundaryButton.isVisible()) {
+ if (added) {
+ floatingButtonColumn.add(Box.createRigidArea(new Dimension(0, 10)));
+ }
+ floatingButtonColumn.add(saveManualBoundaryButton);
+ added = true;
+ }
+ if (settingsReturnButton != null && settingsReturnButton.isVisible()) {
+ if (added) {
+ floatingButtonColumn.add(Box.createRigidArea(new Dimension(0, 10)));
+ }
+ floatingButtonColumn.add(settingsReturnButton);
+ added = true;
+ }
floatingButtonColumn.revalidate();
floatingButtonColumn.repaint();
}
@@ -3255,7 +3542,34 @@
if (latest == null) {
return false;
}
- return lastCapturedCoordinate == null || latest != lastCapturedCoordinate;
+
+ // 妫�鏌ユ槸鍚︽湁鏂扮殑鍧愭爣锛堜笌涓婃閲囬泦鐨勪笉鍚岋級
+ if (lastCapturedCoordinate != null && latest == lastCapturedCoordinate) {
+ return false;
+ }
+
+ // 妫�鏌ュ畾浣嶇姸鎬佹槸鍚︿负4锛堝浐瀹氳В锛�
+ // 褰撻�夋嫨鍓茶崏鏈虹粯鍒跺渾褰㈤殰纰嶇墿鏃讹紝闇�瑕佹鏌ヨ澶囩紪鍙峰拰瀹氫綅鐘舵��
+ Device device = Device.getGecaoji();
+ if (device == null) {
+ return false;
+ }
+
+ String positioningStatus = device.getPositioningStatus();
+ if (positioningStatus == null || !"4".equals(positioningStatus.trim())) {
+ return false;
+ }
+
+ // 妫�鏌ヨ澶囩紪鍙锋槸鍚﹀尮閰嶅壊鑽夋満缂栧彿
+ String mowerId = Setsys.getPropertyValue("mowerId");
+ String deviceId = device.getMowerNumber();
+ if (mowerId != null && !mowerId.trim().isEmpty()) {
+ if (deviceId == null || !mowerId.trim().equals(deviceId.trim())) {
+ return false;
+ }
+ }
+
+ return true;
}
private void applyCirclePrimaryButtonState(boolean enabled) {
@@ -3457,6 +3771,12 @@
activeBoundaryMode = BoundaryCaptureMode.NONE;
}
endDrawingCallback = null;
+
+ // 闅愯棌"姝e湪缁樺埗杈圭晫"鎻愮ず
+ if (drawingBoundaryLabel != null) {
+ drawingBoundaryLabel.setVisible(false);
+ }
+
visualizationPanel.revalidate();
visualizationPanel.repaint();
setHandheldMowerIconActive(false);
@@ -3602,6 +3922,101 @@
return mapRenderer;
}
+ /**
+ * 鑾峰彇鎺у埗闈㈡澘锛堢敤浜庡鑸瑙堟椂鏇挎崲鎸夐挳锛�
+ * @return 鎺у埗闈㈡澘
+ */
+ public JPanel getControlPanel() {
+ return controlPanel;
+ }
+
+ /**
+ * 鑾峰彇寮�濮嬫寜閽紙鐢ㄤ簬瀵艰埅棰勮鏃堕殣钘忥級
+ * @return 寮�濮嬫寜閽�
+ */
+ public JButton getStartButton() {
+ return startBtn;
+ }
+
+ /**
+ * 鑾峰彇缁撴潫鎸夐挳锛堢敤浜庡鑸瑙堟椂闅愯棌锛�
+ * @return 缁撴潫鎸夐挳
+ */
+ public JButton getStopButton() {
+ return stopBtn;
+ }
+
+ /**
+ * 璁剧疆瀵艰埅棰勮妯″紡鏍囩鐨勬樉绀虹姸鎬�
+ * @param visible 鏄惁鏄剧ず
+ */
+ public void setNavigationPreviewLabelVisible(boolean visible) {
+ if (navigationPreviewLabel != null) {
+ navigationPreviewLabel.setVisible(visible);
+ }
+ }
+
+ /**
+ * 鏇存柊瀵艰埅棰勮鐘舵�佹樉绀�
+ * @param active 鏄惁澶勪簬瀵艰埅棰勮妯″紡
+ */
+ public void updateNavigationPreviewStatus(boolean active) {
+ setNavigationPreviewLabelVisible(active);
+ }
+
+ /**
+ * 鏇存柊鍓茶崏杩涘害鏄剧ず
+ * @param percentage 瀹屾垚鐧惧垎姣�
+ * @param completedArea 宸插畬鎴愰潰绉紙骞虫柟绫筹級
+ * @param totalArea 鎬婚潰绉紙骞虫柟绫筹級
+ */
+ public void updateMowingProgress(double percentage, double completedArea, double totalArea) {
+ if (mowingProgressLabel == null) {
+ return;
+ }
+ if (totalArea <= 0) {
+ mowingProgressLabel.setText("--%");
+ mowingProgressLabel.setToolTipText("鏆傛棤鍦板潡闈㈢Н鏁版嵁");
+ return;
+ }
+ double percent = Math.max(0.0, Math.min(100.0, percentage));
+ mowingProgressLabel.setText(String.format(Locale.US, "%.1f%%", percent));
+ mowingProgressLabel.setToolTipText(String.format(Locale.US, "%.1f銕� / %.1f銕�", completedArea, totalArea));
+ }
+
+ /**
+ * 鏇存柊鍓茶崏鏈洪�熷害鏄剧ず
+ * @param speed 閫熷害鍊硷紙鍗曚綅锛歬m/h锛�
+ */
+ public void updateMowerSpeed(double speed) {
+ if (mowerSpeedValueLabel == null) {
+ return;
+ }
+ if (speed < 0) {
+ mowerSpeedValueLabel.setText("--");
+ } else {
+ mowerSpeedValueLabel.setText(String.format(Locale.US, "%.1f", speed));
+ }
+ if (mowerSpeedUnitLabel != null) {
+ mowerSpeedUnitLabel.setText("km/h");
+ }
+ }
+
+ /**
+ * 鑾峰彇鍙鍖栭潰鏉垮疄渚�
+ */
+ public JPanel getVisualizationPanel() {
+ return visualizationPanel;
+ }
+
+ /**
+ * 鑾峰彇涓诲唴瀹归潰鏉垮疄渚嬶紙鐢ㄤ簬娣诲姞娴姩鎸夐挳锛�
+ */
+ public JPanel getMainContentPanel() {
+ return mainContentPanel;
+ }
+
+
public void updateCurrentAreaName(String areaName) {
if (areaNameLabel == null) {
return;
--
Gitblit v1.10.0