Commit | Line | Data |
---|---|---|
d5026c09 NR |
1 | package be.nikiroo.utils.ui; |
2 | ||
3 | import javax.swing.JComponent; | |
4 | import javax.swing.JTextField; | |
5 | ||
6 | import be.nikiroo.utils.resources.MetaInfo; | |
7 | ||
8cea9dc5 | 8 | class ConfigItemString<E extends Enum<E>> extends ConfigItem<E> { |
d5026c09 NR |
9 | private static final long serialVersionUID = 1L; |
10 | ||
11 | /** | |
12 | * Create a new {@link ConfigItemString} for the given {@link MetaInfo}. | |
13 | * | |
14 | * @param info | |
15 | * the {@link MetaInfo} | |
16 | */ | |
17 | public ConfigItemString(MetaInfo<E> info) { | |
18 | super(info, true); | |
19 | } | |
20 | ||
21 | @Override | |
22 | protected Object getFromField(int item) { | |
23 | JTextField field = (JTextField) getField(item); | |
24 | if (field != null) { | |
25 | return field.getText(); | |
26 | } | |
27 | ||
28 | return null; | |
29 | } | |
30 | ||
31 | @Override | |
32 | protected Object getFromInfo(int item) { | |
28a82bab | 33 | return getInfo().getString(item, false); |
d5026c09 NR |
34 | } |
35 | ||
36 | @Override | |
37 | protected void setToField(Object value, int item) { | |
38 | JTextField field = (JTextField) getField(item); | |
39 | if (field != null) { | |
40 | field.setText(value == null ? "" : value.toString()); | |
41 | } | |
42 | } | |
43 | ||
44 | @Override | |
45 | protected void setToInfo(Object value, int item) { | |
28a82bab | 46 | getInfo().setString((String) value, item); |
d5026c09 | 47 | } |
8cea9dc5 | 48 | |
d5026c09 | 49 | @Override |
a0376372 | 50 | protected JComponent createEmptyField(int item) { |
d5026c09 NR |
51 | return new JTextField(); |
52 | } | |
53 | } |