import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.filechooser.FileNameExtensionFilter;
import be.nikiroo.fanfix.Instance;
-import be.nikiroo.fanfix.Library;
+import be.nikiroo.fanfix.LocalLibrary;
+import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.bundles.UiConfig;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.reader.LocalReaderBook.BookActionListener;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.Version;
+import be.nikiroo.utils.ui.ConfigEditor;
import be.nikiroo.utils.ui.ProgressBar;
/**
*
* @param reader
* the associated {@link LocalReader} to forward some commands
- * and access its {@link Library}
+ * and access its {@link LocalLibrary}
* @param type
* the type of {@link Story} to load, or NULL for all types
*/
pgBar.addUpdateListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- revalidate();
+ invalidate();
+ validate();
repaint();
}
});
- setJMenuBar(createMenu());
-
booksByType = new HashMap<LocalReaderGroup, String>();
booksByAuthor = new HashMap<LocalReaderGroup, String>();
- addBookPane(type, true);
- refreshBooks();
+ pane.setVisible(false);
+ final Progress pg = new Progress();
+ final String typeF = type;
+ outOfUi(pg, new Runnable() {
+ public void run() {
+ Instance.getLibrary().refresh(false, pg);
+ invalidate();
+ setJMenuBar(createMenu());
+ addBookPane(typeF, true);
+ refreshBooks();
+ validate();
+ pane.setVisible(true);
+ }
+ });
setVisible(true);
}
* the selected type or author.
*
* @param value
- * the author or the type
+ * the author or the type, or NULL to get all the
+ * authors-or-types
* @param type
* TRUE for type, FALSE for author
*/
private void addBookPane(String value, boolean type) {
if (value == null) {
if (type) {
- for (String tt : Instance.getLibrary().getTypes()) {
+ for (String tt : Instance.getLibrary().getSources()) {
if (tt != null) {
addBookPane(tt, type);
}
popup.add(createMenuItemOpenBook());
popup.addSeparator();
popup.add(createMenuItemExport());
+ popup.add(createMenuItemMove());
popup.add(createMenuItemClearCache());
popup.add(createMenuItemRedownload());
popup.addSeparator();
*/
private void refreshBooks() {
for (LocalReaderGroup group : booksByType.keySet()) {
- List<MetaData> stories = Instance.getLibrary().getListByType(
+ List<MetaData> stories = Instance.getLibrary().getListBySource(
booksByType.get(group));
group.refreshBooks(stories, words);
}
file.add(createMenuItemOpenBook());
file.add(createMenuItemExport());
+ file.add(createMenuItemMove());
file.addSeparator();
file.add(imprt);
file.add(imprtF);
JMenu sources = new JMenu("Sources");
sources.setMnemonic(KeyEvent.VK_S);
- List<String> tt = Instance.getLibrary().getTypes();
+ List<String> tt = Instance.getLibrary().getSources();
tt.add(0, null);
for (final String type : tt) {
JMenuItem item = new JMenuItem(type == null ? "All" : type);
bar.add(authors);
+ JMenu options = new JMenu("Options");
+ options.setMnemonic(KeyEvent.VK_O);
+ options.add(createMenuItemConfig());
+ options.add(createMenuItemUiConfig());
+ bar.add(options);
+
return bar;
}
+ /**
+ * Create the Fanfix Configuration menu item.
+ *
+ * @return the item
+ */
+ private JMenuItem createMenuItemConfig() {
+ final String title = "Fanfix Configuration";
+ JMenuItem item = new JMenuItem(title);
+ item.setMnemonic(KeyEvent.VK_F);
+
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ ConfigEditor<Config> ed = new ConfigEditor<Config>(
+ Config.class, Instance.getConfig(),
+ "This is where you configure the options of the program.");
+ JFrame frame = new JFrame(title);
+ frame.add(ed);
+ frame.setSize(800, 600);
+ frame.setVisible(true);
+ }
+ });
+
+ return item;
+ }
+
+ /**
+ * Create the UI Configuration menu item.
+ *
+ * @return the item
+ */
+ private JMenuItem createMenuItemUiConfig() {
+ final String title = "UI Configuration";
+ JMenuItem item = new JMenuItem(title);
+ item.setMnemonic(KeyEvent.VK_U);
+
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ ConfigEditor<UiConfig> ed = new ConfigEditor<UiConfig>(
+ UiConfig.class, Instance.getUiConfig(),
+ "This is where you configure the graphical appearence of the program.");
+ JFrame frame = new JFrame(title);
+ frame.add(ed);
+ frame.setSize(800, 600);
+ frame.setVisible(true);
+ }
+ });
+
+ return item;
+ }
+
/**
* Create the export menu item.
*
return refresh;
}
+ /**
+ * Create the delete menu item.
+ *
+ * @return the item
+ */
+ private JMenuItem createMenuItemMove() {
+ JMenu moveTo = new JMenu("Move to...");
+ moveTo.setMnemonic(KeyEvent.VK_M);
+
+ List<String> types = new ArrayList<String>();
+ types.add(null);
+ types.addAll(Instance.getLibrary().getSources());
+
+ for (String type : types) {
+ JMenuItem item = new JMenuItem(type == null ? "New type..." : type);
+
+ moveTo.add(item);
+ if (type == null) {
+ moveTo.addSeparator();
+ }
+
+ final String ftype = type;
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (selectedBook != null) {
+ String type = ftype;
+ if (type == null) {
+ Object rep = JOptionPane.showInputDialog(
+ LocalReaderFrame.this, "Move to:",
+ "Moving story",
+ JOptionPane.QUESTION_MESSAGE, null, null,
+ selectedBook.getMeta().getSource());
+ if (rep == null) {
+ return;
+ } else {
+ type = rep.toString();
+ }
+ }
+
+ final String ftype = type;
+ outOfUi(null, new Runnable() {
+ public void run() {
+ reader.changeType(selectedBook.getMeta()
+ .getLuid(), ftype);
+
+ selectedBook = null;
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ setJMenuBar(createMenu());
+ }
+ });
+ }
+ });
+ }
+ }
+ });
+ }
+
+ return moveTo;
+ }
+
/**
* Create the redownload (then delete original) menu item.
*
public void run() {
run.run();
refreshBooks();
- reload.setProgress(100);
+ reload.done();
if (!pg.isDone()) {
// will trigger pgBar ActionListener:
- pg.setProgress(pg.getMax());
+ pg.done();
}
}
}, "outOfUi thread").start();
}
/**
- * Import a {@link Story} into the main {@link Library}.
+ * Import a {@link Story} into the main {@link LocalLibrary}.
* <p>
* Should be called inside the UI thread.
*
}
/**
- * Actually import the {@link Story} into the main {@link Library}.
+ * Actually import the {@link Story} into the main {@link LocalLibrary}.
* <p>
* Should be called inside the UI thread.
*
onSuccess.run();
}
}
- pgOnSuccess.setProgress(100);
+ pgOnSuccess.done();
}
});
}
*/
@Override
public void setEnabled(boolean b) {
- bar.setEnabled(b);
+ if (bar != null) {
+ bar.setEnabled(b);
+ }
+
for (LocalReaderGroup group : booksByType.keySet()) {
group.setEnabled(b);
}