X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FLocalReaderFrame.java;h=bf94f26f8d7ceb1a197a7ab588e33fd4b1652fc9;hp=58c75963d2940e72c856b5a93e34bd83d1a05e01;hb=68e2c6d20049d713de1bd31b749450b2f60d8340;hpb=e8eeea0a321493d270c35f594a8bf392cc95f4df diff --git a/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java b/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java index 58c7596..bf94f26 100644 --- a/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java @@ -13,6 +13,7 @@ import java.awt.event.WindowEvent; 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; @@ -33,7 +34,7 @@ import javax.swing.filechooser.FileFilter; 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; @@ -70,7 +71,7 @@ class LocalReaderFrame extends JFrame { * * @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 */ @@ -116,13 +117,23 @@ class LocalReaderFrame extends JFrame { } }); - setJMenuBar(createMenu()); - booksByType = new HashMap(); booksByAuthor = new HashMap(); - 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); } @@ -132,14 +143,15 @@ class LocalReaderFrame extends JFrame { * 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); } @@ -178,6 +190,7 @@ class LocalReaderFrame extends JFrame { popup.add(createMenuItemOpenBook()); popup.addSeparator(); popup.add(createMenuItemExport()); + popup.add(createMenuItemMove()); popup.add(createMenuItemClearCache()); popup.add(createMenuItemRedownload()); popup.addSeparator(); @@ -207,7 +220,7 @@ class LocalReaderFrame extends JFrame { */ private void refreshBooks() { for (LocalReaderGroup group : booksByType.keySet()) { - List stories = Instance.getLibrary().getListByType( + List stories = Instance.getLibrary().getListBySource( booksByType.get(group)); group.refreshBooks(stories, words); } @@ -255,6 +268,7 @@ class LocalReaderFrame extends JFrame { file.add(createMenuItemOpenBook()); file.add(createMenuItemExport()); + file.add(createMenuItemMove()); file.addSeparator(); file.add(imprt); file.add(imprtF); @@ -298,7 +312,7 @@ class LocalReaderFrame extends JFrame { JMenu sources = new JMenu("Sources"); sources.setMnemonic(KeyEvent.VK_S); - List tt = Instance.getLibrary().getTypes(); + List tt = Instance.getLibrary().getSources(); tt.add(0, null); for (final String type : tt) { JMenuItem item = new JMenuItem(type == null ? "All" : type); @@ -517,6 +531,68 @@ class LocalReaderFrame extends JFrame { 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 types = new ArrayList(); + 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. * @@ -638,17 +714,17 @@ class LocalReaderFrame extends JFrame { 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}. *

* Should be called inside the UI thread. * @@ -688,7 +764,7 @@ class LocalReaderFrame extends JFrame { } /** - * Actually import the {@link Story} into the main {@link Library}. + * Actually import the {@link Story} into the main {@link LocalLibrary}. *

* Should be called inside the UI thread. * @@ -735,7 +811,7 @@ class LocalReaderFrame extends JFrame { onSuccess.run(); } } - pgOnSuccess.setProgress(100); + pgOnSuccess.done(); } }); } @@ -753,7 +829,10 @@ class LocalReaderFrame extends JFrame { */ @Override public void setEnabled(boolean b) { - bar.setEnabled(b); + if (bar != null) { + bar.setEnabled(b); + } + for (LocalReaderGroup group : booksByType.keySet()) { group.setEnabled(b); }