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

mmb.menu.components.BoundCombo 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.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;
		});
	}	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy