source: src/main/java/genius/gui/panels/IntegerModel.java@ 346

Last change on this file since 346 was 93, checked in by Wouter Pasman, 6 years ago

#28 fixed listener structures. Added Lockable interface, boolean model and integer model are now lockable. Slider now reflects state of lockable. Added test for that.

File size: 1.7 KB
Line 
1package genius.gui.panels;
2
3import javax.swing.SpinnerNumberModel;
4import javax.swing.event.ChangeEvent;
5import javax.swing.event.ChangeListener;
6
7import 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 */
13public 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}
Note: See TracBrowser for help on using the repository browser.