package cn.net.connor.std.processedit.util;


import javax.swing.*;
import java.awt.*;

public class TwoColumnRenderer implements ListCellRenderer<OptionItem> {

    private final JLabel label = new JLabel();

    @Override
    public Component getListCellRendererComponent(
            JList<? extends OptionItem> list,
            OptionItem value,
            int index,
            boolean isSelected,
            boolean cellHasFocus) {

        // 设置背景（必须）
        if (isSelected) {
            label.setBackground(list.getSelectionBackground());
        } else {
            label.setBackground(list.getBackground());
        }
        label.setOpaque(true);
        label.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5));

        // 构建 HTML 内容（完全控制颜色，不依赖 setForeground）
        if (value == null) {
            label.setText("<html><i><font color='#888888'>请选择...</font></i></html>");
        } else {
            String html = String.format(
                "<html><b>%s</b>&nbsp;&nbsp;<font color='#888888'>%s</font></html>",
                value.getValue(),
                value.getDescription()
            );
            label.setText(html);
        }


        return label;
    }
}