Merge branch 'subtree'
[fanfix.git] / src / be / nikiroo / utils / ui / ConfigEditor.java
index b384c9dc49631f37d5998385f745408570a1043c..c687c98fee5637dfb8e10b7bad32f6be102ef9d5 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;
@@ -49,23 +50,25 @@ public class ConfigEditor<E extends Enum<E>> extends JPanel {
         */
        public ConfigEditor(Class<E> type, final Bundle<E> bundle, String title) {
                this.setLayout(new BorderLayout());
-               JPanel main = new JPanel();
-
-               JScrollPane scroll = new JScrollPane(main);
-               scroll.getVerticalScrollBar().setUnitIncrement(16);
-               this.add(scroll, BorderLayout.CENTER);
 
+               JPanel main = new 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);
                }
 
-               main.add(createButton("Reset", new ActionListener() {
+               JPanel buttons = new JPanel();
+               buttons.setLayout(new BoxLayout(buttons, BoxLayout.PAGE_AXIS));
+               buttons.setBorder(new EmptyBorder(5, 5, 5, 5));
+
+               buttons.add(createButton("Reset", new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                for (MetaInfo<E> item : items) {
@@ -74,7 +77,7 @@ public class ConfigEditor<E extends Enum<E>> extends JPanel {
                        }
                }));
 
-               main.add(createButton("Default", new ActionListener() {
+               buttons.add(createButton("Default", new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                Object snap = bundle.takeSnapshot();
@@ -87,11 +90,11 @@ public class ConfigEditor<E extends Enum<E>> extends JPanel {
                        }
                }));
 
-               main.add(createButton("Save", new ActionListener() {
+               buttons.add(createButton("Save", new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                for (MetaInfo<E> item : items) {
-                                       item.save();
+                                       item.save(true);
                                }
 
                                try {
@@ -101,6 +104,12 @@ public class ConfigEditor<E extends Enum<E>> extends JPanel {
                                }
                        }
                }));
+
+               JScrollPane scroll = new JScrollPane(main);
+               scroll.getVerticalScrollBar().setUnitIncrement(16);
+
+               this.add(scroll, BorderLayout.CENTER);
+               this.add(buttons, BorderLayout.SOUTH);
        }
 
        private void addItem(JPanel main, MetaInfo<E> item, int nhgap) {
@@ -114,6 +123,7 @@ public class ConfigEditor<E extends Enum<E>> extends JPanel {
                        String info = item.getDescription();
                        info = StringUtils.justifyTexts(info, 100);
                        if (!info.isEmpty()) {
+                               info = info + "\n";
                                JTextArea text = new JTextArea(info);
                                text.setWrapStyleWord(true);
                                text.setOpaque(false);
@@ -128,7 +138,8 @@ public class ConfigEditor<E extends Enum<E>> extends JPanel {
                        bpane.add(pane, BorderLayout.CENTER);
                        main.add(bpane);
                } else {
-                       main.add(new ConfigItem<E>(item, nhgap));
+                       items.add(item);
+                       main.add(ConfigItem.createItem(item, nhgap));
                }
        }