debug
[fanfix.git] / src / be / nikiroo / utils / ui / ConfigItemString.java
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
8 class ConfigItemString<E extends Enum<E>> extends ConfigItem<E> {
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) {
33 return getInfo().getString(item, false);
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) {
46 getInfo().setString((String) value, item);
47 }
48
49 @Override
50 protected JComponent createEmptyField(int item) {
51 return new JTextField();
52 }
53 }