Package ucar.nc2.ui.image
Class ScalablePicture
- java.lang.Object
-
- ucar.nc2.ui.image.ScalablePicture
-
- All Implemented Interfaces:
SourcePictureListener
public class ScalablePicture extends Object implements SourcePictureListener
a class to load and scale an image either immediately or in a separate thread.
-
-
Field Summary
Fields Modifier and Type Field Description static int
ERROR
status code used to signal that there was an errorstatic int
GARBAGE_COLLECTION
status code used to signal that the picture is cleaning up memoryURL
imageUrl
the URL of the picturefloat
jpgQuality
the quality with which the JPG pictures shall be written.static int
LOADED
status code used to signal that the thread has finished loading the imagestatic int
LOADING
status code used to signal that the thread is loading the imagestatic int
READY
status code used to signal that the image is available.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.BufferedImage
scaledPicture
The scaled version of the imagestatic int
SCALING
status code used to signal that the thread has loaded the tread is scaling the imageSourcePicture
sourcePicture
the source picture for the scalable picturestatic int
UNINITIALISED
status code used to signal that the picture is not loaded
-
Constructor Summary
Constructors Constructor Description ScalablePicture()
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addStatusListener(ScalablePictureListener listener)
method to register the listening object of the status eventsvoid
createScaledPictureInThread(int priority)
method that creates the scaled image in the background in it's own thread.String
getFilename()
return the filename of the original imageint
getOriginalHeight()
return the height of the original image or Zero if there is noneBufferedImage
getOriginalImage()
return the image in the original sizeDimension
getOriginalSize()
return the size of the original image or Zero if there is noneint
getOriginalWidth()
return the width of the original image or Zero if there is noneint
getScaledHeight()
return the height of the scaled image or Zero if there is noneBufferedImage
getScaledPicture()
return the scaled imageDimension
getScaledSize()
return the size of the scaled image or Zero if there is noneString
getScaledSizeString()
return the size of the scaled image as a neatly formatted text or Zero if there is noneint
getScaledWidth()
return the width of the scaled image or Zero if there is nonedouble
getScaleFactor()
return the current scale factorDimension
getScaleSize()
return the current scale size.SourcePicture
getSourcePicture()
return the image in the original sizeint
getStatusCode()
Method that returns the status code of the picture loading.String
getStatusMessage()
Method that returns the status code of the picture loading.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.void
loadPictureImd(URL imageUrl, double rotation)
Synchroneous method to load the image.void
removeStatusListener(ScalablePictureListener listener)
method to register the listening object of the status eventsvoid
scalePicture()
void
setJpgQuality(float quality)
accessor method to set the quality that should be used on jpg write operations.void
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 scal factor so that the image fits either by height or by width into the indicated dimension.SourcePicture
setSourcePicture(SourcePicture source)
void
sourceLoadProgressNotification(int statusCode, int percentage)
pass on the update on the loading Progress to the listening objectsvoid
sourceStatusChange(int statusCode, String statusMessage, SourcePicture sp)
method that is invoked by the SourcePictureListener interface.void
stopLoadingExcept(URL url)
stops all picture loading except if the Url we desire is being loadedstatic void
writeJpg(File writeFile, 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.
-
-
-
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.
-
-
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 priorityimageUrl
- The URL of the image you want to loadrotation
- 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 loadedrotation
- 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 interfaceSourcePictureListener
-
sourceLoadProgressNotification
public void sourceLoadProgressNotification(int statusCode, int percentage)
pass on the update on the loading Progress to the listening objects- Specified by:
sourceLoadProgressNotification
in interfaceSourcePictureListener
-
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 callcreateScaledPictureInThread(int)
to make anything happen.
-
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 mehtodgetScaledSize
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
-
setSourcePicture
public SourcePicture setSourcePicture(SourcePicture source)
-
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 datarenderedImage
- The RenderedImage (BufferedImage) to be writtenjpgQuality
- 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.
-
-