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