fix ConfigItem NPE and ConfigEditor Save/Reset/Defaults
authorNiki Roo <niki@nikiroo.be>
Thu, 23 May 2019 08:02:37 +0000 (10:02 +0200)
committerNiki Roo <niki@nikiroo.be>
Thu, 23 May 2019 08:02:37 +0000 (10:02 +0200)
src/be/nikiroo/utils/ui/ConfigEditor.java
src/be/nikiroo/utils/ui/ConfigItem.java

index ca85f6161fdbd7db238a71a3872f59569564d797..45a534ea0c1c576d02e76e71fc5d32cbe04ff270 100644 (file)
@@ -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<E extends Enum<E>> 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<E> item : items) {
+               items = new ArrayList<MetaInfo<E>>();
+               List<MetaInfo<E>> groupedItems = MetaInfo.getItems(type, bundle);
+               for (MetaInfo<E> item : groupedItems) {
+                       // will init this.items
                        addItem(main, item, 0);
                }
 
@@ -129,6 +132,7 @@ public class ConfigEditor<E extends Enum<E>> extends JPanel {
                        bpane.add(pane, BorderLayout.CENTER);
                        main.add(bpane);
                } else {
+                       items.add(item);
                        main.add(new ConfigItem<E>(item, nhgap));
                }
        }
index 46333701ef67a7101935d45a629180dcd61c7c34..04bf76c04683291067ffb6671132e225ed7afbe7 100644 (file)
@@ -348,7 +348,8 @@ public class ConfigItem<E extends Enum<E>> 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);
                                }