source: src/main/java/genius/gui/tree/UncertaintySettingsModel.java@ 126

Last change on this file since 126 was 95, checked in by Wouter Pasman, 6 years ago

#28 isLocked now reflected in GUI appearance of boolean and integer values.

File size: 2.1 KB
RevLine 
[83]1package genius.gui.tree;
2
[95]3import genius.core.listener.Listener;
[84]4import genius.core.utility.UncertainAdditiveUtilitySpace;
5import genius.core.utility.UtilitySpace;
[83]6import genius.gui.panels.BooleanModel;
[91]7import genius.gui.panels.IntegerModel;
[83]8
9/**
10 * Holds the uncertainty settings (while editing a profile)
11 */
12public class UncertaintySettingsModel {
[86]13 private BooleanModel isEnabled;
[91]14 private IntegerModel comparisons;
15 private IntegerModel errors;
[83]16 private BooleanModel isExperimental = new BooleanModel(false);
17 private long totalBids;
18
19 /**
[95]20 * @oaran space the {@link UtilitySpace} we're working with. This panel is
21 * enabled by default iff the space is an
22 * {@link UncertainAdditiveUtilitySpace}. If the space is
23 * {@link UncertainAdditiveUtilitySpace} we also copy the default
24 * values from there. Otherwise all default values are set to 0.
[83]25 */
[95]26 public UncertaintySettingsModel(UtilitySpace space) {
27 isEnabled = new BooleanModel(
28 space instanceof UncertainAdditiveUtilitySpace);
[84]29 totalBids = space.getDomain().getNumberOfPossibleBids();
30 UncertainAdditiveUtilitySpace uspace = (space instanceof UncertainAdditiveUtilitySpace)
31 ? (UncertainAdditiveUtilitySpace) space : null;
[91]32 comparisons = new IntegerModel(
[87]33 uspace != null ? uspace.getComparisons() : 0, 0,
34 (int) totalBids, 1);
[91]35 errors = new IntegerModel(uspace != null ? uspace.getErrors() : 0, 0,
[88]36 (int) totalBids, 1);
[95]37
38 // copy enabledness -> lockedness of other components
39 isEnabled.addListener(new Listener<Boolean>() {
40 @Override
41 public void notifyChange(Boolean enabled) {
42 updateEnabledness(!enabled);
43 }
44 });
45 updateEnabledness(!isEnabled.getValue());
[83]46 }
47
[91]48 public IntegerModel getComparisons() {
[83]49 return comparisons;
50 }
51
[91]52 public IntegerModel getErrors() {
[83]53 return errors;
54 }
55
56 public BooleanModel getIsExperimental() {
57 return isExperimental;
58 }
59
60 public BooleanModel getIsEnabled() {
61 return isEnabled;
62 }
63
64 public long getTotalBids() {
65 return totalBids;
66 }
67
[95]68 private void updateEnabledness(boolean lock) {
69 comparisons.setLock(lock);
70 errors.setLock(lock);
71 isExperimental.setLock(lock);
72 }
73
[83]74}
Note: See TracBrowser for help on using the repository browser.