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=1334518a49feba8367df5f829ae2e48576a2458a;hb=085a2f9a3a811a910de7c3011eb6f5ef2ab18aa0;hpb=326093dc53fa48019c94f59bd006b307d755b392 diff --git a/src/be/nikiroo/fanfix/reader/GuiReaderBook.java b/src/be/nikiroo/fanfix/reader/GuiReaderBook.java index 1334518..bf2b5ed 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( "" @@ -189,26 +199,31 @@ class GuiReaderBook extends JPanel { private void setupListeners() { listeners = new ArrayList(); addMouseListener(new MouseListener() { + @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { popup(e); } } + @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { popup(e); } } + @Override public void mouseExited(MouseEvent e) { setHovered(false); } + @Override public void mouseEntered(MouseEvent e) { setHovered(true); } + @Override public void mouseClicked(MouseEvent e) { if (isEnabled()) { Date now = new Date(); @@ -356,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) { @@ -380,8 +390,13 @@ class GuiReaderBook extends JPanel { 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, @@ -399,13 +414,15 @@ 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); } catch (IOException e) { @@ -415,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; + } }