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

Last change on this file since 127 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
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 BooleanModel isEnabled;
14 private IntegerModel comparisons;
15 private IntegerModel errors;
16 private BooleanModel isExperimental = new BooleanModel(false);
17 private 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 isEnabled = new BooleanModel(
28 space instanceof UncertainAdditiveUtilitySpace);
29 totalBids = space.getDomain().getNumberOfPossibleBids();
30 UncertainAdditiveUtilitySpace uspace = (space instanceof UncertainAdditiveUtilitySpace)
31 ? (UncertainAdditiveUtilitySpace) space : null;
32 comparisons = new IntegerModel(
33 uspace != null ? uspace.getComparisons() : 0, 0,
34 (int) totalBids, 1);
35 errors = new IntegerModel(uspace != null ? uspace.getErrors() : 0, 0,
36 (int) totalBids, 1);
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());
46 }
47
48 public IntegerModel getComparisons() {
49 return comparisons;
50 }
51
52 public IntegerModel getErrors() {
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
68 private void updateEnabledness(boolean lock) {
69 comparisons.setLock(lock);
70 errors.setLock(lock);
71 isExperimental.setLock(lock);
72 }
73
74}
Note: See TracBrowser for help on using the repository browser.