Some fixes: output types, libraries, remote
authorNiki Roo <niki@nikiroo.be>
Sun, 26 Nov 2017 11:16:31 +0000 (12:16 +0100)
committerNiki Roo <niki@nikiroo.be>
Sun, 26 Nov 2017 11:16:31 +0000 (12:16 +0100)
15 files changed:
src/be/nikiroo/fanfix/Instance.java
src/be/nikiroo/fanfix/Main.java
src/be/nikiroo/fanfix/bundles/Config.java
src/be/nikiroo/fanfix/bundles/UiConfig.java
src/be/nikiroo/fanfix/bundles/config.properties
src/be/nikiroo/fanfix/bundles/resources.properties
src/be/nikiroo/fanfix/bundles/ui.properties
src/be/nikiroo/fanfix/bundles/ui_description.properties
src/be/nikiroo/fanfix/library/LocalLibrary.java
src/be/nikiroo/fanfix/library/RemoteLibrary.java
src/be/nikiroo/fanfix/library/RemoteLibraryServer.java
src/be/nikiroo/fanfix/output/BasicOutput.java
src/be/nikiroo/fanfix/reader/GuiReader.java
src/be/nikiroo/fanfix/reader/GuiReaderBook.java
src/be/nikiroo/fanfix/reader/GuiReaderGroup.java

index a06c975420419c00d2998214438e3356101ab397..df990d7f3b1431aabc81c3a3d6ceabaa91a21a94 100644 (file)
@@ -12,7 +12,6 @@ import be.nikiroo.fanfix.bundles.UiConfig;
 import be.nikiroo.fanfix.bundles.UiConfigBundle;
 import be.nikiroo.fanfix.library.BasicLibrary;
 import be.nikiroo.fanfix.library.LocalLibrary;
-import be.nikiroo.fanfix.output.BasicOutput.OutputType;
 import be.nikiroo.utils.IOUtils;
 import be.nikiroo.utils.resources.Bundles;
 
@@ -122,8 +121,7 @@ public class Instance {
                uiconfig = new UiConfigBundle();
                trans = new StringIdBundle(getLang());
                try {
-                       lib = new LocalLibrary(getFile(Config.LIBRARY_DIR),
-                                       OutputType.INFO_TEXT, OutputType.CBZ);
+                       lib = new LocalLibrary(getFile(Config.LIBRARY_DIR));
                } catch (Exception e) {
                        syserr(new IOException("Cannot create library for directory: "
                                        + getFile(Config.LIBRARY_DIR), e));
@@ -134,7 +132,7 @@ public class Instance {
                coverDir = getFile(Config.DEFAULT_COVERS_DIR);
                File tmp = getFile(Config.CACHE_DIR);
                readerTmp = getFile(UiConfig.CACHE_DIR_LOCAL_READER);
-               remoteDir = new File(getFile(Config.LIBRARY_DIR), "remote");
+               remoteDir = new File(configDir, "remote");
 
                if (checkEnv("NOUTF")) {
                        trans.setUnicode(false);
index 99ac119dd3a864d1e77e486a839f99083727789a..c17a1d8b988f0a52c7c763efd9bad67f48bebd92 100644 (file)
@@ -372,7 +372,7 @@ public class Main {
         */
        public static int export(String luid, String typeString, String target,
                        Progress pg) {
-               OutputType type = OutputType.valueOfNullOkUC(typeString);
+               OutputType type = OutputType.valueOfNullOkUC(typeString, null);
                if (type == null) {
                        Instance.syserr(new Exception(trans(StringId.OUTPUT_DESC,
                                        typeString)));
@@ -477,7 +477,7 @@ public class Main {
                                sourceName = sourceName.substring("file://".length());
                        }
 
-                       OutputType type = OutputType.valueOfAllOkUC(typeString);
+                       OutputType type = OutputType.valueOfAllOkUC(typeString, null);
                        if (type == null) {
                                Instance.syserr(new IOException(trans(
                                                StringId.ERR_BAD_OUTPUT_TYPE, typeString)));
index bd27edffc31589abb8346dfa0d59b8428c2da587..d2d189e57fafb46e4377799c29d1e62c5be8ffa4 100644 (file)
@@ -15,6 +15,11 @@ public enum Config {
        @Meta(description = "reader type (CLI = simple output to console, TUI = Text User Interface with menus and windows, GUI = a GUI with locally stored files)", format = Format.FIXED_LIST, list = {
                        "CLI", "GUI", "TUI" }, info = "Select the default reader to use to read stories")
        READER_TYPE, //
+       @Meta(format = Format.COMBO_LIST, list = { "INFO_TEXT", "EPUB", "HTML",
+                       "TEXT" }, info = "One of the known output type", description = "The type of output for the Local Reader for non-images documents")
+       NON_IMAGES_DOCUMENT_TYPE, //
+       @Meta(format = Format.COMBO_LIST, list = { "CBZ", "HTML" }, description = "The type of output for the Local Reader for images documents")
+       IMAGES_DOCUMENT_TYPE, //
        @Meta(description = "absolute path, $HOME variable supported, / is always accepted as dir separator", format = Format.DIRECTORY, info = "The directory where to store temporary files, defaults to directory 'tmp' in the conig directory (usually $HOME/.fanfix)")
        CACHE_DIR, //
        @Meta(description = "delay in hours, or 0 for no cache, or -1 for infinite time (default)", format = Format.INT, info = "The delay after which a cached resource that is thought to change ~often is considered too old and triggers a refresh")
index 271abb3ec8e981957da2ebb4cdfb1ee596a63275..a4d8439132eddbb501d79c241c3b15691ccf8938 100644 (file)
@@ -12,10 +12,11 @@ import be.nikiroo.utils.resources.Meta.Format;
 public enum UiConfig {
        @Meta(format = Format.DIRECTORY, info = "absolute path, $HOME variable supported, / is always accepted as dir separator", description = "The directory where to store temporary files, defaults to directory 'tmp.reader' in the conig directory (usually $HOME/.fanfix)")
        CACHE_DIR_LOCAL_READER, //
-       @Meta(format = Format.COMBO_LIST, list = { "HTML", "CBZ" }, info = "One of the known output type", description = "The type of output for the Local Reader for non-images documents")
-       NON_IMAGES_DOCUMENT_TYPE, //
-       @Meta(format = Format.COMBO_LIST, list = { "HTML", "CBZ" }, description = "The type of output for the Local Reader for images documents")
-       IMAGES_DOCUMENT_TYPE, //
+       @Meta(format = Format.COMBO_LIST, list = { "INFO_TEXT", "EPUB", "HTML",
+                       "TEXT" }, info = "One of the known output type", description = "The type of output for the GUI Reader for non-images documents")
+       GUI_NON_IMAGES_DOCUMENT_TYPE, //
+       @Meta(format = Format.COMBO_LIST, list = { "CBZ", "HTML" }, description = "The type of output for the GUI Reader for images documents")
+       GUI_IMAGES_DOCUMENT_TYPE, //
        @Meta(info = "A command to start", description = "The command launched for images documents -- default to the system default for the current file type")
        IMAGES_DOCUMENT_READER, //
        @Meta(info = "A command to start", description = "The command launched for non images documents -- default to the system default for the current file type")
index 0c04e414cf5437251481ab4b19b1a35180ea8108..b6d8fa5f594146268277a0ae3dd221f7ced07eca 100644 (file)
@@ -9,6 +9,14 @@ LANG =
 # (FORMAT: FIXED_LIST) Select the default reader to use to read stories
 # ALLOWED VALUES: "CLI" "GUI" "TUI"
 READER_TYPE = 
+# The type of output for the Local Reader for non-images documents
+# (FORMAT: COMBO_LIST) One of the known output type
+# ALLOWED VALUES: "INFO_TEXT" "EPUB" "HTML" "TEXT"
+NON_IMAGES_DOCUMENT_TYPE = INFO_TEXT
+# The type of output for the Local Reader for images documents
+# (FORMAT: COMBO_LIST) 
+# ALLOWED VALUES: "CBZ" "HTML"
+IMAGES_DOCUMENT_TYPE = CBZ
 # absolute path, $HOME variable supported, / is always accepted as dir separator
 # (FORMAT: DIRECTORY) The directory where to store temporary files, defaults to directory 'tmp' in the conig directory (usually $HOME/.fanfix)
 CACHE_DIR = 
@@ -78,4 +86,4 @@ LOGIN_FIMFICTION_APIKEY_CLIENT_SECRET =
 LOGIN_FIMFICTION_APIKEY_FORCE_HTML = 
 # A token is required to use the beta APIv2 from FimFiction (see APIKEY_CLIENT_*)
 # (FORMAT: PASSWORD) 
-LOGIN_FIMFICTION_APIKEY_TOKEN = Bearer WnZ5oHlzQoDocv1GcgHfcoqctHkSwL-D 
+LOGIN_FIMFICTION_APIKEY_TOKEN = Bearer WnZ5oHlzQoDocv1GcgHfcoqctHkSwL-D
index bdbb75405509368a6c4c0a33d3591ef9c553b4d6..8d6bb1a792350ad1194c6ce3662bf50edeb1805e 100644 (file)
@@ -19,6 +19,7 @@ HELP_SYNTAX = Valid options:\n\
 \t--list: list the stories present in the library\n\
 \t--set-reader [reader type]: set the reader type to CLI, TUI or GUI for \n\
 \t\tthis command\n\
+\t--server [port]: start a remote server on this port\n\
 \t--remote [host] [port]: select this remote server to get \n\
 \t\t(or update or...) the stories from\n\
 \t--help: this help message\n\
index d98410a8da5c9130a00e779c59a60bc8d027a961..80e0a24d8cb459131f12f4b2efbe1e824bfbdb76 100644 (file)
@@ -5,14 +5,14 @@
 # The directory where to store temporary files, defaults to directory 'tmp.reader' in the conig directory (usually $HOME/.fanfix)
 # (FORMAT: DIRECTORY) absolute path, $HOME variable supported, / is always accepted as dir separator
 CACHE_DIR_LOCAL_READER = 
-# The type of output for the Local Reader for non-images documents
+# The type of output for the GUI Reader for non-images documents
 # (FORMAT: COMBO_LIST) One of the known output type
-# ALLOWED VALUES: "HTML" "CBZ"
-NON_IMAGES_DOCUMENT_TYPE = HTML
-# The type of output for the Local Reader for images documents
+# ALLOWED VALUES: "INFO_TEXT" "EPUB" "HTML" "TEXT"
+GUI_NON_IMAGES_DOCUMENT_TYPE = HTML
+# The type of output for the GUI Reader for images documents
 # (FORMAT: COMBO_LIST) 
-# ALLOWED VALUES: "HTML" "CBZ"
-IMAGES_DOCUMENT_TYPE = CBZ
+# ALLOWED VALUES: "CBZ" "HTML"
+GUI_IMAGES_DOCUMENT_TYPE = CBZ
 # The command launched for images documents -- default to the system default for the current file type
 # (FORMAT: STRING) A command to start
 IMAGES_DOCUMENT_READER = 
index 147a5a6f3353a1036d57501a8ad72bb63b02aeb5..99df88a5db2de3ac2a6dc302578a7b38207def2a 100644 (file)
 # The directory where to store temporary files, defaults to directory 'tmp.reader' in the conig directory (usually $HOME/.fanfix)
 # (FORMAT: DIRECTORY) absolute path, $HOME variable supported, / is always accepted as dir separator
 CACHE_DIR_LOCAL_READER = The directory where to store temporary files, defaults to directory 'tmp.reader' in the config directory (usually $HOME/.fanfix) -- this is an absolute path, $HOME variable supported, / is always accepted as dir separator
-# The type of output for the Local Reader for non-images documents
+# The type of output for the GUI Reader for non-images documents
 # (FORMAT: COMBO_LIST) One of the known output type
-# ALLOWED VALUES: "HTML" "CBZ"
-NON_IMAGES_DOCUMENT_TYPE = 
-# The type of output for the Local Reader for images documents
+# ALLOWED VALUES: "INFO_TEXT" "EPUB" "HTML" "TEXT"
+GUI_NON_IMAGES_DOCUMENT_TYPE = 
+# The type of output for the GUI Reader for images documents
 # (FORMAT: COMBO_LIST) 
-# ALLOWED VALUES: "HTML" "CBZ"
-IMAGES_DOCUMENT_TYPE = 
+# ALLOWED VALUES: "CBZ" "HTML"
+GUI_IMAGES_DOCUMENT_TYPE = 
 # The command launched for images documents -- default to the system default for the current file type
 # (FORMAT: STRING) A command to start
 IMAGES_DOCUMENT_READER = 
index ab5a82b58b48a51ed4b1abc085118e986184f4fd..d811d2b2249ec365232c9ea31657d5b1504f5a11 100644 (file)
@@ -40,15 +40,41 @@ public class LocalLibrary extends BasicLibrary {
        private OutputType text;
        private OutputType image;
 
+       /**
+        * Create a new {@link LocalLibrary} with the given back-end directory.
+        * 
+        * @param baseDir
+        *            the directory where to find the {@link Story} objects
+        */
+       public LocalLibrary(File baseDir) {
+               this(baseDir, Instance.getConfig().getString(
+                               Config.NON_IMAGES_DOCUMENT_TYPE), Instance.getConfig()
+                               .getString(Config.IMAGES_DOCUMENT_TYPE), false);
+       }
+
+       /**
+        * Create a new {@link LocalLibrary} with the given back-end directory.
+        * 
+        * @param baseDir
+        *            the directory where to find the {@link Story} objects
+        */
+       public LocalLibrary(File baseDir, String text, String image,
+                       boolean defaultIsHtml) {
+               this(baseDir, OutputType.valueOfNullOkUC(text,
+                               defaultIsHtml ? OutputType.HTML : OutputType.INFO_TEXT),
+                               OutputType.valueOfNullOkUC(image,
+                                               defaultIsHtml ? OutputType.HTML : OutputType.CBZ));
+       }
+
        /**
         * Create a new {@link LocalLibrary} with the given back-end directory.
         * 
         * @param baseDir
         *            the directory where to find the {@link Story} objects
         * @param text
-        *            the {@link OutputType} to save the text-focused stories into
+        *            the {@link OutputType} to use for non-image documents
         * @param image
-        *            the {@link OutputType} to save the images-focused stories into
+        *            the {@link OutputType} to use for image documents
         */
        public LocalLibrary(File baseDir, OutputType text, OutputType image) {
                this.baseDir = baseDir;
@@ -188,15 +214,24 @@ public class LocalLibrary extends BasicLibrary {
                        pg = new Progress();
                }
 
-               // Check if we can simply copy the files instead of the whole process
+               LocalLibrary otherLocalLibrary = null;
+               if (other instanceof RemoteLibrary) {
+                       otherLocalLibrary = ((RemoteLibrary) other).getLocalLibrary();
+               }
+
                if (other instanceof LocalLibrary) {
-                       LocalLibrary otherLibrary = (LocalLibrary) other;
-                       MetaData meta = otherLibrary.getInfo(luid);
-                       String expectedType = "" + (meta.isImageDocument() ? image : text);
-                       if (meta.getType().equals(expectedType)) {
-                               File from = otherLibrary.getExpectedDir(meta.getSource());
+                       otherLocalLibrary = (LocalLibrary) other;
+               }
+
+               // Check if we can simply copy the files instead of the whole process
+               if (otherLocalLibrary != null) {
+                       MetaData meta = otherLocalLibrary.getInfo(luid);
+                       String expectedType = ""
+                                       + (meta != null && meta.isImageDocument() ? image : text);
+                       if (meta != null && meta.getType().equals(expectedType)) {
+                               File from = otherLocalLibrary.getExpectedDir(meta.getSource());
                                File to = this.getExpectedDir(meta.getSource());
-                               List<File> sources = otherLibrary.getRelatedFiles(luid);
+                               List<File> sources = otherLocalLibrary.getRelatedFiles(luid);
                                if (!sources.isEmpty()) {
                                        pg.setMinMax(0, sources.size());
                                }
@@ -205,6 +240,7 @@ public class LocalLibrary extends BasicLibrary {
                                        File target = new File(source.getAbsolutePath().replace(
                                                        from.getAbsolutePath(), to.getAbsolutePath()));
                                        if (!source.equals(target)) {
+                                               target.getParentFile().mkdirs();
                                                InputStream in = null;
                                                try {
                                                        in = new FileInputStream(source);
@@ -232,6 +268,8 @@ public class LocalLibrary extends BasicLibrary {
                }
 
                super.imprt(other, luid, pg);
+
+               clearCache();
        }
 
        /**
index 337e13fe7394c36f4d089f0e25700e487ed6c4d6..63082ce94fd0a954790865d4a4ddc19fbf6c5ebb 100644 (file)
@@ -9,7 +9,6 @@ import java.util.List;
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
-import be.nikiroo.fanfix.output.BasicOutput.OutputType;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.Version;
 import be.nikiroo.utils.serial.ConnectActionClient;
@@ -44,8 +43,7 @@ public class RemoteLibrary extends BasicLibrary {
                this.baseDir = Instance.getRemoteDir(host);
                this.baseDir.mkdirs();
 
-               this.lib = new LocalLibrary(baseDir, OutputType.INFO_TEXT,
-                               OutputType.CBZ);
+               this.lib = new LocalLibrary(baseDir);
        }
 
        @Override
@@ -61,7 +59,7 @@ public class RemoteLibrary extends BasicLibrary {
                        metas = new ArrayList<MetaData>();
 
                        try {
-                               new ConnectActionClient(host, port, true, null) {
+                               new ConnectActionClient(host, port, true) {
                                        @Override
                                        public void action(Version serverVersion) throws Exception {
                                                try {
@@ -77,6 +75,14 @@ public class RemoteLibrary extends BasicLibrary {
                        } catch (IOException e) {
                                Instance.syserr(e);
                        }
+
+                       List<String> test = new ArrayList<String>();
+                       for (MetaData meta : metas) {
+                               if (test.contains(meta.getLuid())) {
+                                       throw new RuntimeException("wwops");
+                               }
+                               test.add(meta.getLuid());
+                       }
                }
 
                return metas;
@@ -88,7 +94,7 @@ public class RemoteLibrary extends BasicLibrary {
                if (file == null) {
                        final File[] tmp = new File[1];
                        try {
-                               new ConnectActionClient(host, port, true, null) {
+                               new ConnectActionClient(host, port, true) {
                                        @Override
                                        public void action(Version serverVersion) throws Exception {
                                                try {
@@ -119,13 +125,30 @@ public class RemoteLibrary extends BasicLibrary {
        }
 
        @Override
-       public BufferedImage getCover(String luid) {
-               // Retrieve it from the network if needed:
-               if (lib.getInfo(luid) == null) {
-                       getFile(luid);
+       public BufferedImage getCover(final String luid) {
+               // Retrieve it from the cache if possible:
+               if (lib.getInfo(luid) != null) {
+                       return lib.getCover(luid);
+               }
+
+               final BufferedImage[] result = new BufferedImage[1];
+               try {
+                       new ConnectActionClient(host, port, true) {
+                               @Override
+                               public void action(Version serverVersion) throws Exception {
+                                       try {
+                                               Object rep = send("GET_COVER " + luid);
+                                               result[0] = (BufferedImage) rep;
+                                       } catch (Exception e) {
+                                               Instance.syserr(e);
+                                       }
+                               }
+                       }.connect();
+               } catch (IOException e) {
+                       Instance.syserr(e);
                }
 
-               return lib.getCover(luid);
+               return result[0];
        }
 
        @Override
@@ -170,4 +193,13 @@ public class RemoteLibrary extends BasicLibrary {
        protected Story doSave(Story story, Progress pg) throws IOException {
                throw new java.lang.InternalError("Should not have been called");
        }
+
+       /**
+        * Return the backing local library.
+        * 
+        * @return the library
+        */
+       LocalLibrary getLocalLibrary() {
+               return lib;
+       }
 }
index 661bf54d61b8100d0b00a964b9016f77945666c8..221fbdfc05b21153f0c6a33ee012657f0b19cd95 100644 (file)
@@ -65,6 +65,10 @@ public class RemoteLibraryServer extends Server {
                        if (args != null) {
                                return Instance.getLibrary().getStory(args, null);
                        }
+               } else if ("GET_COVER".equals(command)) {
+                       if (args != null) {
+                               return Instance.getLibrary().getCover(args);
+                       }
                }
 
                return null;
index 4607827b14e8010e98b844d0becd3c3df2e61463..036a1564d0a594eae2e4d758f0dd16f40a3fcd44 100644 (file)
@@ -110,17 +110,19 @@ public abstract class BasicOutput {
 
                /**
                 * Call {@link OutputType#valueOf(String)} after conversion to upper
-                * case but return NULL for NULL and empty instead of raising an
+                * case but return def for NULL and empty instead of raising an
                 * exception.
                 * 
                 * @param typeName
                 *            the possible type name
+                * @param def
+                *            the default value
                 * 
                 * @return NULL or the type
                 */
-               public static OutputType valueOfNullOkUC(String typeName) {
+               public static OutputType valueOfNullOkUC(String typeName, OutputType def) {
                        if (typeName == null || typeName.isEmpty()) {
-                               return null;
+                               return def;
                        }
 
                        return OutputType.valueOfUC(typeName);
@@ -128,19 +130,20 @@ public abstract class BasicOutput {
 
                /**
                 * Call {@link OutputType#valueOf(String)} after conversion to upper
-                * case but return NULL in case of error instead of raising an
-                * exception.
+                * case but return def in case of error instead of raising an exception.
                 * 
                 * @param typeName
                 *            the possible type name
+                * @param def
+                *            the default value
                 * 
                 * @return NULL or the type
                 */
-               public static OutputType valueOfAllOkUC(String typeName) {
+               public static OutputType valueOfAllOkUC(String typeName, OutputType def) {
                        try {
                                return OutputType.valueOfUC(typeName);
                        } catch (Exception e) {
-                               return null;
+                               return def;
                        }
                }
        }
index 8559cf112eb34b47dd923cf14b0011c2c4ae561b..410e05e56f0cd3a05338c8d37f6633e488cbb075 100644 (file)
@@ -18,7 +18,6 @@ import be.nikiroo.fanfix.bundles.UiConfig;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.library.LocalLibrary;
-import be.nikiroo.fanfix.output.BasicOutput.OutputType;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.Version;
 import be.nikiroo.utils.ui.UIUtils;
@@ -41,33 +40,9 @@ class GuiReader extends BasicReader {
                                        "Cannote create cache directory for local reader: " + dir);
                }
 
-               OutputType text = null;
-               OutputType images = null;
-
-               try {
-                       text = OutputType.valueOfNullOkUC(Instance.getUiConfig().getString(
-                                       UiConfig.NON_IMAGES_DOCUMENT_TYPE));
-                       if (text == null) {
-                               text = OutputType.HTML;
-                       }
-
-                       images = OutputType.valueOfNullOkUC(Instance.getUiConfig()
-                                       .getString(UiConfig.IMAGES_DOCUMENT_TYPE));
-                       if (images == null) {
-                               images = OutputType.CBZ;
-                       }
-               } catch (Exception e) {
-                       UiConfig key = (text == null) ? UiConfig.NON_IMAGES_DOCUMENT_TYPE
-                                       : UiConfig.IMAGES_DOCUMENT_TYPE;
-                       String value = Instance.getUiConfig().getString(key);
-
-                       throw new IOException(
-                                       String.format(
-                                                       "The configuration option %s is not valid: %s",
-                                                       key, value), e);
-               }
-
-               localLibrary = new LocalLibrary(dir, text, images);
+               localLibrary = new LocalLibrary(dir, Instance.getUiConfig().getString(
+                               UiConfig.GUI_NON_IMAGES_DOCUMENT_TYPE), Instance.getUiConfig()
+                               .getString(UiConfig.GUI_IMAGES_DOCUMENT_TYPE), true);
        }
 
        @Override
index 782481c81a8a34104d50db0fd799b08c0bedf74a..2ae04b461d13bdd43cac911e0702190439d12cca 100644 (file)
@@ -381,18 +381,22 @@ class GuiReaderBook extends JPanel {
                BufferedImage resizedImage = null;
                String id = null;
 
-               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);
-                               }
+               String key = meta.getUuid();
+               if (key == null) {
+                       // a fake meta (a source)
+                       key = "source_" + meta.getSource();
+               }
+
+               id = key + ".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);
                        }
                }
 
@@ -426,7 +430,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;
index 041e8bc4d680eee9ffc153a2226bb0ea10dff550..a087c4c12302851cbb4fe680de1e9a7aca42d0d0 100644 (file)
@@ -7,6 +7,7 @@ import java.awt.event.MouseEvent;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.management.RuntimeErrorException;
 import javax.swing.JLabel;
 import javax.swing.JPanel;