Merge commit '5f3671e17febc5b7f6abbfc62c66c4045d47ec8d'
[fanfix.git] / ui / ConfigItemInteger.java
CommitLineData
d5026c09
NR
1package be.nikiroo.utils.ui;
2
3import javax.swing.JComponent;
4import javax.swing.JSpinner;
5
6import be.nikiroo.utils.resources.MetaInfo;
7
8cea9dc5 8class ConfigItemInteger<E extends Enum<E>> extends ConfigItem<E> {
d5026c09
NR
9 private static final long serialVersionUID = 1L;
10
11 /**
12 * Create a new {@link ConfigItemInteger} for the given {@link MetaInfo}.
13 *
14 * @param info
15 * the {@link MetaInfo}
16 */
17 public ConfigItemInteger(MetaInfo<E> info) {
18 super(info, true);
19 }
20
21 @Override
22 protected Object getFromField(int item) {
23 JSpinner field = (JSpinner) getField(item);
24 if (field != null) {
25 return field.getValue();
26 }
27
28 return null;
29 }
30
31 @Override
32 protected Object getFromInfo(int item) {
aa9c3626 33 return getInfo().getInteger(item, true);
d5026c09
NR
34 }
35
36 @Override
37 protected void setToField(Object value, int item) {
38 JSpinner field = (JSpinner) getField(item);
39 if (field != null) {
40 field.setValue(value == null ? 0 : (Integer) value);
41 }
42 }
43
44 @Override
45 protected void setToInfo(Object value, int item) {
aa9c3626 46 getInfo().setInteger((Integer) value, item);
d5026c09
NR
47 }
48
49 @Override
a0376372 50 protected JComponent createEmptyField(int item) {
d5026c09
NR
51 return new JSpinner();
52 }
53}