Bundle: fix memory leak at init/reset
[fanfix.git] / ui / ConfigItemBoolean.java
CommitLineData
d5026c09
NR
1package be.nikiroo.utils.ui;
2
3import javax.swing.JCheckBox;
4import javax.swing.JComponent;
5
6import be.nikiroo.utils.resources.MetaInfo;
7
8cea9dc5 8class 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) {
aa9c3626 33 return getInfo().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) {
aa9c3626 52 getInfo().setBoolean((Boolean) value, item);
d5026c09
NR
53 }
54
55 @Override
a0376372 56 protected JComponent createEmptyField(int item) {
d5026c09
NR
57 // Should not happen!
58 if (getFromInfo(item) == null) {
59 System.err
60 .println("No default value given for BOOLEAN parameter \""
aa9c3626
NR
61 + getInfo().getName()
62 + "\", we consider it is FALSE");
d5026c09
NR
63 }
64
65 return new JCheckBox();
66 }
67}