Class SourcePicture

  • All Implemented Interfaces:
    Cloneable

    public class SourcePicture
    extends Object
    implements Cloneable
    a class to load and scale a picture either immediately or in a separate thread from a URL
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int ERROR
      status code used to signal that there was an error
      protected ucar.nc2.ui.image.SourcePicture.ImageProgressListener imageProgressListener
      reference to the inner class that listens to the image loading progress
      static int LOADING
      status code used to signal that the thread is loading the image
      static int LOADING_COMPLETED
      status code used to tell that we have a finished loading but only used on notifySourceLoadProgressListeners
      static int LOADING_PROGRESS
      status code used to tell that we have a progress update but only used on notifySourceLoadProgressListeners
      static int LOADING_STARTED
      status code used to tell that we have started loading an image but only used on notifySourceLoadProgressListeners
      static int READY
      status code used to signal that the rotated image is available.
      static int ROTATING
      status code used to signal that the thread is rotating the image
      BufferedImage sourcePictureBufferedImage
      the Buffered Image that this class protects and provides features for.
      static int UNINITIALISED
      status code used to signal that the picture is not loaded
    • Field Detail

      • UNINITIALISED

        public static final int UNINITIALISED
        status code used to signal that the picture is not loaded
        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
      • ROTATING

        public static final int ROTATING
        status code used to signal that the thread is rotating the image
        See Also:
        Constant Field Values
      • READY

        public static final int READY
        status code used to signal that the rotated 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
      • LOADING_STARTED

        public static final int LOADING_STARTED
        status code used to tell that we have started loading an image but only used on notifySourceLoadProgressListeners
        See Also:
        Constant Field Values
      • LOADING_PROGRESS

        public static final int LOADING_PROGRESS
        status code used to tell that we have a progress update but only used on notifySourceLoadProgressListeners
        See Also:
        Constant Field Values
      • LOADING_COMPLETED

        public static final int LOADING_COMPLETED
        status code used to tell that we have a finished loading but only used on notifySourceLoadProgressListeners
        See Also:
        Constant Field Values
      • sourcePictureBufferedImage

        public BufferedImage sourcePictureBufferedImage
        the Buffered Image that this class protects and provides features for.
      • imageProgressListener

        protected ucar.nc2.ui.image.SourcePicture.ImageProgressListener imageProgressListener
        reference to the inner class that listens to the image loading progress
    • Method Detail

      • loadPictureInThread

        public void loadPictureInThread​(URL imageUrl,
                                        int priority,
                                        double rotation)
        method to invoke with a filename or URL of a picture that is to be loaded a new thread. This is handy to update the screen while the loading chuggs along in the background.
        Parameters:
        imageUrl - The URL of the image to be loaded
        priority - The Thread priority for this thread.
        rotation - The rotation 0-360 to be used on this picture
      • loadPicture

        public void loadPicture​(URL imageUrl,
                                double rotation)
        method to invoke with a filename or URL of a picture that is to be loaded in the main thread.
      • loadPicture

        public void loadPicture()
        loads a picture from the URL in the imageUrl object into the sourcePictureBufferedImage object and updates the status when done or failed.
      • stopLoading

        public void stopLoading()
        this method can be invoked to stop the current reader
      • stopLoadingExcept

        public boolean stopLoadingExcept​(URL exemptionURL)
        this method can be invoked to stop the current reader except if it is reading the desired file. It returns true is the desired file is being loaded. Otherwise it returns false.
      • getSize

        public Dimension getSize()
        return the size of the image or Zero if there is none
      • getHeight

        public int getHeight()
        return the height of the image or Zero if there is none
      • getWidth

        public int getWidth()
        return the width of the image or Zero if there is none
      • getUrlString

        public String getUrlString()
        return the URL of the original image as a string
      • getUrl

        public URL getUrl()
        return the URL of the original image
      • getRotation

        public double getRotation()
        return the rotation of the image
      • addListener

        public void addListener​(SourcePictureListener listener)
        method to register the listening object of the status events
      • removeListener

        public void removeListener​(SourcePictureListener listener)
        method to register the listening object of the status events
      • showListeners

        public void showListeners()
      • hasNoListeners

        public boolean hasNoListeners()
        method that says whether there are any listeners attached to this object
      • 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.
      • getPercentLoaded

        public int getPercentLoaded()
        Returns how much of the image has been loaded
      • getSourceBufferedImage

        public BufferedImage getSourceBufferedImage()
        returns the buffered image that was loaded or null if there is no image.
        Returns:
        the BufferedImage that was loaded or null if there is no image.
      • setSourceBufferedImage

        public void setSourceBufferedImage​(BufferedImage img,
                                           String statusMessage)
        sets the buffered image. Unusual method use with care.
      • getSourcePicture

        public SourcePicture getSourcePicture()
        returns a reference to this SourcePicture object
        Returns:
        the reference to this SourcePicture object
      • clone

        public Object clone()
        creates a copy of the SourcePicture
        Overrides:
        clone in class Object