Last change
on this file since 1 was 1, checked in by Wouter Pasman, 6 years ago |
Initial import : Genius 9.0.0
|
File size:
1.1 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 | public void setLock(boolean isLock) {
|
---|
41 | lock = isLock;
|
---|
42 | notifyChange(value);
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * @return true if the value is locked and can't be changed.
|
---|
47 | */
|
---|
48 | public boolean isLocked() {
|
---|
49 | return lock;
|
---|
50 | }
|
---|
51 |
|
---|
52 | public boolean getValue() {
|
---|
53 | return value;
|
---|
54 | }
|
---|
55 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.