Last change
on this file since 84 was 83, checked in by Wouter Pasman, 6 years ago |
#28 added first version of uncertainty panel. Not yet attached to save
|
File size:
1.2 KB
|
Line | |
---|
1 | package genius.gui.panels;
|
---|
2 |
|
---|
3 | import genius.core.listener.DefaultListenable;
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * Stores a listen-able boolean value. Listeners always hear the current value,
|
---|
7 | * not the lock setting.
|
---|
8 | *
|
---|
9 | */
|
---|
10 | public class BooleanModel extends DefaultListenable<Boolean> {
|
---|
11 | private boolean value = false;
|
---|
12 | private boolean lock = false;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | *
|
---|
16 | * @param b
|
---|
17 | * the initial value for the boolean
|
---|
18 | */
|
---|
19 | public BooleanModel(boolean b) {
|
---|
20 | this.value = b;
|
---|
21 | }
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * @param newValue
|
---|
25 | * the new value. Check {@link #isLocked()} before attempting
|
---|
26 | * this
|
---|
27 | * @throws IllegalStateException
|
---|
28 | * if object is locked.
|
---|
29 | */
|
---|
30 | public void setValue(boolean newValue) {
|
---|
31 | if (lock) {
|
---|
32 | throw new IllegalStateException("Value is locked");
|
---|
33 | }
|
---|
34 | if (value != newValue) {
|
---|
35 | value = newValue;
|
---|
36 | notifyChange(value);
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | *
|
---|
42 | * @param isLock
|
---|
43 | * if true, the value can not be changed. The GUI should also
|
---|
44 | * reflect this setting eg by greying out the item.
|
---|
45 | */
|
---|
46 | public void setLock(boolean isLock) {
|
---|
47 | lock = isLock;
|
---|
48 | notifyChange(value);
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * @return true if the value is locked and can't be changed.
|
---|
53 | */
|
---|
54 | public boolean isLocked() {
|
---|
55 | return lock;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public boolean getValue() {
|
---|
59 | return value;
|
---|
60 | }
|
---|
61 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.