X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fui%2FConfigItemBoolean.java;fp=src%2Fbe%2Fnikiroo%2Futils%2Fui%2FConfigItemBoolean.java;h=be7ff20ea1f810c613412810ec6a09e29deeea6c;hb=d5026c096121da14c20d69893520594a36d088bb;hp=0000000000000000000000000000000000000000;hpb=59654e2ab1f6d3314eff438bf9e30ed6f32e5e74;p=fanfix.git diff --git a/src/be/nikiroo/utils/ui/ConfigItemBoolean.java b/src/be/nikiroo/utils/ui/ConfigItemBoolean.java new file mode 100644 index 0000000..be7ff20 --- /dev/null +++ b/src/be/nikiroo/utils/ui/ConfigItemBoolean.java @@ -0,0 +1,66 @@ +package be.nikiroo.utils.ui; + +import javax.swing.JCheckBox; +import javax.swing.JComponent; + +import be.nikiroo.utils.resources.MetaInfo; + +public class ConfigItemBoolean> extends ConfigItem { + private static final long serialVersionUID = 1L; + + /** + * Create a new {@link ConfigItemBoolean} for the given {@link MetaInfo}. + * + * @param info + * the {@link MetaInfo} + */ + public ConfigItemBoolean(MetaInfo info) { + super(info, true); + } + + @Override + protected Object getFromField(int item) { + JCheckBox field = (JCheckBox) getField(item); + if (field != null) { + return field.isSelected(); + } + + return null; + } + + @Override + protected Object getFromInfo(int item) { + return info.getBoolean(item, false); + } + + @Override + protected void setToField(Object value, int item) { + JCheckBox field = (JCheckBox) getField(item); + if (field != null) { + // Should not happen if config enum is correct + // (but this is not enforced) + if (value == null) { + value = false; + } + + field.setSelected((Boolean) value); + } + } + + @Override + protected void setToInfo(Object value, int item) { + info.setBoolean((Boolean) value, item); + } + + @Override + protected JComponent createField(int item) { + // Should not happen! + if (getFromInfo(item) == null) { + System.err + .println("No default value given for BOOLEAN parameter \"" + + info.getName() + "\", we consider it is FALSE"); + } + + return new JCheckBox(); + } +}