| 1 | package be.nikiroo.utils.ui; |
| 2 | |
| 3 | import javax.swing.JComponent; |
| 4 | import javax.swing.JSpinner; |
| 5 | |
| 6 | import be.nikiroo.utils.resources.MetaInfo; |
| 7 | |
| 8 | class ConfigItemInteger<E extends Enum<E>> extends ConfigItem<E> { |
| 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) { |
| 33 | return info.getInteger(item, false); |
| 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) { |
| 46 | info.setInteger((Integer) value, item); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | protected JComponent createField(int item) { |
| 51 | return new JSpinner(); |
| 52 | } |
| 53 | } |