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

Last change on this file since 155 was 155, checked in by Tim Baarslag, 6 years ago

Fixed refactor TODO of createExperimentalOutcomeComparisonUserModel

Made fixed seed a checkbox

User guide fixes

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