All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mmb.menu.components.CellRendererGettingCellRenderer Maven / Gradle / Ivy

Go to download

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<

There is a newer version: 0.6
Show 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;

/**
 * @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 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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy