| 1 | package be.nikiroo.fanfix.reader.tui; |
| 2 | |
| 3 | import jexer.TField; |
| 4 | import jexer.TWidget; |
| 5 | import be.nikiroo.utils.resources.MetaInfo; |
| 6 | |
| 7 | class ConfigItemString<E extends Enum<E>> extends ConfigItem<E> { |
| 8 | /** |
| 9 | * Create a new {@link ConfigItemString} for the given {@link MetaInfo}. |
| 10 | * |
| 11 | * @param info |
| 12 | * the {@link MetaInfo} |
| 13 | */ |
| 14 | public ConfigItemString(TWidget parent, MetaInfo<E> info) { |
| 15 | super(parent, info, true); |
| 16 | } |
| 17 | |
| 18 | @Override |
| 19 | protected Object getFromField(int item) { |
| 20 | TField field = (TField) getField(item); |
| 21 | if (field != null) { |
| 22 | return field.getText(); |
| 23 | } |
| 24 | |
| 25 | return null; |
| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | protected Object getFromInfo(int item) { |
| 30 | return getInfo().getString(item, false); |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | protected void setToField(Object value, int item) { |
| 35 | TField field = (TField) getField(item); |
| 36 | if (field != null) { |
| 37 | field.setText(value == null ? "" : value.toString()); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | protected void setToInfo(Object value, int item) { |
| 43 | getInfo().setString((String) value, item); |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | protected TWidget createEmptyField(int item) { |
| 48 | return new TField(this, 0, 0, 1, false); |
| 49 | } |
| 50 | } |