001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.conflict.pair;
003
004import java.awt.Component;
005
006import javax.swing.JLabel;
007import javax.swing.JList;
008import javax.swing.ListCellRenderer;
009
010import org.openstreetmap.josm.gui.conflict.ConflictColors;
011
012/**
013 * This {@link ListCellRenderer} renders the value of a {@link ComparePairType}
014 */
015public class ComparePairListCellRenderer extends JLabel implements ListCellRenderer<ComparePairType> {
016
017    /**
018     * Constructs a new {@code ComparePairListCellRenderer}.
019     */
020    public ComparePairListCellRenderer() {
021        setOpaque(true);
022    }
023
024    @Override
025    public Component getListCellRendererComponent(
026            JList<? extends ComparePairType> list,
027            ComparePairType value,
028            int index,
029            boolean isSelected,
030            boolean cellHasFocus) {
031        setText(value.getDisplayName());
032        setBackground(isSelected ? ConflictColors.BGCOLOR_SELECTED.get() : ConflictColors.BGCOLOR.get());
033        setForeground(ConflictColors.FGCOLOR.get());
034        return this;
035    }
036}