Module org.jpo

Class ScalablePicture

java.lang.Object
org.jpo.datamodel.ScalablePicture
All Implemented Interfaces:
SourcePictureListener, PictureControllerImage

public class ScalablePicture extends Object implements SourcePictureListener, PictureControllerImage
a class to load and scale an image either immediately or in a separate thread.
  • Constructor Details

    • ScalablePicture

      public ScalablePicture()
      Constructor
  • Method Details

    • loadAndScalePictureInThread

      public void loadAndScalePictureInThread(String sha256, File file, 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 chugs 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:
      file - The URL of the image you want to load
      priority - The Thread priority
      rotation - The rotation 0-360 that the image should be put through after loading.
    • loadPictureImd

      public void loadPictureImd(String sha256, File imageFile, double rotation)
      Loads the image on the current thread. Doesn't send status updates.
      Parameters:
      imageFile - The image File to be loaded
      rotation - The angle by which it is to be rotated upon loading.
    • stopLoadingExcept

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

      public void sourceStatusChange(SourcePicture.SourcePictureStatus 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 its own status and tell the ScalableListeners what's up.
      Specified by:
      sourceStatusChange in interface SourcePictureListener
      Parameters:
      statusCode - status code
      statusMessage - status message
      sp - source picture
    • createScaledPictureInThread

      public void createScaledPictureInThread(int priority)
      method that creates the scaled image in the background in its own thread.
      Specified by:
      createScaledPictureInThread in interface PictureControllerImage
      Parameters:
      priority - The priority this image takes relative to the others.
    • scalePicture

      public void scalePicture()
      call this method when the affine transform op is to be executed.
    • calcScaleSourceToTarget

      public static double calcScaleSourceToTarget(int sourceWidth, int sourceHeight, int maxWidth, int maxHeight)
      Returns the scale factor maintaining aspect ratio to fit the source image into the target dimension..
      Parameters:
      sourceWidth - the width of the original dimension
      sourceHeight - the height of the original dimension
      maxWidth - the maximum width of the output dimension
      maxHeight - the maximum height of the output dimension
      Returns:
      The scale factor by which to multiply the source dimension
    • 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 Picture is 300 x 200

      Specified by:
      setScaleFactor in interface PictureControllerImage
      Parameters:
      newFactor - new factor
    • setScaleSize

      public void setScaleSize(Dimension newSize)
      invoke this method to tell the scale process to figure out the scale factor so that the image fits either by height or by width into the indicated dimension.
      Specified by:
      setScaleSize in interface PictureControllerImage
      Parameters:
      newSize - new size
    • getScaleFactor

      public double getScaleFactor()
      return the current scale factor
      Specified by:
      getScaleFactor in interface PictureControllerImage
      Returns:
      the scale factor
    • getScaleSize

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

      public BufferedImage getScaledPicture()
      return the scaled image
      Specified by:
      getScaledPicture in interface PictureControllerImage
      Returns:
      the scaled image
    • getScaledImageIcon

      public ImageIcon getScaledImageIcon()
      return the scaled image
      Returns:
      the scaled image
    • getScaledSize

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

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

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

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

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

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

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

      public int getOriginalHeight()
      return the height of the original image or Zero if there is none
      Specified by:
      getOriginalHeight in interface PictureControllerImage
      Returns:
      the original height of the image
    • getOriginalWidth

      public int getOriginalWidth()
      return the width of the original image or Zero if there is none
      Specified by:
      getOriginalWidth in interface PictureControllerImage
      Returns:
      the original width of the image
    • getFilename

      public String getFilename()
      return the filename of the original image
      Returns:
      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
    • writeScaledJpg

      public void writeScaledJpg(OutputStream writeStream)
      This method allows the ScalablePicture's scaled BufferedImage to be written to the desired output stream.
      Parameters:
      writeStream - The Stream that shall receive the jpg data
    • writeJpg

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

      public static void writeJpg(OutputStream writeStream, RenderedImage renderedImage, float jpgQuality)
      This static method writes the indicated renderedImage (BufferedImage) to the indicated file.
      Parameters:
      writeStream - 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
      Parameters:
      listener - Listener
    • removeStatusListener

      public void removeStatusListener(ScalablePictureListener listener)
      method to register the listening object of the status events
      Parameters:
      listener - Listener
    • sourceLoadProgressNotification

      public void sourceLoadProgressNotification(SourcePicture.SourcePictureStatus statusCode, int percentage)
      pass on the update on the loading Progress to the listening objects
      Specified by:
      sourceLoadProgressNotification in interface SourcePictureListener
      Parameters:
      statusCode - status code
      percentage - percentage
    • getStatusCode

      public ScalablePicture.ScalablePictureStatus getStatusCode()
      Method that returns the status code of the picture loading.
      Returns:
      the status code
    • setJpgQuality

      public void setJpgQuality(float quality)
      accessor method to set the quality that should be used on jpg write operations.
      Parameters:
      quality - the quality to use
    • setFastScale

      public void setFastScale()
      sets the picture into fast scaling mode
    • setQualityScale

      public void setQualityScale()
      sets the picture into quality scaling mode
    • getScaleSteps

      public int getScaleSteps()
      The number of steps to use in scaling
      Returns:
      the scaleSteps
    • setScaleSteps

      public void setScaleSteps(int scaleSteps)
      The number of steps to use in scaling
      Parameters:
      scaleSteps - the scaleSteps to set