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

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

#44 fixed

File size: 2.2 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)
11 */
12public class UncertaintySettingsModel {
13 private final BooleanModel isEnabled;
14 private final IntegerModel comparisons;
15 private final IntegerModel errors;
16 private final BooleanModel isExperimental;
17 private final long totalBids;
18
19 /**
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.
25 */
26 public UncertaintySettingsModel(UtilitySpace space) {
27 final UncertainAdditiveUtilitySpace uspace = space instanceof UncertainAdditiveUtilitySpace
28 ? (UncertainAdditiveUtilitySpace) space
29 : null;
30
31 isEnabled = new BooleanModel(uspace != null);
32
33 totalBids = space.getDomain().getNumberOfPossibleBids();
34
35 isExperimental = new BooleanModel(
36 uspace != null ? uspace.isExperimental() : false);
37
38 comparisons = new IntegerModel(
39 uspace != null ? uspace.getComparisons() : 0, 0,
40 (int) totalBids, 1);
41
42 errors = new IntegerModel(uspace != null ? uspace.getErrors() : 0, 0,
43 (int) totalBids, 1);
44
45 // copy enabledness -> lockedness of other components
46 isEnabled.addListener(new Listener<Boolean>() {
47 @Override
48 public void notifyChange(Boolean enabled) {
49 updateEnabledness(!enabled);
50 }
51 });
52 updateEnabledness(!isEnabled.getValue());
53 }
54
55 public IntegerModel getComparisons() {
56 return comparisons;
57 }
58
59 public IntegerModel getErrors() {
60 return errors;
61 }
62
63 public BooleanModel getIsExperimental() {
64 return isExperimental;
65 }
66
67 public BooleanModel getIsEnabled() {
68 return isEnabled;
69 }
70
71 public long getTotalBids() {
72 return totalBids;
73 }
74
75 private void updateEnabledness(boolean lock) {
76 comparisons.setLock(lock);
77 errors.setLock(lock);
78 isExperimental.setLock(lock);
79 }
80
81}
Note: See TracBrowser for help on using the repository browser.