From f0d6cefec73492c29d8323e66fb92ee6bbb60cd2 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 26 十二月 2025 18:58:23 +0800
Subject: [PATCH] 优化了预览时候视图居中的逻辑

---
 src/set/Sets.java |  103 ++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 76 insertions(+), 27 deletions(-)

diff --git a/src/set/Sets.java b/src/set/Sets.java
index 2379b27..00d5325 100644
--- a/src/set/Sets.java
+++ b/src/set/Sets.java
@@ -110,6 +110,8 @@
         mainPanel.add(scrollPane, BorderLayout.CENTER);
         
         add(mainPanel, BorderLayout.CENTER);
+        
+        setupEventHandlers();
     }
     
     private JPanel createSettingsPanel() {
@@ -193,6 +195,9 @@
         JPanel manualBoundaryDrawingPanel = createManualBoundaryDrawingPanel();
         manualBoundaryDrawingModeLabel = (JLabel) manualBoundaryDrawingPanel.getClientProperty("valueLabel");
 
+        // 淇敼瀵嗙爜璁剧疆椤�
+        JPanel changePasswordPanel = createChangePasswordPanel();
+
         JPanel feedbackPanel = createFeedbackPanel();
         
         // APP鐗堟湰
@@ -214,6 +219,7 @@
         addSettingItem(panel, boundaryLengthPanel, true);
         addSettingItem(panel, measurementModePanel, true);
         addSettingItem(panel, manualBoundaryDrawingPanel, true);
+        addSettingItem(panel, changePasswordPanel, true);
         addSettingItem(panel, feedbackPanel, true);
         addSettingItem(panel, appVersionPanel, true);
         addSettingItem(panel, logoutPanel, false);  // 鏈�鍚庝竴椤逛笉鍔犲垎鍓茬嚎
@@ -899,7 +905,7 @@
         }
         updateDisplay();
         // 鍔犺浇骞跺簲鐢ㄤ笂娆′繚瀛樼殑瑙嗗浘涓績鍧愭爣
-        loadViewCenterFromProperties();
+        // loadViewCenterFromProperties(); // 绉婚櫎姝よ皟鐢紝閬垮厤鎵撳紑璁剧疆椤甸潰鏃堕噸缃湴鍥捐鍥�
     }
     
     /**
@@ -1062,43 +1068,34 @@
         return trimmed;
     }
     
+    private void addActionListenerUnique(JButton button, ActionListener listener) {
+        if (button == null) return;
+        for (ActionListener al : button.getActionListeners()) {
+            button.removeActionListener(al);
+        }
+        button.addActionListener(listener);
+    }
+
     private void setupEventHandlers() {
         // 鍓茶崏鏈虹紪鍙风紪杈戞寜閽簨浠�
-        if (mowerIdEditBtn != null) {
-            mowerIdEditBtn.addActionListener(e -> editMowerId());
-        }
+        addActionListenerUnique(mowerIdEditBtn, e -> editMowerId());
 
         // 鍓茶崏鏈洪暱瀹界紪杈戞寜閽簨浠�
-        if (mowerSizeEditBtn != null) {
-            mowerSizeEditBtn.addActionListener(e -> editMowerSize());
-        }
+        addActionListenerUnique(mowerSizeEditBtn, e -> editMowerSize());
 
         // 鍓茶崏瀹夊叏璺濈缂栬緫鎸夐挳浜嬩欢
-        if (mowingSafetyDistanceEditBtn != null) {
-            mowingSafetyDistanceEditBtn.addActionListener(e -> editMowingSafetyDistance());
-        }
+        addActionListenerUnique(mowingSafetyDistanceEditBtn, e -> editMowingSafetyDistance());
 
-        if (baseStationIdEditBtn != null) {
-            baseStationIdEditBtn.addActionListener(e -> editBaseStationId());
-        }
+        addActionListenerUnique(baseStationIdEditBtn, e -> editBaseStationId());
         
         // 妫�鏌ユ洿鏂版寜閽簨浠�
-        if (checkUpdateBtn != null) {
-            checkUpdateBtn.addActionListener(e -> checkForUpdates());
-        }
+        addActionListenerUnique(checkUpdateBtn, e -> checkForUpdates());
 
-        if (handheldEditBtn != null) {
-            handheldEditBtn.addActionListener(e -> editHandheldMarkerId());
-        }
+        addActionListenerUnique(handheldEditBtn, e -> editHandheldMarkerId());
 
-        if (feedbackButton != null) {
-            feedbackButton.addActionListener(e -> showFeedbackDialog());
-        }
+        addActionListenerUnique(feedbackButton, e -> showFeedbackDialog());
 
-        if (idleTrailEditBtn != null) {
-            idleTrailEditBtn.addActionListener(e -> editIdleTrailDuration());
-        }
-        
+        addActionListenerUnique(idleTrailEditBtn, e -> editIdleTrailDuration());
     }
     
     private void editMowerId() {
@@ -1804,7 +1801,6 @@
     @Override
     public void setVisible(boolean visible) {
         if (visible) {
-            setupEventHandlers();
             loadData(); // 姣忔鏄剧ず鏃堕噸鏂板姞杞芥暟鎹�
         }
         super.setVisible(visible);
@@ -1860,4 +1856,57 @@
         
         return panel;
     }
+
+    /**
+     * 鍒涘缓淇敼瀵嗙爜璁剧疆闈㈡澘
+     */
+    private JPanel createChangePasswordPanel() {
+        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);
+
+        JLabel valueLabel = new JLabel("******");
+        valueLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+        valueLabel.setForeground(Color.DARK_GRAY);
+        gbc = new GridBagConstraints();
+        gbc.gridx = 1;
+        gbc.gridy = 0;
+        gbc.weightx = 1.0;
+        gbc.anchor = GridBagConstraints.EAST;
+        panel.add(valueLabel, gbc);
+
+        JButton editBtn = createEditButton();
+        editBtn.addActionListener(e -> {
+            SwingUtilities.invokeLater(() -> {
+                xiugaimima dialog = new xiugaimima((Frame) SwingUtilities.getWindowAncestor(this));
+                dialog.setVisible(true);
+            });
+        });
+        
+        gbc = new GridBagConstraints();
+        gbc.gridx = 2;
+        gbc.gridy = 0;
+        gbc.weightx = 0;
+        gbc.anchor = GridBagConstraints.EAST;
+        panel.add(editBtn, gbc);
+
+        return panel;
+    }
 }
\ No newline at end of file

--
Gitblit v1.10.0