/*
 * MIT License
 *
 * Copyright (c) 2020 Jannis Weis
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */
package com.github.weisj.darklaf.components.renderer;

import java.awt.*;
import java.util.function.Function;

import javax.swing.*;
import javax.swing.border.Border;

public class SimpleListCellRenderer<T> extends JLabel implements ListCellRenderer<T> {

    public static <T> SimpleListCellRenderer<T> create(final Function<? super T, String> toText) {
        return new SimpleListCellRenderer<T>() {
            @Override
            protected void customize(final T value) {
                setText(toText.apply(value));
            }
        };
    }

    @Override
    public Component getListCellRendererComponent(final JList<? extends T> list, final T value, final int index,
            final boolean isSelected, final boolean cellHasFocus) {
        setComponentOrientation(list.getComponentOrientation());

        customize(value);

        setEnabled(list.isEnabled());
        setFont(list.getFont());

        Border border = null;
        if (cellHasFocus) {
            if (isSelected) {
                border = UIManager.getBorder("List.focusSelectedCellHighlightBorder");
            }
            if (border == null) {
                border = UIManager.getBorder("List.focusCellHighlightBorder");
            }
        } else {
            border = UIManager.getBorder("List.cellNoFocusBorder");
        }
        setBorder(border);

        return this;
    }

    protected void customize(final T value) {
        if (value instanceof Icon) {
            setIcon((Icon) value);
            setText("");
        } else {
            setIcon(null);
            setText((value == null) ? "" : value.toString());
        }
    }
}

@@ -1191,24 +1191,62 @@
 java.awt.*;%0A
+import java.util.function.BiConsumer;%0A
 import java.
@@ -1713,24 +1713,324 @@
   %7D;%0A    %7D%0A%0A
+    public static %3CT%3E SimpleListCellRenderer%3CT%3E create(final BiConsumer%3CJLabel, T%3E customize) %7B%0A        return new SimpleListCellRenderer%3CT%3E() %7B%0A            @Override%0A            protected void customize(final T value) %7B%0A                customize.accept(this, value);%0A            %7D%0A        %7D;%0A    %7D%0A%0A
     @Overrid

Add more general factory method for SimpleListCellRenderer.