X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fui%2FGuiReaderCoverImager.java;h=0bbf82eb47c29dcaab4a4a3fdee38cf9a995e7c3;hb=723647dd81e7e53b5404c95322a28c54c1d635df;hp=1f476b69708d28d41e0870d66f7ab42781efb169;hpb=bb0cff4b976144ef7dd54d573021e092cc7cb7f7;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderCoverImager.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderCoverImager.java index 1f476b6..0bbf82e 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; @@ -127,8 +126,23 @@ class GuiReaderCoverImager { * @return the icon */ static public ImageIcon generateCoverIcon(BasicLibrary lib, MetaData meta) { + return generateCoverIcon(lib, GuiReaderBookInfo.fromMeta(meta)); + } + + /** + * Generate a cover icon based upon the given {@link GuiReaderBookInfo}. + * + * @param lib + * the library the meta comes from + * @param info + * the {@link GuiReaderBookInfo} + * + * @return the icon + */ + 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 +157,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 +204,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; } }