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

Last change on this file since 148 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
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;
[139]8import genius.gui.panels.NumberModel;
[83]9
10/**
[139]11 * Holds the uncertainty settings (while editing a profile). This MVC model
12 * contains listenable fields and coordinates changes
[83]13 */
14public class UncertaintySettingsModel {
[130]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;
[139]20 private final NumberModel seed;
[83]21
22 /**
[95]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.
[83]28 */
[95]29 public UncertaintySettingsModel(UtilitySpace space) {
[130]30 final UncertainAdditiveUtilitySpace uspace = space instanceof UncertainAdditiveUtilitySpace
31 ? (UncertainAdditiveUtilitySpace) space
32 : null;
33
34 isEnabled = new BooleanModel(uspace != null);
35
[84]36 totalBids = space.getDomain().getNumberOfPossibleBids();
[130]37
38 isExperimental = new BooleanModel(
39 uspace != null ? uspace.isExperimental() : false);
40
[91]41 comparisons = new IntegerModel(
[87]42 uspace != null ? uspace.getComparisons() : 0, 0,
43 (int) totalBids, 1);
[130]44
[91]45 errors = new IntegerModel(uspace != null ? uspace.getErrors() : 0, 0,
[88]46 (int) totalBids, 1);
[95]47
[139]48 seed = new NumberModel(
49 uspace != null && uspace.getSeed() != null ? uspace.getSeed()
50 : 0l,
51 Long.MIN_VALUE, Long.MAX_VALUE, 1l);
52
[95]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());
[83]61 }
62
[91]63 public IntegerModel getComparisons() {
[83]64 return comparisons;
65 }
66
[91]67 public IntegerModel getErrors() {
[83]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
[95]83 private void updateEnabledness(boolean lock) {
84 comparisons.setLock(lock);
85 errors.setLock(lock);
86 isExperimental.setLock(lock);
[139]87 seed.setLock(lock);
[95]88 }
89
[139]90 public NumberModel getSeed() {
91 return seed;
92 }
93
[83]94}
Note: See TracBrowser for help on using the repository browser.