Class ImageLoaderCache


  • class ImageLoaderCache
    extends java.util.Dictionary<java.lang.String,​java.awt.Image>
    This class is a trick to get the JEditorKit to load its images from the epub file instead of from the given url. This class is installed as the JEditorPane's image cache. Whenever it is requested an image it will try to load that image from the epub. Can be shared by multiple documents but can only be used by one document at the time because of the currentFolder issue.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears the image cache.
      private java.awt.Image createImage​(Resource imageResource)
      Create an Image from the data of the given resource.
      java.util.Enumeration<java.awt.Image> elements()  
      java.awt.Image get​(java.lang.Object key)  
      private java.lang.String getResourceHref​(java.lang.String requestUrl)  
      void initBook​(Book book)  
      void initImageLoader​(javax.swing.text.html.HTMLDocument document)  
      boolean isEmpty()  
      java.util.Enumeration<java.lang.String> keys()  
      java.awt.Image put​(java.lang.String key, java.awt.Image value)  
      java.awt.Image remove​(java.lang.Object key)  
      void setContextResource​(Resource resource)  
      int size()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • IMAGE_URL_PREFIX

        public static final java.lang.String IMAGE_URL_PREFIX
        See Also:
        Constant Field Values
      • log

        private static final org.slf4j.Logger log
      • cache

        private java.util.Map<java.lang.String,​java.awt.Image> cache
      • book

        private Book book
      • currentFolder

        private java.lang.String currentFolder
    • Constructor Detail

      • ImageLoaderCache

        public ImageLoaderCache​(Navigator navigator)
    • Method Detail

      • initBook

        public void initBook​(Book book)
      • setContextResource

        public void setContextResource​(Resource resource)
      • initImageLoader

        public void initImageLoader​(javax.swing.text.html.HTMLDocument document)
      • getResourceHref

        private java.lang.String getResourceHref​(java.lang.String requestUrl)
      • createImage

        private java.awt.Image createImage​(Resource imageResource)
        Create an Image from the data of the given resource.
        Parameters:
        imageResource -
        Returns:
      • get

        public java.awt.Image get​(java.lang.Object key)
        Specified by:
        get in class java.util.Dictionary<java.lang.String,​java.awt.Image>
      • size

        public int size()
        Specified by:
        size in class java.util.Dictionary<java.lang.String,​java.awt.Image>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in class java.util.Dictionary<java.lang.String,​java.awt.Image>
      • keys

        public java.util.Enumeration<java.lang.String> keys()
        Specified by:
        keys in class java.util.Dictionary<java.lang.String,​java.awt.Image>
      • elements

        public java.util.Enumeration<java.awt.Image> elements()
        Specified by:
        elements in class java.util.Dictionary<java.lang.String,​java.awt.Image>
      • put

        public java.awt.Image put​(java.lang.String key,
                                  java.awt.Image value)
        Specified by:
        put in class java.util.Dictionary<java.lang.String,​java.awt.Image>
      • remove

        public java.awt.Image remove​(java.lang.Object key)
        Specified by:
        remove in class java.util.Dictionary<java.lang.String,​java.awt.Image>
      • clear

        public void clear()
        Clears the image cache.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object