From 9cc3f77b412d86229861ed54a0d95027996099e4 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 23 May 2019 10:02:37 +0200 Subject: [PATCH] fix ConfigItem NPE and ConfigEditor Save/Reset/Defaults --- src/be/nikiroo/utils/ui/ConfigEditor.java | 10 +++++++--- src/be/nikiroo/utils/ui/ConfigItem.java | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/be/nikiroo/utils/ui/ConfigEditor.java b/src/be/nikiroo/utils/ui/ConfigEditor.java index ca85f61..45a534e 100644 --- a/src/be/nikiroo/utils/ui/ConfigEditor.java +++ b/src/be/nikiroo/utils/ui/ConfigEditor.java @@ -5,6 +5,7 @@ import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import javax.swing.BoxLayout; @@ -57,11 +58,13 @@ public class ConfigEditor> extends JPanel { main.setLayout(new BoxLayout(main, BoxLayout.PAGE_AXIS)); main.setBorder(new EmptyBorder(5, 5, 5, 5)); - + main.add(new JLabel(title)); - items = MetaInfo.getItems(type, bundle); - for (MetaInfo item : items) { + items = new ArrayList>(); + List> groupedItems = MetaInfo.getItems(type, bundle); + for (MetaInfo item : groupedItems) { + // will init this.items addItem(main, item, 0); } @@ -129,6 +132,7 @@ public class ConfigEditor> extends JPanel { bpane.add(pane, BorderLayout.CENTER); main.add(bpane); } else { + items.add(item); main.add(new ConfigItem(item, nhgap)); } } diff --git a/src/be/nikiroo/utils/ui/ConfigItem.java b/src/be/nikiroo/utils/ui/ConfigItem.java index 4633370..04bf76c 100644 --- a/src/be/nikiroo/utils/ui/ConfigItem.java +++ b/src/be/nikiroo/utils/ui/ConfigItem.java @@ -348,7 +348,8 @@ public class ConfigItem> extends JPanel { info.addSaveListener(new Runnable() { @Override public void run() { - String value = field.getSelectedItem().toString(); + Object item = field.getSelectedItem(); + String value = item == null ? null : item.toString(); if (isChanged(value)) { info.setString(value); } -- 2.27.0