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

Last change on this file 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
RevLine 
[87]1package genius.gui.panels;
2
3import javax.swing.SpinnerNumberModel;
[93]4import javax.swing.event.ChangeEvent;
[87]5import javax.swing.event.ChangeListener;
6
[93]7import genius.core.listener.DefaultListenable;
8
[87]9/**
[91]10 * Model for {@link Integer} values. This improves type checking and also allows
[93]11 * us to use it with sliders. Changes on the lock and on value are reported.
[87]12 */
[93]13public class IntegerModel extends DefaultListenable<Integer>
14 implements Lockable {
[87]15
16 private SpinnerNumberModel spinmodel;
[93]17 private boolean isLocked = false;
[87]18
[91]19 public IntegerModel(Integer value, Integer minimum, Integer maximum,
[88]20 Integer stepSize) {
21 spinmodel = new SpinnerNumberModel(value, minimum, maximum, stepSize);
[93]22 spinmodel.addChangeListener(new ChangeListener() {
23 @Override
24 public void stateChanged(ChangeEvent e) {
25 notifyChange((Integer) spinmodel.getValue());
26 }
27 });
[87]28 }
29
30 @SuppressWarnings("unchecked")
[88]31 public Integer getMinimum() {
32 return (Integer) spinmodel.getMinimum();
[87]33 }
34
35 @SuppressWarnings("unchecked")
[88]36 public Integer getMaximum() {
37 return (Integer) spinmodel.getMaximum();
[87]38 }
39
40 public javax.swing.SpinnerModel getSpinnerModel() {
41 return spinmodel;
42 }
43
44 @SuppressWarnings("unchecked")
[88]45 public Integer getValue() {
46 return (Integer) spinmodel.getValue();
[87]47 }
48
[88]49 public void setValue(Integer value) {
[87]50 spinmodel.setValue(value);
51 }
52
[88]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
[93]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
[87]73}
Note: See TracBrowser for help on using the repository browser.