X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FGuiReaderBook.java;h=c70f30a8db69f11976c8b7345d322d8b21c8d074;hb=62c63b0724f4bc45999cb2e7186b4b3ada479a0a;hp=6475bd9736cf2ebe975a92295f2513317bf386ed;hpb=211f7ddb50f68aa8a999023ef6d63d5756bdace6;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/reader/GuiReaderBook.java b/src/be/nikiroo/fanfix/reader/GuiReaderBook.java index 6475bd9..c70f30a 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReaderBook.java +++ b/src/be/nikiroo/fanfix/reader/GuiReaderBook.java @@ -103,7 +103,7 @@ class GuiReaderBook extends JPanel { * @param reader * the associated reader * @param meta - * the story {@link MetaData} + * the story {@link MetaData} or source (if no LUID) * @param cached * TRUE if it is locally cached * @param seeWordCount @@ -118,19 +118,29 @@ class GuiReaderBook extends JPanel { String optSecondary = meta.getAuthor(); if (seeWordCount) { if (meta.getWords() >= 4000) { - optSecondary = (meta.getWords() / 1000) + "k words"; + optSecondary = "" + (meta.getWords() / 1000) + "k"; } else if (meta.getWords() > 0) { - optSecondary = meta.getWords() + " words"; + optSecondary = "" + meta.getWords(); } else { optSecondary = ""; } + + if (!optSecondary.isEmpty()) { + if (meta.isImageDocument()) { + optSecondary += " images"; + } else { + optSecondary += " words"; + } + } } if (optSecondary != null && !optSecondary.isEmpty()) { optSecondary = "(" + optSecondary + ")"; + } else { + optSecondary = ""; } - icon = new JLabel(generateCoverIcon(meta)); + icon = new JLabel(generateCoverIcon()); title = new JLabel( String.format( "" @@ -361,16 +371,11 @@ class GuiReaderBook extends JPanel { /** * Generate a cover icon based upon the given {@link MetaData}. * - * @param meta - * the {@link MetaData} about the target {@link Story} - * * @return the icon */ - private ImageIcon generateCoverIcon(MetaData meta) { - String id = meta.getUuid() + ".thumb_" + SPINE_WIDTH + "x" - + COVER_WIDTH + "+" + SPINE_HEIGHT + "+" + COVER_HEIGHT + "@" - + HOFFSET; + private ImageIcon generateCoverIcon() { BufferedImage resizedImage = null; + String id = getIconId(meta); InputStream in = Instance.getCache().getFromCache(id); if (in != null) { @@ -379,14 +384,19 @@ class GuiReaderBook extends JPanel { in.close(); in = null; } catch (IOException e) { - Instance.syserr(e); + Instance.getTraceHandler().error(e); } } if (resizedImage == null) { try { - BufferedImage cover = reader.getLibrary().getCover( - meta.getLuid()); + BufferedImage cover = null; + if (meta.getLuid() == null) { + cover = reader.getLibrary() + .getSourceCover(meta.getSource()); + } else { + cover = reader.getLibrary().getCover(meta.getLuid()); + } resizedImage = new BufferedImage(SPINE_WIDTH + COVER_WIDTH, SPINE_HEIGHT + COVER_HEIGHT + HOFFSET, @@ -404,20 +414,56 @@ class GuiReaderBook extends JPanel { } g.dispose(); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ImageIO.write(resizedImage, "png", out); - byte[] imageBytes = out.toByteArray(); - in = new ByteArrayInputStream(imageBytes); - Instance.getCache().addToCache(in, id); - in.close(); - in = null; + if (id != null) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ImageIO.write(resizedImage, "png", out); + byte[] imageBytes = out.toByteArray(); + in = new ByteArrayInputStream(imageBytes); + Instance.getCache().addToCache(in, id); + in.close(); + in = null; + } } catch (MalformedURLException e) { - Instance.syserr(e); + Instance.getTraceHandler().error(e); } catch (IOException e) { - Instance.syserr(e); + Instance.getTraceHandler().error(e); } } return new ImageIcon(resizedImage); } + + /** + * Manually clear the icon set for this item. + * + * @param meta + * the meta of the story or source (if luid is null) + */ + public static void clearIcon(MetaData meta) { + String id = getIconId(meta); + 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}). + * + * @param meta + * the meta + * @return the unique ID + */ + private static 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 + "+" + + SPINE_HEIGHT + "+" + COVER_HEIGHT + "@" + HOFFSET; + + return id; + } }