X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fui%2FConfigEditor.java;h=367396da85d5acbaf8c7c1b5a4bd0f8d73615ee0;hb=8517b60cb3dfc64f7cec0c4da8d5003837e82bb2;hp=6b820bb1a45c183a9a72f695a9394506c032ef99;hpb=d350b96b06c55189e5d0ceed9db6f237e7d8d871;p=fanfix.git diff --git a/src/be/nikiroo/utils/ui/ConfigEditor.java b/src/be/nikiroo/utils/ui/ConfigEditor.java index 6b820bb..367396d 100644 --- a/src/be/nikiroo/utils/ui/ConfigEditor.java +++ b/src/be/nikiroo/utils/ui/ConfigEditor.java @@ -8,10 +8,14 @@ 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; +import be.nikiroo.utils.resources.MetaInfo; /** * A configuration panel for a {@link Bundle}. @@ -21,13 +25,13 @@ import be.nikiroo.utils.resources.Bundle; * values. * * @author niki - * + * * @param * the type of {@link Bundle} to edit */ public class ConfigEditor> extends JPanel { private static final long serialVersionUID = 1L; - private List> items; + private List> items; /** * Create a new {@link ConfigEditor} for this {@link Bundle}. @@ -36,38 +40,52 @@ public class ConfigEditor> 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 type, final Bundle bundle) { - this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); + public ConfigEditor(Class type, final Bundle 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 item : items) { - this.add(item); + items = MetaInfo.getItems(type, bundle); + for (MetaInfo item : items) { + main.add(new ConfigItem(item)); } - addButton("Reset", new ActionListener() { + main.add(createButton("Reset", new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - for (ConfigItem item : items) { + for (MetaInfo item : items) { item.reload(); } } - }); + })); - addButton("Default", new ActionListener() { + main.add(createButton("Default", new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { Object snap = bundle.takeSnapshot(); bundle.reload(true); - for (ConfigItem item : items) { + for (MetaInfo item : items) { item.reload(); } bundle.reload(false); bundle.restoreSnapshot(snap); } - }); + })); - addButton("Save", new ActionListener() { + main.add(createButton("Save", new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - for (ConfigItem item : items) { + for (MetaInfo item : items) { item.save(); } @@ -77,7 +95,7 @@ public class ConfigEditor> extends JPanel { e1.printStackTrace(); } } - }); + })); } /** @@ -88,7 +106,7 @@ public class ConfigEditor> 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 +115,6 @@ public class ConfigEditor> extends JPanel { panel.setBorder(new EmptyBorder(2, 10, 2, 10)); panel.add(button, BorderLayout.CENTER); - this.add(panel); + return panel; } }