X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fui%2FConfigEditor.java;h=c687c98fee5637dfb8e10b7bad32f6be102ef9d5;hb=3519cb5c518d569235beaedfc3071cba45ec848d;hp=b2182adb34fd689717cbca9d3ea147f348d1842f;hpb=76b51de96af0b8dfa9615db37823fffd093fcfe3;p=fanfix.git diff --git a/src/be/nikiroo/utils/ui/ConfigEditor.java b/src/be/nikiroo/utils/ui/ConfigEditor.java deleted file mode 100644 index b2182ad..0000000 --- a/src/be/nikiroo/utils/ui/ConfigEditor.java +++ /dev/null @@ -1,131 +0,0 @@ -package be.nikiroo.utils.ui; - -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.IOException; -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}. - *

- * All the items in the given {@link Bundle} will be displayed in editable - * controls, with options to Save, Reset and/or Reset to the application default - * 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; - - /** - * Create a new {@link ConfigEditor} for this {@link Bundle}. - * - * @param type - * 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, 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 = MetaInfo.getItems(type, bundle); - for (MetaInfo item : items) { - addItem(main, item); - } - - main.add(createButton("Reset", new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - 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 (MetaInfo item : items) { - item.reload(); - } - bundle.reload(false); - bundle.restoreSnapshot(snap); - } - })); - - main.add(createButton("Save", new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - for (MetaInfo item : items) { - item.save(); - } - - try { - bundle.updateFile(); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - })); - } - - private void addItem(JPanel main, MetaInfo item) { - if (item.isGroup()) { - // TODO - for (MetaInfo subitem : item) { - addItem(main, subitem); - } - } else { - main.add(new ConfigItem(item)); - } - } - - /** - * Add an action button for this action. - * - * @param title - * the action title - * @param listener - * the action - */ - private JComponent createButton(String title, ActionListener listener) { - JButton button = new JButton(title); - button.addActionListener(listener); - - JPanel panel = new JPanel(); - panel.setLayout(new BorderLayout()); - panel.setBorder(new EmptyBorder(2, 10, 2, 10)); - panel.add(button, BorderLayout.CENTER); - - return panel; - } -}