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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Status that the Scalable Picture could have -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addStatusListener
(ScalablePictureListener listener) method to register the listening object of the status eventsstatic 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..void
createScaledPictureInThread
(int priority) method that creates the scaled image in the background in its own thread.return the filename of the original imageint
return the height of the original image or Zero if there is nonereturn the image in the original sizereturn the size of the original image or Zero if there is noneint
return the width of the original image or Zero if there is noneint
return the height of the scaled image or Zero if there is nonereturn the scaled imagereturn the scaled imagereturn the size of the scaled image or Zero if there is nonereturn the size of the scaled image as a neatly formatted text or Zero if there is noneint
return the width of the scaled image or Zero if there is nonedouble
return the current scale factorreturn the current scale size.int
The number of steps to use in scalingreturn the image in the original sizeMethod that returns the status code of the picture loading.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.void
loadPictureImd
(String sha256, File imageFile, double rotation) Loads the image on the current thread.void
removeStatusListener
(ScalablePictureListener listener) method to register the listening object of the status eventsvoid
call this method when the affine transform op is to be executed.void
sets the picture into fast scaling modevoid
setJpgQuality
(float quality) accessor method to set the quality that should be used on jpg write operations.void
sets the picture into quality scaling modevoid
setScaleFactor
(double newFactor) set the scale factor to the new desired value.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.void
setScaleSteps
(int scaleSteps) The number of steps to use in scalingvoid
sourceLoadProgressNotification
(SourcePicture.SourcePictureStatus statusCode, int percentage) pass on the update on the loading Progress to the listening objectsvoid
sourceStatusChange
(SourcePicture.SourcePictureStatus statusCode, String statusMessage, SourcePicture sp) method that is invoked by the SourcePictureListener interface.void
stopLoadingExcept
(File file) stops all picture loading except if the Url we desire is being loadedstatic void
writeJpg
(File targetFile, RenderedImage renderedImage, float jpgQuality) This static method writes the indicated renderedImage (BufferedImage) to the indicated file.static void
writeJpg
(OutputStream writeStream, RenderedImage renderedImage, float jpgQuality) This static method writes the indicated renderedImage (BufferedImage) to the indicated file.void
writeScaledJpg
(File writeFile) This method allows the ScalablePicture's scaled BufferedImage to be written to the desired file.void
writeScaledJpg
(OutputStream writeStream) This method allows the ScalablePicture's scaled BufferedImage to be written to the desired output stream.
-
Constructor Details
-
ScalablePicture
public ScalablePicture()Constructor
-
-
Method Details
-
loadAndScalePictureInThread
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 loadpriority
- The Thread priorityrotation
- The rotation 0-360 that the image should be put through after loading.
-
loadPictureImd
Loads the image on the current thread. Doesn't send status updates.- Parameters:
imageFile
- The image File to be loadedrotation
- The angle by which it is to be rotated upon loading.
-
stopLoadingExcept
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 interfaceSourcePictureListener
- Parameters:
statusCode
- status codestatusMessage
- status messagesp
- 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 interfacePictureControllerImage
- 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 dimensionsourceHeight
- the height of the original dimensionmaxWidth
- the maximum width of the output dimensionmaxHeight
- 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 callcreateScaledPictureInThread(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 interfacePictureControllerImage
- Parameters:
newFactor
- new factor
-
setScaleSize
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 interfacePictureControllerImage
- Parameters:
newSize
- new size
-
getScaleFactor
public double getScaleFactor()return the current scale factor- Specified by:
getScaleFactor
in interfacePictureControllerImage
- Returns:
- the scale factor
-
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 methodgetScaledSize
that will return the size of the picture.- Returns:
- the current scale size
-
getScaledPicture
return the scaled image- Specified by:
getScaledPicture
in interfacePictureControllerImage
- Returns:
- the scaled image
-
getScaledImageIcon
return the scaled image- Returns:
- the scaled image
-
getScaledSize
return the size of the scaled image or Zero if there is none- Returns:
- the scaled size
-
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
return the image in the original size- Returns:
- image in the original size
-
getSourcePicture
return the image in the original size- Returns:
- the original picture
-
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 interfacePictureControllerImage
- 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 interfacePictureControllerImage
- Returns:
- the original width of the image
-
getFilename
return the filename of the original image- Returns:
- the filename of the original image
-
writeScaledJpg
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
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
This static method writes the indicated renderedImage (BufferedImage) to the indicated file.- Parameters:
targetFile
- The File that shall receive the jpg datarenderedImage
- The RenderedImage (BufferedImage) to be writtenjpgQuality
- 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 datarenderedImage
- The RenderedImage (BufferedImage) to be writtenjpgQuality
- The quality with which to compress to jpg
-
addStatusListener
method to register the listening object of the status events- Parameters:
listener
- Listener
-
removeStatusListener
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 interfaceSourcePictureListener
- Parameters:
statusCode
- status codepercentage
- percentage
-
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
-