张世豪
2 天以前 f0d6cefec73492c29d8323e66fb92ee6bbb60cd2
src/set/Sets.java
@@ -17,6 +17,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import denglu.Denglu;
import denglu.UserChuShiHua;
/**
 * 设置对话框 - 参考Shouye.java样式
@@ -97,15 +99,24 @@
        // 创建设置项面板(圆角白色面板)
        JPanel settingsPanel = createSettingsPanel();
        
        // 创建滚动面板
        JScrollPane scrollPane = new JScrollPane(settingsPanel);
        scrollPane.setBorder(null); // 去除边框
        scrollPane.getViewport().setBackground(BACKGROUND_COLOR); // 设置视口背景色与主背景一致
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); // 禁止水平滚动
        scrollPane.getVerticalScrollBar().setUnitIncrement(16); // 增加滚动速度
        // 添加组件到主面板
        mainPanel.add(settingsPanel, BorderLayout.CENTER);
        mainPanel.add(scrollPane, BorderLayout.CENTER);
        
        add(mainPanel, BorderLayout.CENTER);
        setupEventHandlers();
    }
    
    private JPanel createSettingsPanel() {
        // 创建圆角白色面板容器
        JPanel container = new JPanel() {
        JPanel container = new ScrollablePanel() {
            @Override
            protected void paintComponent(Graphics g) {
                Graphics2D g2d = (Graphics2D) g.create();
@@ -184,11 +195,17 @@
        JPanel manualBoundaryDrawingPanel = createManualBoundaryDrawingPanel();
        manualBoundaryDrawingModeLabel = (JLabel) manualBoundaryDrawingPanel.getClientProperty("valueLabel");
        // 修改密码设置项
        JPanel changePasswordPanel = createChangePasswordPanel();
        JPanel feedbackPanel = createFeedbackPanel();
        
        // APP版本
        JPanel appVersionPanel = createAppVersionPanel();
        
        // 退出登录
        JPanel logoutPanel = createLogoutPanel();
        // 添加设置项,使用分割线分隔
        addSettingItem(panel, mowerIdPanel, true);
        addSettingItem(panel, mowerSizePanel, true);
@@ -202,8 +219,10 @@
        addSettingItem(panel, boundaryLengthPanel, true);
        addSettingItem(panel, measurementModePanel, true);
        addSettingItem(panel, manualBoundaryDrawingPanel, true);
        addSettingItem(panel, changePasswordPanel, true);
        addSettingItem(panel, feedbackPanel, true);
        addSettingItem(panel, appVersionPanel, false);  // 最后一项不加分割线
        addSettingItem(panel, appVersionPanel, true);
        addSettingItem(panel, logoutPanel, false);  // 最后一项不加分割线
        
        container.add(panel, BorderLayout.CENTER);
        return container;
@@ -886,7 +905,7 @@
        }
        updateDisplay();
        // 加载并应用上次保存的视图中心坐标
        loadViewCenterFromProperties();
        // loadViewCenterFromProperties(); // 移除此调用,避免打开设置页面时重置地图视图
    }
    
    /**
@@ -1049,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() {
@@ -1756,13 +1766,147 @@
        timer.start();
    }
    
    /**
     * 可滚动的面板,强制宽度适应视口
     */
    private class ScrollablePanel extends JPanel implements Scrollable {
        private static final long serialVersionUID = 1L;
        @Override
        public Dimension getPreferredScrollableViewportSize() {
            return getPreferredSize();
        }
        @Override
        public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
            return 16;
        }
        @Override
        public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
            return 16;
        }
        @Override
        public boolean getScrollableTracksViewportWidth() {
            return true; // 强制宽度适应视口,防止水平滚动
        }
        @Override
        public boolean getScrollableTracksViewportHeight() {
            return false;
        }
    }
    @Override
    public void setVisible(boolean visible) {
        if (visible) {
            setupEventHandlers();
            loadData(); // 每次显示时重新加载数据
        }
        super.setVisible(visible);
    }
    private JPanel createLogoutPanel() {
        JPanel panel = new JPanel(new GridBagLayout());
        panel.setOpaque(false);
        panel.setAlignmentX(Component.LEFT_ALIGNMENT);
        panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT + 20));
        panel.setBorder(BorderFactory.createEmptyBorder(ITEM_PADDING, ITEM_PADDING, ITEM_PADDING, ITEM_PADDING));
        JButton logoutBtn = new JButton("退出登录");
        logoutBtn.setFont(new Font("微软雅黑", Font.BOLD, 14));
        logoutBtn.setForeground(Color.WHITE);
        logoutBtn.setBackground(new Color(220, 53, 69)); // Red color
        logoutBtn.setFocusPainted(false);
        logoutBtn.setBorderPainted(false);
        logoutBtn.setCursor(new Cursor(Cursor.HAND_CURSOR));
        logoutBtn.setPreferredSize(new Dimension(200, 40));
        logoutBtn.addActionListener(e -> {
            int confirm = JOptionPane.showConfirmDialog(this,
                "确定要退出登录吗?", "退出确认",
                JOptionPane.YES_NO_OPTION);
            if (confirm == JOptionPane.YES_OPTION) {
                // Reset Remember Me
                UserChuShiHua.updateProperty("rememberPassword", "0");
                // Close current dialog
                dispose();
                // Close all windows and open Login
                for (Window window : Window.getWindows()) {
                    if (window.isDisplayable()) {
                        window.dispose();
                    }
                }
                SwingUtilities.invokeLater(() -> {
                    new Denglu().setVisible(true);
                });
            }
        });
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.anchor = GridBagConstraints.CENTER;
        panel.add(logoutBtn, gbc);
        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;
    }
}