Class ScalablePicture

    • Field Detail

      • sourcePicture

        public SourcePicture sourcePicture
        the source picture for the scalable picture
      • scaledPicture

        public BufferedImage scaledPicture
        The scaled version of the image
      • imageUrl

        public URL imageUrl
        the URL of the picture
      • UNINITIALISED

        public static final int UNINITIALISED
        status code used to signal that the picture is not loaded
        See Also:
        Constant Field Values
      • GARBAGE_COLLECTION

        public static final int GARBAGE_COLLECTION
        status code used to signal that the picture is cleaning up memory
        See Also:
        Constant Field Values
      • LOADING

        public static final int LOADING
        status code used to signal that the thread is loading the image
        See Also:
        Constant Field Values
      • LOADED

        public static final int LOADED
        status code used to signal that the thread has finished loading the image
        See Also:
        Constant Field Values
      • SCALING

        public static final int SCALING
        status code used to signal that the thread has loaded the tread is scaling the image
        See Also:
        Constant Field Values
      • READY

        public static final int READY
        status code used to signal that the image is available.
        See Also:
        Constant Field Values
      • ERROR

        public static final int ERROR
        status code used to signal that there was an error
        See Also:
        Constant Field Values
      • jpgQuality

        public float jpgQuality
        the quality with which the JPG pictures shall be written. 0 means poor 1 means great.
      • scaleAfterLoad

        public boolean scaleAfterLoad
        flag that indicates that the image should be scaled after a status message is received from the SourcePicture that the picture was loaded.
    • Constructor Detail

      • ScalablePicture

        public ScalablePicture()
        Constructor
    • Method Detail

      • loadAndScalePictureInThread

        public void loadAndScalePictureInThread​(URL imageUrl,
                                                int priority,
                                                double rotation)
        method to invoke with a filename or URL of a picture that is to be loaded and scaled in a new thread. This is handy to update the screen while the loading chuggs along in the background. Make sure you invoked setScaleFactor or setScaleSize before invoking this method.

        Step 1: Am I already loading what I need somewhere? If yes -> use it. Has it finished loading? If no -> wait for it If yes -> use it Else -> load it

        Parameters:
        priority - The Thread priority
        imageUrl - The URL of the image you want to load
        rotation - The rotation 0-360 that the image should be put through after loading.
      • loadPictureImd

        public void loadPictureImd​(URL imageUrl,
                                   double rotation)
        Synchroneous method to load the image. It should only be called by something which is a thread itself such as the HtmlDistillerThread. Since this intended for large batch operations this bypasses the cache.
        Parameters:
        imageUrl - The Url of the image to be loaded
        rotation - The angle by which it is to be roated upon loading.
      • stopLoadingExcept

        public void stopLoadingExcept​(URL url)
        stops all picture loading except if the Url we desire is being loaded
        Parameters:
        url - The URL of the image which is to be loaded.
      • sourceStatusChange

        public void sourceStatusChange​(int statusCode,
                                       String statusMessage,
                                       SourcePicture sp)
        method that is invoked by the SourcePictureListener interface. Usually this will be called by the SourcePicture telling the ScalablePicture that it has completed loading. The ScalablePicture should then change it's own status and tell the ScalableListeners what's up.
        Specified by:
        sourceStatusChange in interface SourcePictureListener
      • sourceLoadProgressNotification

        public void sourceLoadProgressNotification​(int statusCode,
                                                   int percentage)
        pass on the update on the loading Progress to the listening objects
        Specified by:
        sourceLoadProgressNotification in interface SourcePictureListener
      • createScaledPictureInThread

        public void createScaledPictureInThread​(int priority)
        method that creates the scaled image in the background in it's own thread.
        Parameters:
        priority - The priority this image takes relative to the others.
      • scalePicture

        public void scalePicture()
      • setScaleFactor

        public void setScaleFactor​(double newFactor)
        set the scale factor to the new desired value. The scale factor is a multiplier by which the original picture needs to be multiplied to get the size of the picture on the screen. You must call createScaledPictureInThread(int) to make anything happen.

        Example: Original is 3000 x 2000 --> Scale Factor 0.10 --> Target Picutre is 300 x 200

      • setScaleSize

        public void setScaleSize​(Dimension newSize)
        invoke this method to tell the scale process to figure out the scal factor so that the image fits either by height or by width into the indicated dimension.
      • getScaleFactor

        public double getScaleFactor()
        return the current scale factor
      • getScaleSize

        public Dimension getScaleSize()
        return the current scale size. This is the area that the picture ist fitted into. Since the are could be wider or taller than the picture will be scaled to there is a different mehtod getScaledSize that will return the size of the picture.
      • getScaledPicture

        public BufferedImage getScaledPicture()
        return the scaled image
      • getScaledSize

        public Dimension getScaledSize()
        return the size of the scaled image or Zero if there is none
      • getScaledSizeString

        public String getScaledSizeString()
        return the size of the scaled image as a neatly formatted text or Zero if there is none
      • getScaledHeight

        public int getScaledHeight()
        return the height of the scaled image or Zero if there is none
      • getScaledWidth

        public int getScaledWidth()
        return the width of the scaled image or Zero if there is none
      • getOriginalImage

        public BufferedImage getOriginalImage()
        return the image in the original size
      • getSourcePicture

        public SourcePicture getSourcePicture()
        return the image in the original size
      • getOriginalSize

        public Dimension getOriginalSize()
        return the size of the original image or Zero if there is none
      • getOriginalHeight

        public int getOriginalHeight()
        return the height of the original image or Zero if there is none
      • getOriginalWidth

        public int getOriginalWidth()
        return the width of the original image or Zero if there is none
      • getFilename

        public String getFilename()
        return the filename of the original image
      • writeScaledJpg

        public void writeScaledJpg​(File writeFile)
        This method allows the ScalablePicture's scaled BufferedImage to be written to the desired file.
        Parameters:
        writeFile - The File that shall receive the jpg data
      • writeJpg

        public static void writeJpg​(File writeFile,
                                    RenderedImage renderedImage,
                                    float jpgQuality)
        This static method writes the indicated renderedImage (BufferedImage) to the indicated file.
        Parameters:
        writeFile - The File that shall receive the jpg data
        renderedImage - The RenderedImage (BufferedImage) to be written
        jpgQuality - The quality with which to compress to jpg
      • addStatusListener

        public void addStatusListener​(ScalablePictureListener listener)
        method to register the listening object of the status events
      • removeStatusListener

        public void removeStatusListener​(ScalablePictureListener listener)
        method to register the listening object of the status events
      • getStatusCode

        public int getStatusCode()
        Method that returns the status code of the picture loading.
      • getStatusMessage

        public String getStatusMessage()
        Method that returns the status code of the picture loading.
      • setJpgQuality

        public void setJpgQuality​(float quality)
        accessor method to set the quality that should be used on jpg write operations.