张世豪
2025-12-02 6799351be12deb2f713f2c0a2b4c467a6d1098c3
src/set/Sets.java
@@ -1,9 +1,12 @@
package set;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
 * 设置对话框 - 参考Shouye.java样式
@@ -21,12 +24,15 @@
    
    // 设置项组件
    private JLabel mowerIdLabel;
    private JLabel handheldMarkerLabel;
    private JLabel simCardNumberLabel;
    private JLabel firmwareVersionLabel;
    private JLabel appVersionLabel;
    
    private JButton mowerIdEditBtn;
    private JButton handheldEditBtn;
    private JButton checkUpdateBtn;
    private JButton feedbackButton;
    
    // 数据模型
    private Setsys setData;
@@ -87,6 +93,11 @@
        mowerIdLabel = (JLabel) mowerIdPanel.getClientProperty("valueLabel");
        mowerIdEditBtn = (JButton) mowerIdPanel.getClientProperty("editButton");
        
        JPanel handheldPanel = createSettingItemPanel("便携打点器编号",
            setData.getHandheldMarkerId() != null ? setData.getHandheldMarkerId() : "未设置", true);
        handheldMarkerLabel = (JLabel) handheldPanel.getClientProperty("valueLabel");
        handheldEditBtn = (JButton) handheldPanel.getClientProperty("editButton");
        // 物联卡号
        JPanel simCardPanel = createSettingItemPanel("物联卡号", 
            setData.getSimCardNumber() != null ? setData.getSimCardNumber() : "未设置", false);
@@ -96,13 +107,17 @@
        JPanel firmwarePanel = createSettingItemPanel("固件版本", 
            setData.getFirmwareVersion() != null ? setData.getFirmwareVersion() : "未设置", false);
        firmwareVersionLabel = (JLabel) firmwarePanel.getClientProperty("valueLabel");
        JPanel feedbackPanel = createFeedbackPanel();
        
        // APP版本
        JPanel appVersionPanel = createAppVersionPanel();
        
        addRowWithSpacing(panel, mowerIdPanel);
        addRowWithSpacing(panel, handheldPanel);
        addRowWithSpacing(panel, simCardPanel);
        addRowWithSpacing(panel, firmwarePanel);
        addRowWithSpacing(panel, feedbackPanel);
        panel.add(appVersionPanel);
        
        return panel;
@@ -226,6 +241,62 @@
        return panel;
    }
    private JPanel createFeedbackPanel() {
        JPanel panel = new JPanel(new GridBagLayout());
        panel.setBackground(PANEL_BACKGROUND);
        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));
        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);
        feedbackButton = new JButton("反馈");
        feedbackButton.setFont(new Font("微软雅黑", Font.PLAIN, 12));
        feedbackButton.setBackground(THEME_COLOR);
        feedbackButton.setForeground(Color.WHITE);
        feedbackButton.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 20));
        feedbackButton.setPreferredSize(new Dimension(100, 28));
        feedbackButton.setMinimumSize(new Dimension(100, 28));
        feedbackButton.setMaximumSize(new Dimension(100, 28));
        feedbackButton.setFocusPainted(false);
        feedbackButton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                feedbackButton.setBackground(new Color(
                        Math.max(THEME_COLOR.getRed() - 20, 0),
                        Math.max(THEME_COLOR.getGreen() - 20, 0),
                        Math.max(THEME_COLOR.getBlue() - 20, 0)));
            }
            @Override
            public void mouseExited(MouseEvent e) {
                feedbackButton.setBackground(THEME_COLOR);
            }
        });
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.anchor = GridBagConstraints.EAST;
        panel.add(feedbackButton, gbc);
        return panel;
    }
    
    private JButton createEditButton() {
        JButton button = new JButton();
@@ -270,6 +341,10 @@
        if (mowerIdLabel != null) {
            mowerIdLabel.setText(setData.getMowerId() != null ? setData.getMowerId() : "未设置");
        }
        if (handheldMarkerLabel != null) {
            handheldMarkerLabel.setText(setData.getHandheldMarkerId() != null ? setData.getHandheldMarkerId() : "未设置");
        }
        
        // 更新物联卡号显示
        if (simCardNumberLabel != null) {
@@ -300,6 +375,14 @@
        if (checkUpdateBtn != null) {
            checkUpdateBtn.addActionListener(e -> checkForUpdates());
        }
        if (handheldEditBtn != null) {
            handheldEditBtn.addActionListener(e -> editHandheldMarkerId());
        }
        if (feedbackButton != null) {
            feedbackButton.addActionListener(e -> showFeedbackDialog());
        }
        
    }
    
@@ -327,6 +410,183 @@
            }
        }
    }
    private void editHandheldMarkerId() {
        String currentValue = setData.getHandheldMarkerId() != null ? setData.getHandheldMarkerId() : "";
        String newValue = (String) JOptionPane.showInputDialog(this,
                "请输入便携打点器编号:",
                "修改便携打点器编号",
                JOptionPane.QUESTION_MESSAGE,
                null,
                null,
                currentValue);
        if (newValue == null) {
            return;
        }
        newValue = newValue.trim();
        if (!newValue.isEmpty()) {
            if (setData.updateProperty("handheldMarkerId", newValue)) {
                if (handheldMarkerLabel != null) {
                    handheldMarkerLabel.setText(newValue);
                }
                JOptionPane.showMessageDialog(this, "便携打点器编号更新成功", "成功", JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "便携打点器编号更新失败", "错误", JOptionPane.ERROR_MESSAGE);
            }
        }
    }
    private void showFeedbackDialog() {
    JDialog dialog = new JDialog(this, "问题反馈咨询", true);
    dialog.setLayout(new BorderLayout(0, 12));
    dialog.setResizable(false);
    dialog.setPreferredSize(new Dimension(400, 800));
    dialog.setSize(new Dimension(400, 800));
    dialog.setMinimumSize(new Dimension(400, 800));
    JPanel content = new JPanel();
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    content.setBorder(BorderFactory.createEmptyBorder(20, 24, 20, 24));
    dialog.add(content, BorderLayout.CENTER);
        JLabel descriptionLabel = new JLabel("问题描述:");
        descriptionLabel.setFont(new Font("微软雅黑", Font.BOLD, 13));
        descriptionLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        content.add(descriptionLabel);
        content.add(Box.createRigidArea(new Dimension(0, 8)));
        JTextArea descriptionArea = new JTextArea(5, 30);
        descriptionArea.setLineWrap(true);
        descriptionArea.setWrapStyleWord(true);
        descriptionArea.setFont(new Font("微软雅黑", Font.PLAIN, 13));
        JScrollPane scrollPane = new JScrollPane(descriptionArea);
        scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT);
        content.add(scrollPane);
        content.add(Box.createRigidArea(new Dimension(0, 16)));
        JPanel photoControls = new JPanel(new FlowLayout(FlowLayout.LEFT, 12, 0));
        photoControls.setAlignmentX(Component.LEFT_ALIGNMENT);
        JLabel photoLabel = new JLabel("选择照片(最多6张):");
        photoLabel.setFont(new Font("微软雅黑", Font.BOLD, 13));
        JButton selectPhotosButton = new JButton("选择照片");
        selectPhotosButton.setFont(new Font("微软雅黑", Font.PLAIN, 12));
        selectPhotosButton.setFocusPainted(false);
        photoControls.add(photoLabel);
        photoControls.add(selectPhotosButton);
    content.add(photoControls);
    content.add(Box.createRigidArea(new Dimension(0, 20)));
        JPanel photoGrid = new JPanel(new GridLayout(2, 3, 12, 12));
        photoGrid.setAlignmentX(Component.LEFT_ALIGNMENT);
        photoGrid.setMaximumSize(new Dimension(Integer.MAX_VALUE, 220));
        List<JLabel> photoSlots = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            JLabel slot = buildPhotoSlot();
            photoGrid.add(slot);
            photoSlots.add(slot);
        }
        content.add(photoGrid);
        content.add(Box.createRigidArea(new Dimension(0, 20)));
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        JButton cancelButton = new JButton("放弃");
        JButton submitButton = new JButton("提交");
        submitButton.setBackground(THEME_COLOR);
        submitButton.setForeground(Color.WHITE);
        submitButton.setFocusPainted(false);
        cancelButton.setFocusPainted(false);
        buttonPanel.add(cancelButton);
        buttonPanel.add(submitButton);
        dialog.add(buttonPanel, BorderLayout.SOUTH);
        List<File> selectedPhotos = new ArrayList<>();
        selectPhotosButton.addActionListener(e -> {
            JFileChooser chooser = new JFileChooser();
            chooser.setMultiSelectionEnabled(true);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            chooser.setFileFilter(new FileNameExtensionFilter("图片文件", "jpg", "jpeg", "png", "bmp", "gif", "webp"));
            if (chooser.showOpenDialog(dialog) == JFileChooser.APPROVE_OPTION) {
                File[] files = chooser.getSelectedFiles();
                if (files != null) {
                    if (selectedPhotos.size() >= 6) {
                        JOptionPane.showMessageDialog(dialog, "已达到6张照片上限", "提示", JOptionPane.WARNING_MESSAGE);
                        return;
                    }
                    for (File file : files) {
                        if (selectedPhotos.size() >= 6) {
                            break;
                        }
                        if (file != null && file.exists() && file.isFile()) {
                            selectedPhotos.add(file);
                        }
                    }
                    updatePhotoPreview(photoSlots, selectedPhotos);
                }
            }
        });
        cancelButton.addActionListener(e -> dialog.dispose());
        submitButton.addActionListener(e -> {
            String description = descriptionArea.getText() != null ? descriptionArea.getText().trim() : "";
            if (description.isEmpty()) {
                JOptionPane.showMessageDialog(dialog, "请填写问题描述", "提示", JOptionPane.WARNING_MESSAGE);
                descriptionArea.requestFocusInWindow();
                return;
            }
            // 提交逻辑占位
            JOptionPane.showMessageDialog(dialog,
                    "反馈已提交,感谢您的支持!\n描述字数:" + description.length() + ",照片数量:" + selectedPhotos.size(),
                    "提交成功",
                    JOptionPane.INFORMATION_MESSAGE);
            dialog.dispose();
        });
        dialog.pack();
        dialog.setLocationRelativeTo(this);
        dialog.setVisible(true);
    }
    private JLabel buildPhotoSlot() {
        JLabel slot = new JLabel();
        slot.setPreferredSize(new Dimension(100, 100));
        slot.setMinimumSize(new Dimension(100, 100));
        slot.setOpaque(true);
        slot.setBackground(new Color(245, 245, 245));
        slot.setHorizontalAlignment(SwingConstants.CENTER);
        slot.setVerticalAlignment(SwingConstants.CENTER);
        slot.setBorder(BorderFactory.createLineBorder(new Color(220, 220, 220), 1));
        slot.setText("+");
        slot.setFont(new Font("微软雅黑", Font.BOLD, 18));
        slot.setForeground(new Color(180, 180, 180));
        return slot;
    }
    private void updatePhotoPreview(List<JLabel> slots, List<File> photos) {
        for (int i = 0; i < slots.size(); i++) {
            JLabel slot = slots.get(i);
            if (i < photos.size()) {
                File photo = photos.get(i);
                ImageIcon icon = new ImageIcon(photo.getAbsolutePath());
                Image scaled = icon.getImage().getScaledInstance(100, 100, Image.SCALE_SMOOTH);
                slot.setIcon(new ImageIcon(scaled));
                slot.setText(null);
            } else {
                slot.setIcon(null);
                slot.setText("+");
            }
        }
    }
    
    private void checkForUpdates() {
        // 模拟检查更新过程