mmb.menu.world.window.WorldToolList 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.world.window;
import java.awt.Component;
import javax.swing.DefaultListModel;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.ListSelectionModel;
import mmb.NN;
import mmb.engine.debug.Debugger;
import mmb.menu.wtool.Tools;
import mmb.menu.wtool.WindowTool;
import monniasza.collects.Collects;
/**
* @author oskar
*
*/
public class WorldToolList extends JList {
private static final long serialVersionUID = -8108364897856379665L;
@NN public final DefaultListModel model = new DefaultListModel<>();
private static final Debugger debug = new Debugger("TOOL LIST");
private JPanel DUMMY = new JPanel();
public WorldToolList(ToolSelectionModel tsmodel, WorldWindow window) {
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
addListSelectionListener(e -> {
WindowTool tool = getSelectedValue();
if(window.toolEditorSplitPane != null) {
window.toolEditorSplitPane.setRightComponent(tool.GUI() == null?DUMMY:tool.GUI());
}
debug.printl("Tool selected: "+ tool.id);
tsmodel.toolSelectedToolList(tool);
});
Tools.createWindowTools(Collects.toWritableList(model), window);
setCellRenderer(new CellRenderer());
setModel(model);
}
private static class CellRenderer extends JLabel implements ListCellRenderer{
private static final long serialVersionUID = 1968960106003843654L;
public CellRenderer() {
setOpaque(true);
}
@Override
public Component getListCellRendererComponent(
@SuppressWarnings("null") JList extends WindowTool> list,
@SuppressWarnings("null") WindowTool tool,
int index,
boolean isSelected,
boolean hasFocus
){
setOpaque(true);
setIcon(tool.getIcon());
setText(tool.title());
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
return this;
}
}
}