1 | package genius.gui.panels;
|
---|
2 |
|
---|
3 | import javax.swing.SpinnerNumberModel;
|
---|
4 | import javax.swing.event.ChangeEvent;
|
---|
5 | import javax.swing.event.ChangeListener;
|
---|
6 |
|
---|
7 | import genius.core.listener.DefaultListenable;
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * Model for {@link Integer} values. This improves type checking and also allows
|
---|
11 | * us to use it with sliders. Changes on the lock and on value are reported.
|
---|
12 | */
|
---|
13 | public class IntegerModel extends DefaultListenable<Integer>
|
---|
14 | implements Lockable {
|
---|
15 |
|
---|
16 | private SpinnerNumberModel spinmodel;
|
---|
17 | private boolean isLocked = false;
|
---|
18 |
|
---|
19 | public IntegerModel(Integer value, Integer minimum, Integer maximum,
|
---|
20 | Integer stepSize) {
|
---|
21 | spinmodel = new SpinnerNumberModel(value, minimum, maximum, stepSize);
|
---|
22 | spinmodel.addChangeListener(new ChangeListener() {
|
---|
23 | @Override
|
---|
24 | public void stateChanged(ChangeEvent e) {
|
---|
25 | notifyChange((Integer) spinmodel.getValue());
|
---|
26 | }
|
---|
27 | });
|
---|
28 | }
|
---|
29 |
|
---|
30 | @SuppressWarnings("unchecked")
|
---|
31 | public Integer getMinimum() {
|
---|
32 | return (Integer) spinmodel.getMinimum();
|
---|
33 | }
|
---|
34 |
|
---|
35 | @SuppressWarnings("unchecked")
|
---|
36 | public Integer getMaximum() {
|
---|
37 | return (Integer) spinmodel.getMaximum();
|
---|
38 | }
|
---|
39 |
|
---|
40 | public javax.swing.SpinnerModel getSpinnerModel() {
|
---|
41 | return spinmodel;
|
---|
42 | }
|
---|
43 |
|
---|
44 | @SuppressWarnings("unchecked")
|
---|
45 | public Integer getValue() {
|
---|
46 | return (Integer) spinmodel.getValue();
|
---|
47 | }
|
---|
48 |
|
---|
49 | public void setValue(Integer value) {
|
---|
50 | spinmodel.setValue(value);
|
---|
51 | }
|
---|
52 |
|
---|
53 | public void setMinimum(Integer newMinimum) {
|
---|
54 | spinmodel.setMinimum(newMinimum);
|
---|
55 | }
|
---|
56 |
|
---|
57 | public void setMaximum(Integer newMaximum) {
|
---|
58 | spinmodel.setMinimum(newMaximum);
|
---|
59 |
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Override
|
---|
63 | public void setLock(boolean isLock) {
|
---|
64 | this.isLocked = isLock;
|
---|
65 | notifyChange((Integer) spinmodel.getValue());
|
---|
66 | }
|
---|
67 |
|
---|
68 | @Override
|
---|
69 | public boolean isLocked() {
|
---|
70 | return isLocked;
|
---|
71 | }
|
---|
72 |
|
---|
73 | }
|
---|