Version 1.4.0: new Bundle configuration controls
authorNiki Roo <niki@nikiroo.be>
Wed, 8 Mar 2017 19:26:23 +0000 (20:26 +0100)
committerNiki Roo <niki@nikiroo.be>
Wed, 8 Mar 2017 19:26:23 +0000 (20:26 +0100)
changelog
src/be/nikiroo/utils/ui/ConfigEditor.java
src/be/nikiroo/utils/ui/ConfigItem.java

index 56a8fab0909b3241be20ecedbd9745aa18debd0e..4a8514d782e6aa60a6ea8ab42cc47309891717bb 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,9 +1,12 @@
 Version 1.4.0
 -------------
 
-RW Bundles
+R/W Bundles
        Bundle is now Read/Write
 
+Bundle Configuration
+       New UI controls to configure the Bundles graphically
+
 Version 1.3.6
 -------------
 
index 6b820bb1a45c183a9a72f695a9394506c032ef99..fb98eba01f72458ca21f5c97302350b058206ba5 100644 (file)
@@ -8,7 +8,10 @@ import java.util.List;
 
 import javax.swing.BoxLayout;
 import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JScrollPane;
 import javax.swing.border.EmptyBorder;
 
 import be.nikiroo.utils.resources.Bundle;
@@ -36,24 +39,35 @@ public class ConfigEditor<E extends Enum<E>> extends JPanel {
         *            a class instance of the item type to work on
         * @param bundle
         *            the {@link Bundle} to sort through
+        * @param title
+        *            the title to display before the options
         */
-       public ConfigEditor(Class<E> type, final Bundle<E> bundle) {
-               this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
+       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);
+
+               main.setLayout(new BoxLayout(main, BoxLayout.PAGE_AXIS));
+
+               main.add(new JLabel(title));
 
                items = ConfigItem.getItems(type, bundle);
                for (ConfigItem<E> item : items) {
-                       this.add(item);
+                       main.add(item);
                }
 
-               addButton("Reset", new ActionListener() {
+               main.add(createButton("Reset", new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                for (ConfigItem<E> item : items) {
                                        item.reload();
                                }
                        }
-               });
+               }));
 
-               addButton("Default", new ActionListener() {
+               main.add(createButton("Default", new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                Object snap = bundle.takeSnapshot();
                                bundle.reload(true);
@@ -63,9 +77,9 @@ public class ConfigEditor<E extends Enum<E>> extends JPanel {
                                bundle.reload(false);
                                bundle.restoreSnapshot(snap);
                        }
-               });
+               }));
 
-               addButton("Save", new ActionListener() {
+               main.add(createButton("Save", new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                for (ConfigItem<E> item : items) {
                                        item.save();
@@ -77,7 +91,7 @@ public class ConfigEditor<E extends Enum<E>> extends JPanel {
                                        e1.printStackTrace();
                                }
                        }
-               });
+               }));
        }
 
        /**
@@ -88,7 +102,7 @@ public class ConfigEditor<E extends Enum<E>> extends JPanel {
         * @param listener
         *            the action
         */
-       private void addButton(String title, ActionListener listener) {
+       private JComponent createButton(String title, ActionListener listener) {
                JButton button = new JButton(title);
                button.addActionListener(listener);
 
@@ -97,6 +111,6 @@ public class ConfigEditor<E extends Enum<E>> extends JPanel {
                panel.setBorder(new EmptyBorder(2, 10, 2, 10));
                panel.add(button, BorderLayout.CENTER);
 
-               this.add(panel);
+               return panel;
        }
 }
index 3593d7ce3c8ded39e42289f08285f32b131accdf..2cec4cab381e300dc53382c3961f508ada6f801f 100644 (file)
@@ -36,7 +36,13 @@ public class ConfigItem<E extends Enum<E>> extends JPanel {
                this.setLayout(new BorderLayout());
                this.setBorder(new EmptyBorder(2, 10, 2, 10));
 
-               JLabel nameLabel = new JLabel(id.toString());
+               String name = id.toString();
+               if (name.length() > 1) {
+                       name = name.substring(0, 1) + name.substring(1).toLowerCase();
+                       name = name.replace("_", " ");
+               }
+
+               JLabel nameLabel = new JLabel(name);
                nameLabel.setPreferredSize(new Dimension(400, 0));
                this.add(nameLabel, BorderLayout.WEST);