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

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

#54 added GUI stuff for uncertainty seed. Not yet connected with actual code.

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 NumberModel extends DefaultListenable<Number> implements Lockable {
14
15 private SpinnerNumberModel spinmodel;
16 private boolean isLocked = false;
17
18 public NumberModel(Number value, Comparable minimum, Comparable maximum,
19 Number stepSize) {
20 spinmodel = new SpinnerNumberModel(value, minimum, maximum, stepSize);
21 spinmodel.addChangeListener(new ChangeListener() {
22 @Override
23 public void stateChanged(ChangeEvent e) {
24 notifyChange((Number) spinmodel.getValue());
25 }
26 });
27 }
28
29 @SuppressWarnings("unchecked")
30 public Number getMinimum() {
31 return (Number) spinmodel.getMinimum();
32 }
33
34 @SuppressWarnings("unchecked")
35 public Number getMaximum() {
36 return (Number) spinmodel.getMaximum();
37 }
38
39 public javax.swing.SpinnerModel getSpinnerModel() {
40 return spinmodel;
41 }
42
43 @SuppressWarnings("unchecked")
44 public Number getValue() {
45 return (Number) spinmodel.getValue();
46 }
47
48 public void setValue(Number value) {
49 spinmodel.setValue(value);
50 }
51
52 public void setMinimum(Comparable newMinimum) {
53 spinmodel.setMinimum(newMinimum);
54 }
55
56 public void setMaximum(Comparable newMaximum) {
57 spinmodel.setMinimum(newMaximum);
58
59 }
60
61 @Override
62 public void setLock(boolean isLock) {
63 this.isLocked = isLock;
64 notifyChange(((Number) spinmodel.getValue()));
65 }
66
67 @Override
68 public boolean isLocked() {
69 return isLocked;
70 }
71
72}
Note: See TracBrowser for help on using the repository browser.