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 seperate thread.
-
-
Field Summary
Fields Modifier and Type Field Description static intERRORstatus code used to signal that there was an errorstatic intGARBAGE_COLLECTIONstatus code used to signal that the picture is cleaning up memoryURLimageUrlthe URL of the picturefloatjpgQualitythe quality with which the JPG pictures shall be written.static intLOADEDstatus code used to signal that the thread has finished loading the imagestatic intLOADINGstatus code used to signal that the thread is loading the imagestatic intREADYstatus code used to signal that the image is available.booleanscaleAfterLoadflag that indicates that the image should be scaled after a status message is received from the SourcePicture that the picture was loaded.BufferedImagescaledPictureThe scaled version of the imagestatic intSCALINGstatus code used to signal that the thread has loaded the tread is scaling the imageSourcePicturesourcePicturethe source picture for the scalable picturestatic intUNINITIALISEDstatus 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 voidaddStatusListener(ScalablePictureListener listener)method to register the listening object of the status eventsvoidcreateScaledPictureInThread(int priority)method that creates the scaled image in the background in it's own thread.StringgetFilename()return the filename of the original imageintgetOriginalHeight()return the height of the original image or Zero if there is noneBufferedImagegetOriginalImage()return the image in the original sizeDimensiongetOriginalSize()return the size of the original image or Zero if there is noneintgetOriginalWidth()return the width of the original image or Zero if there is noneintgetScaledHeight()return the height of the scaled image or Zero if there is noneBufferedImagegetScaledPicture()return the scaled imageDimensiongetScaledSize()return the size of the scaled image or Zero if there is noneStringgetScaledSizeString()return the size of the scaled image as a neatly formatted text or Zero if there is noneintgetScaledWidth()return the width of the scaled image or Zero if there is nonedoublegetScaleFactor()return the current scale factorDimensiongetScaleSize()return the current scale size.SourcePicturegetSourcePicture()return the image in the original sizeintgetStatusCode()Method that returns the status code of the picture loading.StringgetStatusMessage()Method that returns the status code of the picture loading.voidloadAndScalePictureInThread(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.voidloadPictureImd(URL imageUrl, double rotation)Synchroneous method to load the image.voidremoveStatusListener(ScalablePictureListener listener)method to register the listening object of the status eventsvoidscalePicture()voidsetJpgQuality(float quality)accessor method to set the quality that should be used on jpg write operations.voidsetScaleFactor(double newFactor)set the scale factor to the new desired value.voidsetScaleSize(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.SourcePicturesetSourcePicture(SourcePicture source)voidsourceLoadProgressNotification(int statusCode, int percentage)pass on the update on the loading Progress to the listening objectsvoidsourceStatusChange(int statusCode, String statusMessage, SourcePicture sp)method that is invoked by the SourcePictureListener interface.voidstopLoadingExcept(URL url)stops all picture loading except if the Url we desire is being loadedstatic voidwriteJpg(File writeFile, RenderedImage renderedImage, float jpgQuality)This static method writes the indicated renderedImage (BufferedImage) to the indicated file.voidwriteScaledJpg(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:
sourceStatusChangein interfaceSourcePictureListener
-
sourceLoadProgressNotification
public void sourceLoadProgressNotification(int statusCode, int percentage)pass on the update on the loading Progress to the listening objects- Specified by:
sourceLoadProgressNotificationin 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.
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 mehtodgetScaledSizethat 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.
-
-