X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fui%2FConfigItemBoolean.java;fp=src%2Fbe%2Fnikiroo%2Futils%2Fui%2FConfigItemBoolean.java;h=255ec1338f442eaa2f4c5802e1d54a570a035ce9;hp=0000000000000000000000000000000000000000;hb=d46b7b96f94e88a776bcd2dfd756549ffb300cc9;hpb=c9994f27667bc421bcd448d39e55774fddf5c431 diff --git a/src/be/nikiroo/utils/ui/ConfigItemBoolean.java b/src/be/nikiroo/utils/ui/ConfigItemBoolean.java new file mode 100644 index 0000000..255ec13 --- /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; + +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, true); + } + + @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 createEmptyField(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(); + } +}