From b272034a1fdbfe32b355fc6c264a4c45df107190 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期二, 23 十二月 2025 14:55:03 +0800
Subject: [PATCH] 优化了新增地块功能
---
src/zhuye/Shouye.java | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 102 insertions(+), 3 deletions(-)
diff --git a/src/zhuye/Shouye.java b/src/zhuye/Shouye.java
index 8162334..a59e71d 100644
--- a/src/zhuye/Shouye.java
+++ b/src/zhuye/Shouye.java
@@ -131,8 +131,10 @@
private Runnable pathPreviewReturnAction;
private JButton settingsReturnButton; // 杩斿洖绯荤粺璁剧疆椤甸潰鐨勬偓娴寜閽�
private JButton saveManualBoundaryButton; // 淇濆瓨鎵嬪姩缁樺埗杈圭晫鐨勬寜閽�
+ private JButton toggleBoundaryDisplayButton; // 鍒囨崲杈圭晫鏄剧ず鎸夐挳锛堝彧鏄剧ず鍘熷杈圭晫/鏄剧ず鍏ㄩ儴锛�
private String previewRestoreLandNumber;
private String previewRestoreLandName;
+ private Dikuai currentBoundaryPreviewDikuai; // 褰撳墠杈圭晫棰勮鐨勫湴鍧楀紩鐢�
private boolean drawingPaused;
private ImageIcon pauseIcon;
private ImageIcon pauseActiveIcon;
@@ -3238,6 +3240,13 @@
floatingButtonColumn.add(pathPreviewReturnButton);
added = true;
}
+ if (toggleBoundaryDisplayButton != null && toggleBoundaryDisplayButton.isVisible()) {
+ if (added) {
+ floatingButtonColumn.add(Box.createRigidArea(new Dimension(0, 10)));
+ }
+ floatingButtonColumn.add(toggleBoundaryDisplayButton);
+ added = true;
+ }
if (saveManualBoundaryButton != null && saveManualBoundaryButton.isVisible()) {
if (added) {
floatingButtonColumn.add(Box.createRigidArea(new Dimension(0, 10)));
@@ -4309,12 +4318,32 @@
return;
}
+ // 淇濆瓨褰撳墠鍦板潡寮曠敤
+ shouye.currentBoundaryPreviewDikuai = dikuai;
+
// 鑾峰彇鍘熷杈圭晫XY鍧愭爣
String originalBoundaryXY = dikuai.getBoundaryOriginalXY();
// 璁剧疆杈圭晫棰勮
shouye.mapRenderer.setBoundaryPreview(originalBoundaryXY, optimizedBoundary);
+ // 璁剧疆杈圭晫棰勮鏇存柊鍥炶皟锛岀敤浜庝繚瀛樺垹闄ゅ潗鏍囩偣鍚庣殑杈圭晫
+ shouye.mapRenderer.setBoundaryPreviewUpdateCallback(updatedBoundary -> {
+ if (shouye.currentBoundaryPreviewDikuai != null && updatedBoundary != null) {
+ // 淇濆瓨鏇存柊鍚庣殑杈圭晫鍧愭爣
+ Dikuai.updateField(shouye.currentBoundaryPreviewDikuai.getLandNumber(), "boundaryCoordinates", updatedBoundary);
+ java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ Dikuai.updateField(shouye.currentBoundaryPreviewDikuai.getLandNumber(), "updateTime", sdf.format(new java.util.Date()));
+ Dikuai.saveToProperties();
+
+ // 鍚屾鏇存柊褰撳墠鍦板潡瀵硅薄鐨勫唴瀛樺�硷紙纭繚杩斿洖鏃惰兘鑾峰彇鍒版渶鏂板�硷級
+ shouye.currentBoundaryPreviewDikuai.setBoundaryCoordinates(updatedBoundary);
+
+ // 鏇存柊棰勮杈圭晫锛堥噸鏂拌缃互鍒锋柊鏄剧ず锛�
+ shouye.mapRenderer.setBoundaryPreview(originalBoundaryXY, updatedBoundary);
+ }
+ });
+
// 鍋滄缁樺埗鍓茶崏鏈哄疄鏃舵嫋灏�
if (shouye.mapRenderer != null) {
shouye.mapRenderer.setIdleTrailSuppressed(true);
@@ -4333,11 +4362,23 @@
shouye.pathPreviewReturnButton.setToolTipText("杩斿洖杈圭晫缂栬緫椤甸潰");
}
+ // 鍒涘缓鎴栨樉绀哄垏鎹㈣竟鐣屾樉绀烘寜閽�
+ if (shouye.toggleBoundaryDisplayButton == null) {
+ shouye.toggleBoundaryDisplayButton = shouye.createToggleBoundaryDisplayButton();
+ }
+
+ // 閲嶇疆鍒囨崲鎸夐挳鐘舵�侊紙榛樿鏄剧ず鍏ㄩ儴杈圭晫锛�
+ if (shouye.mapRenderer != null) {
+ shouye.mapRenderer.setShowOnlyOriginalBoundary(false);
+ }
+ shouye.updateToggleBoundaryDisplayButtonText();
+
// 闅愯棌鍏朵粬鎮诞鎸夐挳
shouye.hideFloatingDrawingControls();
- // 鏄剧ず杩斿洖鎸夐挳
+ // 鏄剧ず杩斿洖鎸夐挳鍜屽垏鎹㈡寜閽�
shouye.pathPreviewReturnButton.setVisible(true);
+ shouye.toggleBoundaryDisplayButton.setVisible(true);
if (shouye.floatingButtonPanel != null) {
shouye.floatingButtonPanel.setVisible(true);
if (shouye.floatingButtonPanel.getParent() != shouye.visualizationPanel) {
@@ -4367,20 +4408,28 @@
private void exitBoundaryPreview() {
pathPreviewActive = false;
+ // 娓呴櫎褰撳墠鍦板潡寮曠敤
+ currentBoundaryPreviewDikuai = null;
+
// 鎭㈠缁樺埗鍓茶崏鏈哄疄鏃舵嫋灏�
if (mapRenderer != null) {
mapRenderer.setIdleTrailSuppressed(false);
}
- // 娓呴櫎杈圭晫棰勮
+ // 娓呴櫎杈圭晫棰勮骞堕噸缃樉绀虹姸鎬�
if (mapRenderer != null) {
mapRenderer.clearBoundaryPreview();
+ mapRenderer.setBoundaryPreviewUpdateCallback(null);
+ mapRenderer.setShowOnlyOriginalBoundary(false); // 閲嶇疆涓烘樉绀哄叏閮ㄨ竟鐣�
}
- // 闅愯棌杩斿洖鎸夐挳
+ // 闅愯棌杩斿洖鎸夐挳鍜屽垏鎹㈡寜閽�
if (pathPreviewReturnButton != null) {
pathPreviewReturnButton.setVisible(false);
}
+ if (toggleBoundaryDisplayButton != null) {
+ toggleBoundaryDisplayButton.setVisible(false);
+ }
// 闅愯棌鎮诞闈㈡澘
if (floatingButtonPanel != null) {
@@ -4390,6 +4439,56 @@
visualizationPanel.revalidate();
visualizationPanel.repaint();
}
+
+ /**
+ * 鍒涘缓鍒囨崲杈圭晫鏄剧ず鎸夐挳
+ */
+ private JButton createToggleBoundaryDisplayButton() {
+ JButton button = new JButton("闅愯棌浼樺寲杈圭晫");
+ button.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 13));
+ button.setBackground(new Color(46, 139, 87));
+ button.setForeground(Color.WHITE);
+ button.setBorder(BorderFactory.createEmptyBorder(8, 16, 8, 16));
+ button.setFocusPainted(false);
+ button.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ button.setToolTipText("鍒囨崲鏄剧ず锛氬彧鏄剧ず鍘熷杈圭晫/鏄剧ず鍏ㄩ儴杈圭晫");
+
+ button.addActionListener(e -> {
+ if (mapRenderer == null) {
+ return;
+ }
+ // 鍒囨崲鏄剧ず鐘舵��
+ boolean currentState = mapRenderer.isShowOnlyOriginalBoundary();
+ mapRenderer.setShowOnlyOriginalBoundary(!currentState);
+ updateToggleBoundaryDisplayButtonText();
+ });
+
+ button.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mouseEntered(java.awt.event.MouseEvent e) {
+ button.setBackground(new Color(30, 107, 69));
+ }
+
+ public void mouseExited(java.awt.event.MouseEvent e) {
+ button.setBackground(new Color(46, 139, 87));
+ }
+ });
+
+ return button;
+ }
+
+ /**
+ * 鏇存柊鍒囨崲杈圭晫鏄剧ず鎸夐挳鐨勬枃鏈�
+ */
+ private void updateToggleBoundaryDisplayButtonText() {
+ if (toggleBoundaryDisplayButton == null || mapRenderer == null) {
+ return;
+ }
+ if (mapRenderer.isShowOnlyOriginalBoundary()) {
+ toggleBoundaryDisplayButton.setText("鏄剧ず鍏ㄩ儴杈圭晫");
+ } else {
+ toggleBoundaryDisplayButton.setText("闅愯棌浼樺寲杈圭晫");
+ }
+ }
// 娴嬭瘯鏂规硶
public static void main(String[] args) {
--
Gitblit v1.10.0