package jetbrains.mps.ide.editor.util.renderer;
/*Generated by MPS */
import com.intellij.ui.ColoredListCellRenderer;
import javax.swing.JList;
import java.awt.Color;
import com.intellij.ui.SimpleTextAttributes;
import java.awt.Font;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nullable;
import javax.swing.Icon;
public abstract class BaseRenderer<T> extends ColoredListCellRenderer {
protected BaseRenderer() {
}
protected void customizeCellRenderer(JList list, Object value, int i, boolean index, boolean selected) {
T element = (T) value;
String name = getElementText(element);
Color color = list.getForeground();
SimpleTextAttributes nameAttributes = new SimpleTextAttributes(Font.PLAIN, color);
assert name != null : "Null name for PSI element " + element;
append(name, nameAttributes);
setIcon(getIcon(element));
String containerText = getContainerText(element, name);
if (containerText != null) {
append(" " + containerText, new SimpleTextAttributes(Font.PLAIN, Color.GRAY));
}
setPaintFocusBorder(false);
setBackground((selected ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground()));
}
protected abstract String getElementText(T element);
@Nullable
protected abstract String getContainerText(T element, final String name);
protected abstract Icon getIcon(T element);
}