Commit | Line | Data |
---|---|---|
d5026c09 NR |
1 | package be.nikiroo.utils.ui; |
2 | ||
3 | import javax.swing.JCheckBox; | |
4 | import javax.swing.JComponent; | |
5 | ||
6 | import be.nikiroo.utils.resources.MetaInfo; | |
7 | ||
8cea9dc5 | 8 | class ConfigItemBoolean<E extends Enum<E>> extends ConfigItem<E> { |
d5026c09 NR |
9 | private static final long serialVersionUID = 1L; |
10 | ||
11 | /** | |
12 | * Create a new {@link ConfigItemBoolean} for the given {@link MetaInfo}. | |
13 | * | |
14 | * @param info | |
15 | * the {@link MetaInfo} | |
16 | */ | |
17 | public ConfigItemBoolean(MetaInfo<E> info) { | |
18 | super(info, true); | |
19 | } | |
20 | ||
21 | @Override | |
22 | protected Object getFromField(int item) { | |
23 | JCheckBox field = (JCheckBox) getField(item); | |
24 | if (field != null) { | |
25 | return field.isSelected(); | |
26 | } | |
27 | ||
28 | return null; | |
29 | } | |
30 | ||
31 | @Override | |
32 | protected Object getFromInfo(int item) { | |
b5313d03 | 33 | return info.getBoolean(item, true); |
d5026c09 NR |
34 | } |
35 | ||
36 | @Override | |
37 | protected void setToField(Object value, int item) { | |
38 | JCheckBox field = (JCheckBox) getField(item); | |
39 | if (field != null) { | |
40 | // Should not happen if config enum is correct | |
41 | // (but this is not enforced) | |
42 | if (value == null) { | |
43 | value = false; | |
44 | } | |
45 | ||
46 | field.setSelected((Boolean) value); | |
47 | } | |
48 | } | |
49 | ||
50 | @Override | |
51 | protected void setToInfo(Object value, int item) { | |
52 | info.setBoolean((Boolean) value, item); | |
53 | } | |
54 | ||
55 | @Override | |
56 | protected JComponent createField(int item) { | |
57 | // Should not happen! | |
58 | if (getFromInfo(item) == null) { | |
59 | System.err | |
60 | .println("No default value given for BOOLEAN parameter \"" | |
61 | + info.getName() + "\", we consider it is FALSE"); | |
62 | } | |
63 | ||
64 | return new JCheckBox(); | |
65 | } | |
66 | } |