com.ngs.image
Class ImageModel

java.lang.Object
  extended by com.ngs.image.ImageModel

public class ImageModel
extends Object

Controller / Model for manipulation of BufferedImages provided by an ImageSource.

Author:
Bryan.Varner

Field Summary
static int FIT_BOTH
           
static int FIT_HEIGHT
           
static int FIT_NONE
           
static int FIT_WIDTH
           
 
Constructor Summary
ImageModel()
          Creates a new ImageModel with a small thread pool for handling manipulation commands asynchronously, and no ImageSource.
ImageModel(ImageSource source)
          Constructs a new ImageModel for controlling the given ImageSource.
 
Method Summary
 void addImageListener(ImageEventListener iel)
          Adds an ImageEventListener to inform interested parties that a specific type of event has occurred.
 void addRotation(int degrees)
          Adds the number of degrees to the current rotation.
 void adjustBrightness(int by)
          Adjusts the current brightness value by the given increment.
 void adjustContrast(float by)
          Adds the given increment to the current contrast value.
 void clearClip()
          Removes the current clip if there is one.
 void error(String message)
          Handles an error occurring from a source.
 BufferedImage extendRender(BufferedImage image)
          ImageModel subclasses can override this method to extend the rendering process.
 int getBrightness()
          Gets the current brightness value.
 Rectangle getClip()
          Retrieves the current clip bounds if we in sub-clip mode.
 float getContrast()
          Gets the current contrast value.
 int getFitMode()
          Gets the fitMode
 BufferedImage getImage()
          Gets the current BufferedImage to be rendered by a view for this model.
 int getImageCount()
          Forwards the request to the ImageSource.
 int getImagePage()
          Gets which image from the given ImageSource is currently being made available for render.
 Dimension getPageSize()
          Gets the dimension of the current page, scaled by the current scale factor.
 Dimension getPageSize(Dimension d)
          Gets the dimension of the current page, scaled by the current scale factor.
 int getRotation()
          Gets the current rotation in degrees
 float getScale()
          Gets the scale.
 ImageSource getSource()
          Gets the ImageSource for this ImageModel
 AffineTransform getTransform()
           
 void invert()
          Tells the model to render the image with all colors inverted.
 boolean isInverted()
          Returns weather or not this instance is going to invert the image.
 void nextPage()
          Moves to the next image.
 BufferedImage preRender(BufferedImage image)
          ImageModel subclasses can override this method to extend the rendering process.
 void prevPage()
          Moves to the previous Image.
 void queueRender()
          Places a new entry into the render Queue.
 void removeImageListener(ImageEventListener iel)
          Removes an ImageEventListener used to inform interested parties that a specific type of event has occurred.
 void removeSource()
          Removes the source that's currently in use.
 void render()
          Immediately re-render and fire an event when done.
 void scaleBy(float factor)
          Scales the Current scale factor by the given amount.
 void setBrightness(int offset)
          Sets the Brightness.
 void setClip(Rectangle rect)
          Otherwise, we clear the scale and go to full page rendering mode.
 void setContrast(float contrast)
          Sets the current contrast value.
 void setFitMode(Rectangle rect, int fitMode)
          Sets the fit mode
 void setImagePage(int page)
          Sets the current image to be rendered to the given index into the current ImageSource.
 void setRotation(int degrees)
          Sets the rotation to the given degrees If the combined rotation is > 360, we automatically subtract 360, so that the calculated radians remain within the 0 - 360 degree equivalent range.
 void setScale(float scale)
          Sets the scale factor for rendering the current Image.
 void setScale(float scalex, float scaley)
          Sets the scale factor for rendering the current Image.
 void setSource(ImageSource source)
          Sets the ImageSource for this ImageModel to use when retrieving images
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIT_NONE

public static final int FIT_NONE
See Also:
Constant Field Values

FIT_WIDTH

public static final int FIT_WIDTH
See Also:
Constant Field Values

FIT_HEIGHT

public static final int FIT_HEIGHT
See Also:
Constant Field Values

FIT_BOTH

public static final int FIT_BOTH
See Also:
Constant Field Values
Constructor Detail

ImageModel

public ImageModel()
Creates a new ImageModel with a small thread pool for handling manipulation commands asynchronously, and no ImageSource.


ImageModel

public ImageModel(ImageSource source)
Constructs a new ImageModel for controlling the given ImageSource.

Method Detail

getImage

public BufferedImage getImage()
Gets the current BufferedImage to be rendered by a view for this model.


addImageListener

public void addImageListener(ImageEventListener iel)
Adds an ImageEventListener to inform interested parties that a specific type of event has occurred.


removeImageListener

public void removeImageListener(ImageEventListener iel)
Removes an ImageEventListener used to inform interested parties that a specific type of event has occurred.


setSource

public void setSource(ImageSource source)
Sets the ImageSource for this ImageModel to use when retrieving images


getSource

public ImageSource getSource()
Gets the ImageSource for this ImageModel


removeSource

public void removeSource()
Removes the source that's currently in use.


setClip

public void setClip(Rectangle rect)
Otherwise, we clear the scale and go to full page rendering mode.


setFitMode

public void setFitMode(Rectangle rect,
                       int fitMode)
Sets the fit mode


getFitMode

public int getFitMode()
Gets the fitMode


getClip

public Rectangle getClip()
Retrieves the current clip bounds if we in sub-clip mode.


clearClip

public void clearClip()
Removes the current clip if there is one.


getPageSize

public Dimension getPageSize()
Gets the dimension of the current page, scaled by the current scale factor.


getPageSize

public Dimension getPageSize(Dimension d)
Gets the dimension of the current page, scaled by the current scale factor. Mutates the dimension provided prior to returning.


error

public void error(String message)
Handles an error occurring from a source.


getImageCount

public int getImageCount()
Forwards the request to the ImageSource.


setImagePage

public void setImagePage(int page)
Sets the current image to be rendered to the given index into the current ImageSource.


getImagePage

public int getImagePage()
Gets which image from the given ImageSource is currently being made available for render.


nextPage

public void nextPage()
Moves to the next image.


prevPage

public void prevPage()
Moves to the previous Image.


setRotation

public void setRotation(int degrees)
Sets the rotation to the given degrees If the combined rotation is > 360, we automatically subtract 360, so that the calculated radians remain within the 0 - 360 degree equivalent range.


getRotation

public int getRotation()
Gets the current rotation in degrees


addRotation

public void addRotation(int degrees)
Adds the number of degrees to the current rotation. To rotate clockwise, add 90. To rotate counter-clockwise, add -90.


setScale

public void setScale(float scalex,
                     float scaley)
Sets the scale factor for rendering the current Image.


setScale

public void setScale(float scale)
Sets the scale factor for rendering the current Image.


scaleBy

public void scaleBy(float factor)
Scales the Current scale factor by the given amount.


getScale

public float getScale()
Gets the scale.


setBrightness

public void setBrightness(int offset)
Sets the Brightness. Default is 0. Negative & positive numbers are acceptable.


adjustBrightness

public void adjustBrightness(int by)
Adjusts the current brightness value by the given increment.


getBrightness

public int getBrightness()
Gets the current brightness value.


setContrast

public void setContrast(float contrast)
Sets the current contrast value. the default is 1.0 (float). Valid values are anything > 0.


adjustContrast

public void adjustContrast(float by)
Adds the given increment to the current contrast value.


getContrast

public float getContrast()
Gets the current contrast value.


invert

public void invert()
Tells the model to render the image with all colors inverted.


isInverted

public boolean isInverted()
Returns weather or not this instance is going to invert the image.


preRender

public BufferedImage preRender(BufferedImage image)
ImageModel subclasses can override this method to extend the rendering process. This method is invoked prior to any clipping, rotation, scaling, or rescaling occurs.


extendRender

public BufferedImage extendRender(BufferedImage image)
ImageModel subclasses can override this method to extend the rendering process. Note that all clipping, rotation, and rescaling occurs -before- this method is called.


getTransform

public AffineTransform getTransform()

queueRender

public void queueRender()
Places a new entry into the render Queue.


render

public void render()
Immediately re-render and fire an event when done. This is a blocking operation, and should -not- be executed in the AWT Event thread.