X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fui%2FConfigEditor.java;h=c687c98fee5637dfb8e10b7bad32f6be102ef9d5;hb=5584adbbbf5444c0039fed2b35dc7d5bb57b71b1;hp=b2182adb34fd689717cbca9d3ea147f348d1842f;hpb=76b51de96af0b8dfa9615db37823fffd093fcfe3;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/ui/ConfigEditor.java b/src/be/nikiroo/utils/ui/ConfigEditor.java index b2182ad..c687c98 100644 --- a/src/be/nikiroo/utils/ui/ConfigEditor.java +++ b/src/be/nikiroo/utils/ui/ConfigEditor.java @@ -1,9 +1,11 @@ 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; +import java.util.ArrayList; import java.util.List; import javax.swing.BoxLayout; @@ -12,8 +14,11 @@ 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; @@ -45,22 +50,25 @@ public class ConfigEditor> extends JPanel { */ 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); + 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 item : items) { - addItem(main, item); + items = new ArrayList>(); + List> groupedItems = MetaInfo.getItems(type, bundle); + for (MetaInfo 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 item : items) { @@ -69,7 +77,7 @@ public class ConfigEditor> extends JPanel { } })); - main.add(createButton("Default", new ActionListener() { + buttons.add(createButton("Default", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object snap = bundle.takeSnapshot(); @@ -82,11 +90,11 @@ public class ConfigEditor> extends JPanel { } })); - main.add(createButton("Save", new ActionListener() { + buttons.add(createButton("Save", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (MetaInfo item : items) { - item.save(); + item.save(true); } try { @@ -96,16 +104,42 @@ public class ConfigEditor> 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 item) { + private void addItem(JPanel main, MetaInfo item, int nhgap) { if (item.isGroup()) { - // TODO + 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(main, subitem); + addItem(pane, subitem, nhgap + 11); } + bpane.add(pane, BorderLayout.CENTER); + main.add(bpane); } else { - main.add(new ConfigItem(item)); + items.add(item); + main.add(ConfigItem.createItem(item, nhgap)); } }