X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fui%2FConfigEditor.java;h=ca85f6161fdbd7db238a71a3872f59569564d797;hb=e95f4fb6e42ae31c2353a31aca79ecf68ee6a014;hp=fb98eba01f72458ca21f5c97302350b058206ba5;hpb=49f79f31c728cc9a39b695a559404faa9a15f9b3;p=fanfix.git diff --git a/src/be/nikiroo/utils/ui/ConfigEditor.java b/src/be/nikiroo/utils/ui/ConfigEditor.java index fb98eba..ca85f61 100644 --- a/src/be/nikiroo/utils/ui/ConfigEditor.java +++ b/src/be/nikiroo/utils/ui/ConfigEditor.java @@ -1,6 +1,7 @@ package be.nikiroo.utils.ui; import java.awt.BorderLayout; +import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; @@ -12,9 +13,13 @@ import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.JTextArea; import javax.swing.border.EmptyBorder; +import javax.swing.border.TitledBorder; +import be.nikiroo.utils.StringUtils; import be.nikiroo.utils.resources.Bundle; +import be.nikiroo.utils.resources.MetaInfo; /** * A configuration panel for a {@link Bundle}. @@ -24,13 +29,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}. @@ -51,27 +56,30 @@ public class ConfigEditor> extends JPanel { this.add(scroll, BorderLayout.CENTER); main.setLayout(new BoxLayout(main, BoxLayout.PAGE_AXIS)); - + main.setBorder(new EmptyBorder(5, 5, 5, 5)); + main.add(new JLabel(title)); - items = ConfigItem.getItems(type, bundle); - for (ConfigItem item : items) { - main.add(item); + items = MetaInfo.getItems(type, bundle); + for (MetaInfo item : items) { + addItem(main, item, 0); } main.add(createButton("Reset", new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - for (ConfigItem item : items) { + for (MetaInfo item : items) { item.reload(); } } })); 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); @@ -80,8 +88,9 @@ public class ConfigEditor> extends JPanel { })); main.add(createButton("Save", new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - for (ConfigItem item : items) { + for (MetaInfo item : items) { item.save(); } @@ -94,6 +103,36 @@ public class ConfigEditor> extends JPanel { })); } + private void addItem(JPanel main, MetaInfo item, int nhgap) { + if (item.isGroup()) { + JPanel bpane = new JPanel(new BorderLayout()); + bpane.setBorder(new TitledBorder(item.getName())); + JPanel pane = new JPanel(); + pane.setBorder(new EmptyBorder(5, 5, 5, 5)); + pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); + + 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); + text.setForeground(new Color(100, 100, 180)); + text.setEditable(false); + pane.add(text); + } + + for (MetaInfo subitem : item) { + addItem(pane, subitem, nhgap + 11); + } + bpane.add(pane, BorderLayout.CENTER); + main.add(bpane); + } else { + main.add(new ConfigItem(item, nhgap)); + } + } + /** * Add an action button for this action. *