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

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

#54 added GUI stuff for uncertainty seed. Not yet connected with actual code.

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