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

mmb.menu.world.craft.ItemStackCellRenderer 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.world.craft;

import java.awt.Component;
import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import mmb.engine.inv.ItemStack;

public class ItemStackCellRenderer extends JLabel implements ListCellRenderer{
	public static final ItemStackCellRenderer instance = new ItemStackCellRenderer();
	private static final long serialVersionUID = -3535344904857285958L;
	private static final Dimension PRESENT = new Dimension(275, 32);
	private static final Dimension ABSENT = new Dimension();
	@Override
	public Component getListCellRendererComponent(
		@SuppressWarnings("null") JList list,
		@SuppressWarnings("null") ItemStack itemType,
		int index,
		boolean isSelected,
		boolean cellHasFocus
	){
		if(itemType.amount == 0) {
			setPreferredSize(ABSENT);
			setMinimumSize(ABSENT);
		}else {
			setPreferredSize(PRESENT);
			setMinimumSize(PRESENT);
		}
		setOpaque(true);
		setIcon(itemType.item.icon());
		setText(itemType.id().title() + " � " + itemType.amount);
		
		if (isSelected) {
		    setBackground(list.getSelectionBackground());
		    setForeground(list.getSelectionForeground());
		} else {
		    setBackground(list.getBackground());
		    setForeground(list.getForeground());
		}
		return this;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy