
mmb.engine.recipe.RecipeList Maven / Gradle / Ivy
/**
*
*/
package mmb.engine.recipe;
import javax.swing.JScrollPane;
import javax.swing.ListCellRenderer;
import mmb.NN;
import mmb.Nil;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JList;
/**
* Represents a recipe list for almost anything (but not pickaxes)
* @author oskar
* @param type of the recipes
* @param type of the recipe group
*/
public class RecipeList, G extends RecipeGroup> extends JScrollPane {
private static final long serialVersionUID = 828762086772542204L;
private final RecipeView rv;
/**
* Creates a recipe list for almost anything (but not pickaxes)
* @param group recipe group used for this list
* */
public RecipeList(G group) {
rv = group.createView();
JList> list = new JList<>();
@SuppressWarnings("unchecked")
RecipeEntry[] data = new RecipeEntry[group.recipes().size()];
int i = 0;
for(T recipe: group.recipes()) {
data[i] = new RecipeEntry<>(recipe);
i++;
}
list.setListData(data);
list.setCellRenderer(new CellRenderer());
setViewportView(list);
}
static class RecipeEntry>{
@NN public final T recipe;
@NN public final ItemStack[] stack;
public RecipeEntry(T recipe2) {
this.recipe = recipe2;
stack = VectorUtils.list2arr(recipe2.output());
}
}
class CellRenderer implements ListCellRenderer>{
public CellRenderer() {
setPreferredSize(new Dimension(600, 200));
}
@Override
public Component getListCellRendererComponent(
@SuppressWarnings("null") JList extends RecipeEntry> list,
@Nil RecipeEntry value, int index,
boolean isSelected, boolean cellHasFocus) {
if(value != null) rv.set(value.recipe);
return rv;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy