张世豪
2025-12-11 6f59464fc6e12a525ba3004864eceb1bc1573a31
src/zhuye/LegendDialog.java
@@ -6,14 +6,13 @@
import java.awt.*;
public class LegendDialog extends JDialog {
    private final Color THEME_COLOR;
    public LegendDialog(Component parent, Color themeColor) {
        super(parent != null ? (JFrame) SwingUtilities.getWindowAncestor(parent) : null,
              "图例", true);
    this.THEME_COLOR = themeColor;
    // 使用统一对话框尺寸(6.5 寸竖屏)
    initializeDialog(UIConfig.DIALOG_WIDTH, UIConfig.DIALOG_HEIGHT);
    public LegendDialog(Component parent, Color ignoredThemeColor) {
      super(parent != null ? (JFrame) SwingUtilities.getWindowAncestor(parent) : null,
          "图例", true);
      int adjustedWidth = (int) Math.round(UIConfig.DIALOG_WIDTH * 0.8);
    int adjustedHeight = (int) Math.round(UIConfig.DIALOG_HEIGHT * 0.4);
    initializeDialog(adjustedWidth, adjustedHeight);
        initializeLegendContent();
        if (parent == null) {
            setLocationRelativeTo(null); // 居中显示
@@ -33,13 +32,6 @@
        mainPanel.setBackground(Color.WHITE);
        mainPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 10, 15));
        
        // 标题 - 修改为"图例"
        JLabel titleLabel = new JLabel("图例", JLabel.CENTER);
        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 14));
        titleLabel.setForeground(new Color(60, 60, 60));
        titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
        mainPanel.add(titleLabel, BorderLayout.NORTH);
        // 图例内容面板 - 直接添加,不使用滚动条
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
@@ -72,61 +64,6 @@
        // 直接添加内容面板,不使用滚动条
        mainPanel.add(contentPanel, BorderLayout.CENTER);
        
        // 底部按钮面板
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
        buttonPanel.setBackground(Color.WHITE);
        buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
        // 美化关闭按钮
        JButton closeButton = new JButton("关闭") {
            @Override
            protected void paintComponent(Graphics g) {
                Graphics2D g2 = (Graphics2D) g.create();
                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                // 绘制圆角矩形背景
                g2.setColor(THEME_COLOR);
                g2.fillRoundRect(0, 0, getWidth(), getHeight(), 15, 15);
                // 绘制边框
                g2.setColor(THEME_COLOR.darker());
                g2.setStroke(new BasicStroke(1.5f));
                g2.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 15, 15);
                // 绘制文字
                g2.setColor(Color.WHITE);
                g2.setFont(getFont());
                FontMetrics fm = g2.getFontMetrics();
                int x = (getWidth() - fm.stringWidth(getText())) / 2;
                int y = (getHeight() - fm.getHeight()) / 2 + fm.getAscent();
                g2.drawString(getText(), x, y);
                g2.dispose();
            }
        };
        closeButton.setFont(new Font("微软雅黑", Font.BOLD, 12));
        closeButton.setForeground(Color.WHITE);
        closeButton.setBackground(THEME_COLOR);
        closeButton.setFocusPainted(false);
        closeButton.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15));
        closeButton.setContentAreaFilled(false);
        closeButton.setPreferredSize(new Dimension(70, 28));
        closeButton.addActionListener(e -> dispose());
        // 添加鼠标悬停效果
        closeButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                closeButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                closeButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            }
        });
        buttonPanel.add(closeButton);
        mainPanel.add(buttonPanel, BorderLayout.SOUTH);
        getContentPane().add(mainPanel);
    }