mmb.menu.components.CellRendererGettingCellRenderer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multimachinebuilder Show documentation
Show all versions of multimachinebuilder Show documentation
Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world.
THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<
/**
*
*/
package mmb.menu.components;
import java.awt.Color;
import java.awt.Component;
import java.util.function.Function;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
/**
* @author oskar
* A cell renderer which renders entries, whose have their own cell renderers
* @param type of data
*/
public class CellRendererGettingCellRenderer implements ListCellRenderer {
private final Function> getter;
public CellRendererGettingCellRenderer(Function> getter) {
this.getter = getter;
}
@Override
public Component getListCellRendererComponent(JList extends E> list, E value, int index, boolean isSelected,
boolean cellHasFocus) {
ListCellRenderer renderer = getter.apply(value);
Component c = renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if(isSelected) {
c.setBackground(list.getSelectionBackground());
c.setForeground(list.getSelectionForeground());
}else {
c.setBackground(new Color(204, 204, 204));
c.setForeground(list.getForeground());
}
return c;
}
}