X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FGuiReaderBook.java;h=c70f30a8db69f11976c8b7345d322d8b21c8d074;hb=62c63b0724f4bc45999cb2e7186b4b3ada479a0a;hp=2ae04b461d13bdd43cac911e0702190439d12cca;hpb=e604986c4208da0091d26bc0e1c4feb4ff3c588f;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/GuiReaderBook.java b/src/be/nikiroo/fanfix/reader/GuiReaderBook.java index 2ae04b4..c70f30a 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReaderBook.java +++ b/src/be/nikiroo/fanfix/reader/GuiReaderBook.java @@ -140,7 +140,7 @@ class GuiReaderBook extends JPanel { optSecondary = ""; } - icon = new JLabel(generateCoverIcon(meta)); + icon = new JLabel(generateCoverIcon()); title = new JLabel( String.format( "" @@ -371,24 +371,12 @@ 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 key = meta.getUuid(); - if (key == null) { - // a fake meta (a source) - key = "source_" + meta.getSource(); - } + String id = getIconId(meta); - id = key + ".thumb_" + SPINE_WIDTH + "x" + COVER_WIDTH + "+" - + SPINE_HEIGHT + "+" + COVER_HEIGHT + "@" + HOFFSET; InputStream in = Instance.getCache().getFromCache(id); if (in != null) { try { @@ -396,7 +384,7 @@ class GuiReaderBook extends JPanel { in.close(); in = null; } catch (IOException e) { - Instance.syserr(e); + Instance.getTraceHandler().error(e); } } @@ -436,12 +424,46 @@ class GuiReaderBook extends JPanel { 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; + } }