X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FGuiReaderFrame.java;h=39db588bee8ff225974663a0f445ffb642f70610;hb=99ccbdf63b539f1f40e070f5833f2d15fcf79830;hp=e88c9777ee3afc01ab27efb2cb8595991a4c4f90;hpb=211f7ddb50f68aa8a999023ef6d63d5756bdace6;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java b/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java index e88c977..39db588 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java @@ -22,6 +22,7 @@ import java.util.Map.Entry; import javax.swing.BoxLayout; import javax.swing.JFileChooser; import javax.swing.JFrame; +import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; @@ -29,6 +30,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; +import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileNameExtensionFilter; @@ -66,6 +68,21 @@ class GuiReaderFrame extends JFrame { private GuiReaderBook selectedBook; private boolean words; // words or authors (secondary info on books) + /** + * A {@link Runnable} with a {@link Story} parameter. + * + * @author niki + */ + private interface StoryRunnable { + /** + * Run the action. + * + * @param story + * the story + */ + public void run(Story story); + } + /** * Create a new {@link GuiReaderFrame}. * @@ -97,6 +114,12 @@ class GuiReaderFrame extends JFrame { scroll.getVerticalScrollBar().setUnitIncrement(16); add(scroll, BorderLayout.CENTER); + String message = reader.getLibrary().getLibraryName(); + if (!message.isEmpty()) { + JLabel name = new JLabel(message, SwingConstants.CENTER); + add(name, BorderLayout.NORTH); + } + pgBar = new ProgressBar(); add(pgBar, BorderLayout.SOUTH); @@ -141,6 +164,49 @@ class GuiReaderFrame extends JFrame { setVisible(true); } + private void addSourcePanes() { + // Sources -> i18n + GuiReaderGroup bookPane = new GuiReaderGroup(reader, "Sources", color); + + List sources = new ArrayList(); + for (String source : reader.getLibrary().getSources()) { + MetaData mSource = new MetaData(); + mSource.setLuid(null); + mSource.setTitle(source); + mSource.setSource(source); + sources.add(mSource); + } + + bookPane.refreshBooks(sources, false); + + this.invalidate(); + pane.invalidate(); + pane.add(bookPane); + pane.validate(); + this.validate(); + + bookPane.setActionListener(new BookActionListener() { + @Override + public void select(GuiReaderBook book) { + selectedBook = book; + } + + @Override + public void popupRequested(GuiReaderBook book, MouseEvent e) { + JPopupMenu popup = new JPopupMenu(); + popup.add(createMenuItemOpenBook()); + popup.show(e.getComponent(), e.getX(), e.getY()); + } + + @Override + public void action(final GuiReaderBook book) { + removeBookPanes(); + addBookPane(book.getMeta().getSource(), true); + refreshBooks(); + } + }); + } + /** * Add a new {@link GuiReaderGroup} on the frame to display the books of the * selected type or author. @@ -154,9 +220,14 @@ class GuiReaderFrame extends JFrame { private void addBookPane(String value, boolean type) { if (value == null) { if (type) { - for (String tt : reader.getLibrary().getSources()) { - if (tt != null) { - addBookPane(tt, type); + if (Instance.getUiConfig().getBoolean(UiConfig.SOURCE_PAGE, + false)) { + addSourcePanes(); + } else { + for (String tt : reader.getLibrary().getSources()) { + if (tt != null) { + addBookPane(tt, type); + } } } } else { @@ -196,6 +267,7 @@ class GuiReaderFrame extends JFrame { popup.addSeparator(); popup.add(createMenuItemExport()); popup.add(createMenuItemMove()); + popup.add(createMenuItemSetCover()); popup.add(createMenuItemClearCache()); popup.add(createMenuItemRedownload()); popup.addSeparator(); @@ -584,7 +656,7 @@ class GuiReaderFrame extends JFrame { "Moving story", JOptionPane.QUESTION_MESSAGE, null, null, selectedBook.getMeta().getSource()); - + if (rep == null) { return; } @@ -629,11 +701,16 @@ class GuiReaderFrame extends JFrame { public void actionPerformed(ActionEvent e) { if (selectedBook != null) { final MetaData meta = selectedBook.getMeta(); - imprt(meta.getUrl(), new Runnable() { + imprt(meta.getUrl(), new StoryRunnable() { @Override - public void run() { + public void run(Story story) { reader.delete(meta.getLuid()); GuiReaderFrame.this.selectedBook = null; + MetaData newMeta = story.getMeta(); + if (!newMeta.getSource().equals(meta.getSource())) { + reader.changeType(newMeta.getLuid(), + meta.getSource()); + } } }, "Removing old copy"); } @@ -669,7 +746,7 @@ class GuiReaderFrame extends JFrame { } /** - * Create the open menu item. + * Create the open menu item for a book or a source (no LUID). * * @return the item */ @@ -679,7 +756,35 @@ class GuiReaderFrame extends JFrame { @Override public void actionPerformed(ActionEvent e) { if (selectedBook != null) { - openBook(selectedBook); + if (selectedBook.getMeta().getLuid() == null) { + removeBookPanes(); + addBookPane(selectedBook.getMeta().getSource(), true); + refreshBooks(); + } else { + openBook(selectedBook); + } + } + } + }); + + return open; + } + + /** + * Create the SetCover menu item for a book to change the linked source + * cover. + * + * @return the item + */ + private JMenuItem createMenuItemSetCover() { + JMenuItem open = new JMenuItem("Set as cover for source", KeyEvent.VK_C); + open.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (selectedBook != null) { + reader.getLibrary().setSourceCover( + selectedBook.getMeta().getSource(), + selectedBook.getMeta().getLuid()); } } }); @@ -805,7 +910,7 @@ class GuiReaderFrame extends JFrame { * @param onSuccess * Action to execute on success */ - private void imprt(final String url, final Runnable onSuccess, + private void imprt(final String url, final StoryRunnable onSuccess, String onSuccessPgName) { final Progress pg = new Progress(); final Progress pgImprt = new Progress(); @@ -817,8 +922,10 @@ class GuiReaderFrame extends JFrame { @Override public void run() { Exception ex = null; + Story story = null; try { - reader.getLibrary().imprt(BasicReader.getUrl(url), pgImprt); + story = reader.getLibrary().imprt(BasicReader.getUrl(url), + pgImprt); } catch (IOException e) { ex = e; } @@ -840,7 +947,7 @@ class GuiReaderFrame extends JFrame { }); } else { if (onSuccess != null) { - onSuccess.run(); + onSuccess.run(story); } } pgOnSuccess.done();