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<
The newest version!
/**
*
*/
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;
/**
* A cell renderer which gets the required cell renderer and uses it to actually render a cell
* @author oskar
*
* @param type of data
*/
public class CellRendererGettingCellRenderer implements ListCellRenderer {
private final Function> getter;
/**
* Creates a cell renderer
* @param getter function to extract cell renderers
*/
public CellRendererGettingCellRenderer(Function> getter) {
this.getter = getter;
}
@Override
public Component getListCellRendererComponent(@SuppressWarnings("null") 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;
}
}