X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FGuiReaderBook.java;h=bf2b5ed96f233cd60a59228f5ac91f10080dd7cb;hp=29f4c49783a0a727d7c9f08011ee5c8408617c9c;hb=085a2f9a3a811a910de7c3011eb6f5ef2ab18aa0;hpb=14b574483b51d3859acef6a269f8841b5a4eb5f8 diff --git a/src/be/nikiroo/fanfix/reader/GuiReaderBook.java b/src/be/nikiroo/fanfix/reader/GuiReaderBook.java index 29f4c49..bf2b5ed 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReaderBook.java +++ b/src/be/nikiroo/fanfix/reader/GuiReaderBook.java @@ -118,12 +118,20 @@ 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()) { @@ -132,7 +140,7 @@ class GuiReaderBook extends JPanel { optSecondary = ""; } - icon = new JLabel(generateCoverIcon(meta)); + icon = new JLabel(generateCoverIcon()); title = new JLabel( String.format( "" @@ -363,28 +371,20 @@ class GuiReaderBook extends JPanel { /** * Generate a cover icon based upon the given {@link MetaData}. * - * @param meta - * the {@link MetaData} about the target {@link Story} or source - * (if no LUID) - * * @return the icon */ - private ImageIcon generateCoverIcon(MetaData meta) { + private ImageIcon generateCoverIcon() { BufferedImage resizedImage = null; - String id = null; + String id = getIconId(meta); - if (meta.getLuid() != null) { - id = meta.getUuid() + ".thumb_" + SPINE_WIDTH + "x" + COVER_WIDTH - + "+" + SPINE_HEIGHT + "+" + COVER_HEIGHT + "@" + HOFFSET; - InputStream in = Instance.getCache().getFromCache(id); - if (in != null) { - try { - resizedImage = ImageUtils.fromStream(in); - in.close(); - in = null; - } catch (IOException e) { - Instance.syserr(e); - } + InputStream in = Instance.getCache().getFromCache(id); + if (in != null) { + try { + resizedImage = ImageUtils.fromStream(in); + in.close(); + in = null; + } catch (IOException e) { + Instance.syserr(e); } } @@ -418,7 +418,7 @@ class GuiReaderBook extends JPanel { ByteArrayOutputStream out = new ByteArrayOutputStream(); ImageIO.write(resizedImage, "png", out); byte[] imageBytes = out.toByteArray(); - InputStream in = new ByteArrayInputStream(imageBytes); + in = new ByteArrayInputStream(imageBytes); Instance.getCache().addToCache(in, id); in.close(); in = null; @@ -432,4 +432,38 @@ class GuiReaderBook extends JPanel { 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; + } }