1 | package genius.gui.panels;
|
---|
2 |
|
---|
3 | import javax.swing.SpinnerNumberModel;
|
---|
4 | import javax.swing.event.ChangeListener;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * Just like SpinnerModel but ensures that it works with numbers of type N. This
|
---|
8 | * improves type checking. Useful when you get something out of the model....
|
---|
9 | *
|
---|
10 | * @param N
|
---|
11 | * the type of the numbers in the model, the number must also
|
---|
12 | * implement Comparable.
|
---|
13 | */
|
---|
14 | public class SpinnerModel<N extends Number> {
|
---|
15 |
|
---|
16 | private SpinnerNumberModel spinmodel;
|
---|
17 |
|
---|
18 | public SpinnerModel(N value, N minimum, N maximum, N stepSize) {
|
---|
19 | spinmodel = new SpinnerNumberModel(value, (Comparable) minimum,
|
---|
20 | (Comparable) maximum, stepSize);
|
---|
21 | }
|
---|
22 |
|
---|
23 | @SuppressWarnings("unchecked")
|
---|
24 | public N getMinimum() {
|
---|
25 | return (N) spinmodel.getMinimum();
|
---|
26 | }
|
---|
27 |
|
---|
28 | @SuppressWarnings("unchecked")
|
---|
29 | public N getMaximum() {
|
---|
30 | return (N) spinmodel.getMaximum();
|
---|
31 | }
|
---|
32 |
|
---|
33 | public javax.swing.SpinnerModel getSpinnerModel() {
|
---|
34 | return spinmodel;
|
---|
35 | }
|
---|
36 |
|
---|
37 | @SuppressWarnings("unchecked")
|
---|
38 | public N getValue() {
|
---|
39 | return (N) spinmodel.getValue();
|
---|
40 | }
|
---|
41 |
|
---|
42 | public void setValue(N value) {
|
---|
43 | spinmodel.setValue(value);
|
---|
44 | }
|
---|
45 |
|
---|
46 | public void addChangeListener(ChangeListener changeListener) {
|
---|
47 | spinmodel.addChangeListener(changeListener);
|
---|
48 | }
|
---|
49 |
|
---|
50 | }
|
---|