X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fui%2FConfigItem.java;h=3780a7e21058a1c9a80475ce8932112aa350e039;hb=8517b60cb3dfc64f7cec0c4da8d5003837e82bb2;hp=beed66f55f9de312998924c0e85c06f01344a45c;hpb=9e834013f84e8797acf26f5418ae3448044ad097;p=fanfix.git diff --git a/src/be/nikiroo/utils/ui/ConfigItem.java b/src/be/nikiroo/utils/ui/ConfigItem.java index beed66f..3780a7e 100644 --- a/src/be/nikiroo/utils/ui/ConfigItem.java +++ b/src/be/nikiroo/utils/ui/ConfigItem.java @@ -3,9 +3,9 @@ package be.nikiroo.utils.ui; import java.awt.BorderLayout; import javax.swing.JCheckBox; +import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.border.EmptyBorder; import be.nikiroo.utils.resources.Bundle; import be.nikiroo.utils.resources.Meta.Format; @@ -25,7 +25,7 @@ public class ConfigItem> extends JPanel { public ConfigItem(final MetaInfo info) { this.setLayout(new BorderLayout()); - this.setBorder(new EmptyBorder(2, 10, 2, 10)); + // this.setBorder(new EmptyBorder(2, 10, 2, 10)); if (info.getFormat() == Format.BOOLEAN) { final JCheckBox field = new JCheckBox(); @@ -38,33 +38,56 @@ public class ConfigItem> extends JPanel { // Should not happen! if (state == null) { System.err - .println("No default value given for BOOLEAN parameter " - + info.getName() + ", we consider it is FALSE"); + .println("No default value given for BOOLEAN parameter \"" + + info.getName() + + "\", we consider it is FALSE"); state = false; } field.setSelected(state); - info.addReloadListener(new Runnable() { + info.addReloadedListener(new Runnable() { @Override public void run() { - field.setText(info.getString()); + Boolean state = info.getBoolean(); + if (state == null) { + info.getDefaultBoolean(); + } + if (state == null) { + state = false; + } + + field.setSelected(state); + } + }); + info.addSaveListener(new Runnable() { + @Override + public void run() { + info.setBoolean(field.isSelected()); } }); + this.add(new JLabel(info.getName() + ": "), BorderLayout.WEST); this.add(field, BorderLayout.CENTER); } else { final JTextField field = new JTextField(); field.setToolTipText(info.getDescription()); field.setText(info.getString()); - info.addReloadListener(new Runnable() { + info.addReloadedListener(new Runnable() { @Override public void run() { field.setText(info.getString()); } }); + info.addSaveListener(new Runnable() { + @Override + public void run() { + info.setString(field.getText()); + } + }); + this.add(new JLabel(info.getName() + ": "), BorderLayout.WEST); this.add(field, BorderLayout.CENTER); } }