mmb.menu.components.BoundCombo 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<
/**
*
*/
package mmb.menu.components;
import java.util.function.Consumer;
import javax.swing.JComboBox;
import mmb.NN;
import mmb.Nil;
import mmb.data.variables.ListenableValue;
/**
* @author oskar
*
*/
public class BoundCombo extends JComboBox {
private static final long serialVersionUID = -3081047509881544718L;
private transient ListenableValue bvar;
@NN private transient Consumer update = this::setSelectedItem;
private boolean valueChangeUnderway = false;
public void setVariable(@Nil ListenableValue var) {
if(var != null) setSelectedItem(var.get());
if(bvar != null) bvar.unlistenadd(update);
bvar = var;
if(bvar != null) bvar.listenadd(update);
}
public BoundCombo() {
super();
addActionListener(e -> {
if(valueChangeUnderway) return;
valueChangeUnderway = true;
if(bvar != null) bvar.set((E) getSelectedItem());
valueChangeUnderway = false;
});
}
}