package genius.gui.tree; import genius.core.listener.Listener; import genius.core.utility.UncertainAdditiveUtilitySpace; import genius.core.utility.UtilitySpace; import genius.gui.panels.BooleanModel; import genius.gui.panels.IntegerModel; /** * Holds the uncertainty settings (while editing a profile) */ public class UncertaintySettingsModel { private BooleanModel isEnabled; private IntegerModel comparisons; private IntegerModel errors; private BooleanModel isExperimental = new BooleanModel(false); private long totalBids; /** * @oaran space the {@link UtilitySpace} we're working with. This panel is * enabled by default iff the space is an * {@link UncertainAdditiveUtilitySpace}. If the space is * {@link UncertainAdditiveUtilitySpace} we also copy the default * values from there. Otherwise all default values are set to 0. */ public UncertaintySettingsModel(UtilitySpace space) { isEnabled = new BooleanModel( space instanceof UncertainAdditiveUtilitySpace); totalBids = space.getDomain().getNumberOfPossibleBids(); UncertainAdditiveUtilitySpace uspace = (space instanceof UncertainAdditiveUtilitySpace) ? (UncertainAdditiveUtilitySpace) space : null; comparisons = new IntegerModel( uspace != null ? uspace.getComparisons() : 0, 0, (int) totalBids, 1); errors = new IntegerModel(uspace != null ? uspace.getErrors() : 0, 0, (int) totalBids, 1); // copy enabledness -> lockedness of other components isEnabled.addListener(new Listener() { @Override public void notifyChange(Boolean enabled) { updateEnabledness(!enabled); } }); updateEnabledness(!isEnabled.getValue()); } public IntegerModel getComparisons() { return comparisons; } public IntegerModel getErrors() { return errors; } public BooleanModel getIsExperimental() { return isExperimental; } public BooleanModel getIsEnabled() { return isEnabled; } public long getTotalBids() { return totalBids; } private void updateEnabledness(boolean lock) { comparisons.setLock(lock); errors.setLock(lock); isExperimental.setLock(lock); } }