From 79a9950614d3bea63b0daafb7b7365f6ae3cbeb9 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Wed, 20 Mar 2019 23:39:10 +0100 Subject: [PATCH] gui: add support for author cover --- .../fanfix/reader/ui/GuiReaderBook.java | 46 ++---- .../fanfix/reader/ui/GuiReaderBookInfo.java | 128 ++++++++++++++++ .../reader/ui/GuiReaderCoverImager.java | 76 +++++----- .../fanfix/reader/ui/GuiReaderFrame.java | 140 ++++++++++++------ .../fanfix/reader/ui/GuiReaderGroup.java | 22 +-- .../fanfix/reader/ui/GuiReaderMainPanel.java | 45 +++--- .../reader/ui/GuiReaderPropertiesFrame.java | 14 +- 7 files changed, 312 insertions(+), 159 deletions(-) create mode 100644 src/be/nikiroo/fanfix/reader/ui/GuiReaderBookInfo.java diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java index 4683f71..af2a5a7 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java @@ -12,7 +12,6 @@ import java.util.List; import javax.swing.JLabel; import javax.swing.JPanel; -import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix.reader.Reader; @@ -67,7 +66,7 @@ class GuiReaderBook extends JPanel { private Date lastClick; private List listeners; - private MetaData meta; + private GuiReaderBookInfo info; private boolean cached; /** @@ -75,45 +74,22 @@ class GuiReaderBook extends JPanel { * * @param reader * the associated reader - * @param meta - * the story {@link MetaData} or source (if no LUID) + * @param info + * the information about the story to represent * @param cached * TRUE if it is locally cached * @param seeWordCount * TRUE to see word counts, FALSE to see authors */ - public GuiReaderBook(Reader reader, MetaData meta, boolean cached, + public GuiReaderBook(Reader reader, GuiReaderBookInfo info, boolean cached, boolean seeWordCount) { this.cached = cached; - this.meta = meta; - - String optSecondary = meta.getAuthor(); - if (seeWordCount) { - if (meta.getWords() >= 4000) { - optSecondary = "" + (meta.getWords() / 1000) + "k"; - } else if (meta.getWords() > 0) { - optSecondary = "" + meta.getWords(); - } else { - optSecondary = ""; - } - - if (!optSecondary.isEmpty()) { - if (meta.isImageDocument()) { - optSecondary += " images"; - } else { - optSecondary += " words"; - } - } - } + this.info = info; - if (optSecondary != null && !optSecondary.isEmpty()) { - optSecondary = "(" + optSecondary + ")"; - } else { - optSecondary = ""; - } + String optSecondary = info.getSecondaryInfo(seeWordCount); icon = new JLabel(GuiReaderCoverImager.generateCoverIcon( - reader.getLibrary(), getMeta())); + reader.getLibrary(), info)); title = new JLabel( String.format( "" @@ -121,7 +97,7 @@ class GuiReaderBook extends JPanel { + "%s" + "
" + "" + "%s" + "" + "" + "", GuiReaderCoverImager.TEXT_WIDTH, - GuiReaderCoverImager.TEXT_HEIGHT, meta.getTitle(), + GuiReaderCoverImager.TEXT_HEIGHT, info.getMainInfo(), AUTHOR_COLOR, optSecondary)); setLayout(new BorderLayout(10, 10)); @@ -251,12 +227,12 @@ class GuiReaderBook extends JPanel { } /** - * The Library {@link MetaData} of the book represented by this item. + * The information about the book represented by this item. * * @return the meta */ - public MetaData getMeta() { - return meta; + public GuiReaderBookInfo getInfo() { + return info; } /** diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderBookInfo.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderBookInfo.java new file mode 100644 index 0000000..fe34844 --- /dev/null +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderBookInfo.java @@ -0,0 +1,128 @@ +package be.nikiroo.fanfix.reader.ui; + +import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.fanfix.library.BasicLibrary; +import be.nikiroo.utils.Image; + +public class GuiReaderBookInfo { + public enum Type { + /** A normal story, which can be "read". */ + STORY, + /** + * A special, empty story that represents a source/type common to one or + * more normal stories. + */ + SOURCE, + /** A special, empty story that represents an author. */ + AUTHOR + } + + private Type type; + private String id; + private String value; + private String count; + + private MetaData meta; + + // use the fromXXX methods + private GuiReaderBookInfo(Type type, String id, String value) { + this.type = type; + this.id = id; + this.value = value; + } + + public String getMainInfo() { + return value; + } + + public String getSecondaryInfo(boolean seeCount) { + String author = meta == null ? null : meta.getAuthor(); + String secondaryInfo = seeCount ? count : author; + + if (secondaryInfo != null && !secondaryInfo.trim().isEmpty()) { + secondaryInfo = "(" + secondaryInfo + ")"; + } else { + secondaryInfo = ""; + } + + return secondaryInfo; + } + + /** + * A unique ID for this {@link GuiReaderBookInfo}. + * + * @return the unique ID + */ + public String getId() { + return id; + } + + // can return null for non-books + public MetaData getMeta() { + return meta; + } + + public Image getBaseImage(BasicLibrary lib) { + switch (type) { + case STORY: + return lib.getCover(meta.getLuid()); + case SOURCE: + return lib.getSourceCover(value); + case AUTHOR: + return lib.getAuthorCover(value); + } + + return null; + } + + static public GuiReaderBookInfo fromMeta(MetaData meta) { + String uid = meta.getUuid(); + if (uid == null || uid.trim().isEmpty()) { + uid = meta.getLuid(); + } + + GuiReaderBookInfo info = new GuiReaderBookInfo(Type.STORY, uid, + meta.getTitle()); + + info.meta = meta; + info.count = formatNumber(meta.getWords(), + meta.isImageDocument() ? "images" : "words"); + + return info; + } + + static public GuiReaderBookInfo fromSource(BasicLibrary lib, String source) { + GuiReaderBookInfo info = new GuiReaderBookInfo(Type.SOURCE, "source_" + + source, source); + + info.count = formatNumber(lib.getListBySource(source).size(), "stories"); + + return info; + } + + static public GuiReaderBookInfo fromAuthor(BasicLibrary lib, String author) { + GuiReaderBookInfo info = new GuiReaderBookInfo(Type.AUTHOR, "author_" + + author, author); + + info.count = formatNumber(lib.getListByAuthor(author).size(), "stories"); + + return info; + } + + static private String formatNumber(long number, String ofWhat) { + String displayNumber; + if (number >= 4000) { + displayNumber = "" + (number / 1000) + "k"; + } else if (number > 0) { + displayNumber = "" + number; + } else { + displayNumber = ""; + } + + if (!displayNumber.isEmpty()) { + displayNumber += " " + ofWhat; + } + + return displayNumber; + } +} diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderCoverImager.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderCoverImager.java index 1f476b6..0f6d0b6 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderCoverImager.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderCoverImager.java @@ -17,7 +17,6 @@ import javax.swing.ImageIcon; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.data.MetaData; -import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix.library.BasicLibrary; import be.nikiroo.utils.Image; import be.nikiroo.utils.ui.ImageUtilsAwt; @@ -121,14 +120,15 @@ class GuiReaderCoverImager { * * @param lib * the library the meta comes from - * @param meta + * @param info * the {@link MetaData} * * @return the icon */ - static public ImageIcon generateCoverIcon(BasicLibrary lib, MetaData meta) { + static public ImageIcon generateCoverIcon(BasicLibrary lib, + GuiReaderBookInfo info) { BufferedImage resizedImage = null; - String id = getIconId(meta); + String id = getIconId(info); InputStream in = Instance.getCache().getFromCache(id); if (in != null) { @@ -143,30 +143,30 @@ class GuiReaderCoverImager { if (resizedImage == null) { try { - Image cover = null; - if (meta.getLuid() != null) { - cover = lib.getCover(meta.getLuid()); - } - if (cover == null) { - cover = lib.getSourceCover(meta.getSource()); - } - + Image cover = info.getBaseImage(lib); resizedImage = new BufferedImage(SPINE_WIDTH + COVER_WIDTH, SPINE_HEIGHT + COVER_HEIGHT + HOFFSET, BufferedImage.TYPE_4BYTE_ABGR); + Graphics2D g = resizedImage.createGraphics(); - g.setColor(Color.white); - g.fillRect(0, HOFFSET, COVER_WIDTH, COVER_HEIGHT); - if (cover != null) { - BufferedImage coverb = ImageUtilsAwt.fromImage(cover); - g.drawImage(coverb, 0, HOFFSET, COVER_WIDTH, COVER_HEIGHT, - null); - } else { - g.setColor(Color.black); - g.drawLine(0, HOFFSET, COVER_WIDTH, HOFFSET + COVER_HEIGHT); - g.drawLine(COVER_WIDTH, HOFFSET, 0, HOFFSET + COVER_HEIGHT); + try { + g.setColor(Color.white); + g.fillRect(0, HOFFSET, COVER_WIDTH, COVER_HEIGHT); + + if (cover != null) { + BufferedImage coverb = ImageUtilsAwt.fromImage(cover); + g.drawImage(coverb, 0, HOFFSET, COVER_WIDTH, + COVER_HEIGHT, null); + } else { + g.setColor(Color.black); + g.drawLine(0, HOFFSET, COVER_WIDTH, HOFFSET + + COVER_HEIGHT); + g.drawLine(COVER_WIDTH, HOFFSET, 0, HOFFSET + + COVER_HEIGHT); + } + } finally { + g.dispose(); } - g.dispose(); if (id != null) { ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -190,34 +190,24 @@ class GuiReaderCoverImager { /** * Manually clear the icon set for this item. * - * @param meta - * the meta of the story or source (if luid is null) + * @param info + * the info about the story or source/type or author */ - static public void clearIcon(MetaData meta) { - String id = getIconId(meta); + static public void clearIcon(GuiReaderBookInfo info) { + String id = getIconId(info); Instance.getCache().removeFromCache(id); } /** - * Get a unique ID from this meta (note that if the luid is null, it is - * considered a source and not a {@link Story}). + * Get a unique ID from this {@link GuiReaderBookInfo} (note that it can be + * a story, a fake item for a source/type or a fake item for an author). * - * @param meta - * the meta + * @param info + * the info * @return the unique ID */ - static private String getIconId(MetaData meta) { - String id = null; - - String key = meta.getUuid(); - if (meta.getLuid() == null) { - // a fake meta (== a source) - key = "source_" + meta.getSource(); - } - - id = key + ".thumb_" + SPINE_WIDTH + "x" + COVER_WIDTH + "+" + static private String getIconId(GuiReaderBookInfo info) { + return info.getId() + ".thumb_" + SPINE_WIDTH + "x" + COVER_WIDTH + "+" + SPINE_HEIGHT + "+" + COVER_HEIGHT + "@" + HOFFSET; - - return id; } } diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java index c690379..e2ead39 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java @@ -29,6 +29,7 @@ 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.library.BasicLibrary; import be.nikiroo.fanfix.library.LocalLibrary; import be.nikiroo.fanfix.output.BasicOutput.OutputType; import be.nikiroo.fanfix.reader.BasicReader; @@ -51,8 +52,18 @@ class GuiReaderFrame extends JFrame implements FrameHelper { private GuiReader reader; private GuiReaderMainPanel mainPanel; - private enum MoveAction { - SOURCE, TITLE, AUTHOR + /** + * The different modification actions you can use on {@link Story} items. + * + * @author niki + */ + private enum ChangeAction { + /** Change the source/type, that is, move it to another source. */ + SOURCE, + /** Change its name. */ + TITLE, + /** Change its author. */ + AUTHOR } /** @@ -83,7 +94,8 @@ class GuiReaderFrame extends JFrame implements FrameHelper { popup.addSeparator(); popup.add(createMenuItemExport()); popup.add(createMenuItemMoveTo(true)); - popup.add(createMenuItemSetCover()); + popup.add(createMenuItemSetCoverForSource()); + popup.add(createMenuItemSetCoverForAuthor()); popup.add(createMenuItemClearCache()); popup.add(createMenuItemRedownload()); popup.addSeparator(); @@ -401,8 +413,8 @@ class GuiReaderFrame extends JFrame implements FrameHelper { public void run() { try { reader.getLibrary().export( - selectedBook.getMeta().getLuid(), - type, path, pg); + selectedBook.getInfo().getMeta() + .getLuid(), type, path, pg); } catch (IOException e) { Instance.getTraceHandler().error(e); } @@ -454,11 +466,11 @@ class GuiReaderFrame extends JFrame implements FrameHelper { mainPanel.outOfUi(null, new Runnable() { @Override public void run() { - reader.clearLocalReaderCache(selectedBook.getMeta() - .getLuid()); + reader.clearLocalReaderCache(selectedBook.getInfo() + .getMeta().getLuid()); selectedBook.setCached(false); GuiReaderCoverImager.clearIcon(selectedBook - .getMeta()); + .getInfo()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -492,7 +504,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { } JMenuItem item = new JMenuItem("New type..."); - item.addActionListener(createMoveAction(MoveAction.SOURCE, null)); + item.addActionListener(createMoveAction(ChangeAction.SOURCE, null)); changeTo.add(item); changeTo.addSeparator(); @@ -500,7 +512,8 @@ class GuiReaderFrame extends JFrame implements FrameHelper { List list = groupedSources.get(type); if (list.size() == 1 && list.get(0).isEmpty()) { item = new JMenuItem(type); - item.addActionListener(createMoveAction(MoveAction.SOURCE, type)); + item.addActionListener(createMoveAction(ChangeAction.SOURCE, + type)); changeTo.add(item); } else { JMenu dir = new JMenu(type); @@ -513,8 +526,8 @@ class GuiReaderFrame extends JFrame implements FrameHelper { } item = new JMenuItem(itemName); - item.addActionListener(createMoveAction(MoveAction.SOURCE, - actualType)); + item.addActionListener(createMoveAction( + ChangeAction.SOURCE, actualType)); dir.add(item); } changeTo.add(dir); @@ -540,7 +553,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { JMenuItem newItem = new JMenuItem("New author..."); changeTo.add(newItem); changeTo.addSeparator(); - newItem.addActionListener(createMoveAction(MoveAction.AUTHOR, null)); + newItem.addActionListener(createMoveAction(ChangeAction.AUTHOR, null)); // Existing authors if (libOk) { @@ -554,7 +567,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { JMenuItem item = new JMenuItem( value.isEmpty() ? "[unknown]" : value); item.addActionListener(createMoveAction( - MoveAction.AUTHOR, value)); + ChangeAction.AUTHOR, value)); group.add(item); } changeTo.add(group); @@ -563,8 +576,8 @@ class GuiReaderFrame extends JFrame implements FrameHelper { for (String value : groupedAuthors.values().iterator().next()) { JMenuItem item = new JMenuItem( value.isEmpty() ? "[unknown]" : value); - item.addActionListener(createMoveAction(MoveAction.AUTHOR, - value)); + item.addActionListener(createMoveAction( + ChangeAction.AUTHOR, value)); changeTo.add(item); } } @@ -585,11 +598,11 @@ class GuiReaderFrame extends JFrame implements FrameHelper { @SuppressWarnings("unused") boolean libOk) { JMenuItem changeTo = new JMenuItem("Rename..."); changeTo.setMnemonic(KeyEvent.VK_R); - changeTo.addActionListener(createMoveAction(MoveAction.TITLE, null)); + changeTo.addActionListener(createMoveAction(ChangeAction.TITLE, null)); return changeTo; } - private ActionListener createMoveAction(final MoveAction what, + private ActionListener createMoveAction(final ChangeAction what, final String type) { return new ActionListener() { @Override @@ -598,13 +611,14 @@ class GuiReaderFrame extends JFrame implements FrameHelper { if (selectedBook != null) { String changeTo = type; if (type == null) { + MetaData meta = selectedBook.getInfo().getMeta(); String init = ""; - if (what == MoveAction.SOURCE) { - init = selectedBook.getMeta().getSource(); - } else if (what == MoveAction.TITLE) { - init = selectedBook.getMeta().getTitle(); - } else if (what == MoveAction.AUTHOR) { - init = selectedBook.getMeta().getAuthor(); + if (what == ChangeAction.SOURCE) { + init = meta.getSource(); + } else if (what == ChangeAction.TITLE) { + init = meta.getTitle(); + } else if (what == ChangeAction.AUTHOR) { + init = meta.getAuthor(); } Object rep = JOptionPane.showInputDialog( @@ -623,15 +637,14 @@ class GuiReaderFrame extends JFrame implements FrameHelper { mainPanel.outOfUi(null, new Runnable() { @Override public void run() { - if (what == MoveAction.SOURCE) { - reader.changeSource(selectedBook.getMeta() - .getLuid(), fChangeTo); - } else if (what == MoveAction.TITLE) { - reader.changeTitle(selectedBook.getMeta() - .getLuid(), fChangeTo); - } else if (what == MoveAction.AUTHOR) { - reader.changeAuthor(selectedBook.getMeta() - .getLuid(), fChangeTo); + String luid = selectedBook.getInfo().getMeta() + .getLuid(); + if (what == ChangeAction.SOURCE) { + reader.changeSource(luid, fChangeTo); + } else if (what == ChangeAction.TITLE) { + reader.changeTitle(luid, fChangeTo); + } else if (what == ChangeAction.AUTHOR) { + reader.changeAuthor(luid, fChangeTo); } mainPanel.unsetSelectedBook(); @@ -650,7 +663,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { } /** - * Create the redownload (then delete original) menu item. + * Create the re-download (then delete original) menu item. * * @return the item */ @@ -661,7 +674,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { public void actionPerformed(ActionEvent e) { final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { - final MetaData meta = selectedBook.getMeta(); + final MetaData meta = selectedBook.getInfo().getMeta(); mainPanel.imprt(meta.getUrl(), new StoryRunnable() { @Override public void run(Story story) { @@ -696,7 +709,8 @@ class GuiReaderFrame extends JFrame implements FrameHelper { mainPanel.outOfUi(null, new Runnable() { @Override public void run() { - reader.delete(selectedBook.getMeta().getLuid()); + reader.delete(selectedBook.getInfo().getMeta() + .getLuid()); mainPanel.unsetSelectedBook(); } }); @@ -723,7 +737,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { @Override public void run() { new GuiReaderPropertiesFrame(reader, selectedBook - .getMeta()).setVisible(true); + .getInfo()).setVisible(true); } }); } @@ -745,9 +759,9 @@ class GuiReaderFrame extends JFrame implements FrameHelper { public void actionPerformed(ActionEvent e) { final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { - if (selectedBook.getMeta().getLuid() == null) { + if (selectedBook.getInfo().getMeta().getLuid() == null) { mainPanel.removeBookPanes(); - mainPanel.addBookPane(selectedBook.getMeta() + mainPanel.addBookPane(selectedBook.getInfo().getMeta() .getSource(), true); mainPanel.refreshBooks(); } else { @@ -766,19 +780,53 @@ class GuiReaderFrame extends JFrame implements FrameHelper { * * @return the item */ - private JMenuItem createMenuItemSetCover() { + private JMenuItem createMenuItemSetCoverForSource() { JMenuItem open = new JMenuItem("Set as cover for source", KeyEvent.VK_C); open.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { - reader.getLibrary().setSourceCover( - selectedBook.getMeta().getSource(), - selectedBook.getMeta().getLuid()); - MetaData source = selectedBook.getMeta().clone(); - source.setLuid(null); - GuiReaderCoverImager.clearIcon(source); + BasicLibrary lib = reader.getLibrary(); + String luid = selectedBook.getInfo().getMeta().getLuid(); + String source = selectedBook.getInfo().getMeta() + .getSource(); + + lib.setSourceCover(source, luid); + + GuiReaderBookInfo sourceInfo = GuiReaderBookInfo + .fromSource(lib, source); + GuiReaderCoverImager.clearIcon(sourceInfo); + } + } + }); + + return open; + } + + /** + * Create the SetCover menu item for a book to change the linked source + * cover. + * + * @return the item + */ + private JMenuItem createMenuItemSetCoverForAuthor() { + JMenuItem open = new JMenuItem("Set as cover for author", KeyEvent.VK_A); + open.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); + if (selectedBook != null) { + BasicLibrary lib = reader.getLibrary(); + String luid = selectedBook.getInfo().getMeta().getLuid(); + String author = selectedBook.getInfo().getMeta() + .getAuthor(); + + lib.setAuthorCover(author, luid); + + GuiReaderBookInfo authorInfo = GuiReaderBookInfo + .fromAuthor(lib, author); + GuiReaderCoverImager.clearIcon(authorInfo); } } }); diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java index c96b02d..8d766f2 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java @@ -7,11 +7,9 @@ import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; -import javax.management.RuntimeErrorException; import javax.swing.JLabel; import javax.swing.JPanel; -import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.reader.ui.GuiReaderBook.BookActionListener; import be.nikiroo.utils.ui.WrapLayout; @@ -25,7 +23,7 @@ public class GuiReaderGroup extends JPanel { private BookActionListener action; private Color backgroundColor; private GuiReader reader; - private List stories; + private List infos; private List books; private JPanel pane; private boolean words; // words or authors (secondary info on books) @@ -79,7 +77,7 @@ public class GuiReaderGroup extends JPanel { */ public void setActionListener(BookActionListener action) { this.action = action; - refreshBooks(stories, words); + refreshBooks(infos, words); } /** @@ -90,8 +88,9 @@ public class GuiReaderGroup extends JPanel { * @param seeWordcount * TRUE to see word counts, FALSE to see authors */ - public void refreshBooks(List stories, boolean seeWordcount) { - this.stories = stories; + public void refreshBooks(List stories, + boolean seeWordcount) { + this.infos = stories; this.words = seeWordcount; books = new ArrayList(); @@ -100,9 +99,14 @@ public class GuiReaderGroup extends JPanel { pane.removeAll(); if (stories != null) { - for (MetaData meta : stories) { - GuiReaderBook book = new GuiReaderBook(reader, meta, - reader.isCached(meta.getLuid()), seeWordcount); + for (GuiReaderBookInfo info : stories) { + boolean isCached = false; + if (info.getMeta() != null) { + isCached = reader.isCached(info.getMeta().getLuid()); + } + + GuiReaderBook book = new GuiReaderBook(reader, info, isCached, + seeWordcount); if (backgroundColor != null) { book.setBackground(backgroundColor); } diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java index a53d572..a0f0fc9 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java @@ -334,15 +334,19 @@ class GuiReaderMainPanel extends JPanel { public void refreshBooks() { BasicLibrary lib = helper.getReader().getLibrary(); for (GuiReaderGroup group : booksByType.keySet()) { - List stories = lib - .getListBySource(booksByType.get(group)); - group.refreshBooks(stories, words); + List infos = new ArrayList(); + for (MetaData meta : lib.getListBySource(booksByType.get(group))) { + infos.add(GuiReaderBookInfo.fromMeta(meta)); + } + group.refreshBooks(infos, words); } for (GuiReaderGroup group : booksByAuthor.keySet()) { - List stories = lib.getListByAuthor(booksByAuthor - .get(group)); - group.refreshBooks(stories, words); + List infos = new ArrayList(); + for (MetaData meta : lib.getListByAuthor(booksByAuthor.get(group))) { + infos.add(GuiReaderBookInfo.fromMeta(meta)); + } + group.refreshBooks(infos, words); } pane.repaint(); @@ -361,8 +365,8 @@ class GuiReaderMainPanel extends JPanel { @Override public void run() { try { - helper.getReader() - .read(book.getMeta().getLuid(), false, pg); + helper.getReader().read(book.getInfo().getMeta().getLuid(), + false, pg); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -556,20 +560,21 @@ class GuiReaderMainPanel extends JPanel { private void addListPane(String name, List values, final boolean type) { - // Sources -> i18n - GuiReaderGroup bookPane = new GuiReaderGroup(helper.getReader(), name, - color); + GuiReader reader = helper.getReader(); + BasicLibrary lib = reader.getLibrary(); - List metas = new ArrayList(); - for (String source : values) { - MetaData mSource = new MetaData(); - mSource.setLuid(null); - mSource.setTitle(source); - mSource.setSource(source); - metas.add(mSource); + GuiReaderGroup bookPane = new GuiReaderGroup(reader, name, color); + + List infos = new ArrayList(); + for (String value : values) { + if (type) { + infos.add(GuiReaderBookInfo.fromSource(lib, value)); + } else { + infos.add(GuiReaderBookInfo.fromAuthor(lib, value)); + } } - bookPane.refreshBooks(metas, false); + bookPane.refreshBooks(infos, false); this.invalidate(); pane.invalidate(); @@ -592,7 +597,7 @@ class GuiReaderMainPanel extends JPanel { @Override public void action(final GuiReaderBook book) { removeBookPanes(); - addBookPane(book.getMeta().getSource(), type); + addBookPane(book.getInfo().getMainInfo(), type); refreshBooks(); } }); diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java index 0ad082c..975136f 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java @@ -35,14 +35,16 @@ public class GuiReaderPropertiesFrame extends JFrame { * @param meta * the meta to describe */ - public GuiReaderPropertiesFrame(Reader reader, MetaData meta) { + public GuiReaderPropertiesFrame(Reader reader, GuiReaderBookInfo info) { + MetaData meta = info.getMeta(); + // Borders int top = 20; int space = 10; // Image ImageIcon img = GuiReaderCoverImager.generateCoverIcon( - reader.getLibrary(), meta); + reader.getLibrary(), info); // frame setTitle(meta.getLuid() + ": " + meta.getTitle()); @@ -61,11 +63,11 @@ public class GuiReaderPropertiesFrame extends JFrame { mainPanel.add(mainPanelKeys, BorderLayout.WEST); mainPanel.add(mainPanelValues, BorderLayout.CENTER); - List> infos = BasicReader.getMetaDesc(meta); + List> desc = BasicReader.getMetaDesc(meta); Color trans = new Color(0, 0, 0, 1); - for (Entry info : infos) { - JTextArea key = new JTextArea(info.getKey()); + for (Entry descLine : desc) { + JTextArea key = new JTextArea(descLine.getKey()); key.setFont(new Font(key.getFont().getFontName(), Font.BOLD, key .getFont().getSize())); key.setEditable(false); @@ -73,7 +75,7 @@ public class GuiReaderPropertiesFrame extends JFrame { key.setBackground(trans); mainPanelKeys.add(key); - JTextArea value = new JTextArea(info.getValue()); + JTextArea value = new JTextArea(descLine.getValue()); value.setEditable(false); value.setLineWrap(false); value.setBackground(trans); -- 2.27.0