org.foray.graphic
Class Graphic4a

java.lang.Object
  extended by org.foray.graphic.Graphic4a
All Implemented Interfaces:
org.axsl.graphic.Graphic
Direct Known Subclasses:
BMPGraphic, EPSGraphic, GIFGraphic, JPEGGraphic, MathGraphic4a, PDFGraphic, PNGGraphic, SVGGraphic, TIFFGraphic

public abstract class Graphic4a
extends Object
implements org.axsl.graphic.Graphic

Abstract base class for graphics.

Author:
Eric Schaeffer, Eric Dalquist

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.axsl.graphic.Graphic
org.axsl.graphic.Graphic.Compression, org.axsl.graphic.Graphic.Type
 
Field Summary
static byte BIT_DEPTH_4
          The bit depth (bits per pixel) for a 4-bit image.
static byte BIT_DEPTH_COLOR
          The bit depth (bits per pixel) for a typical 3-channel color image.
static byte BIT_DEPTH_GRAYSCALE
          The bit depth (bits per pixel) for an 8-bit image.
static byte BIT_DEPTH_MONOCHROME
          The bit depth (bits per pixel) for a monochrome image.
 
Constructor Summary
Graphic4a(GraphicServer4a server, URL url, BufferedInputStream bis)
          Constructor.
 
Method Summary
 int absoluteHeight(int pixelsPerInch)
           
abstract  int absoluteHeightReal()
          Returns the absolute height, in millipoints, of the graphic.
 int absoluteWidth(int pixelsPerInch)
           
abstract  int absoluteWidthReal()
          Returns the absolute width, in millipoints, of the graphic.
 boolean canMakeGraphicOutput(String mimeType)
           
 void close()
           
 int getBitDepth()
          Returns the bit depth for this graphic.
 int getBitsPerComponent()
           
 byte[] getContent()
           
 int getContentSize()
           
 org.axsl.graphic.output.GraphicOutput getGraphicOutput(String mimeType)
           
 InputStream getInputStream()
          Returns the input stream for this file.
 GraphicLink4a[] getLinks()
          Returns the links associated with this graphic.
 org.apache.commons.logging.Log getLogger()
          Returns the logger.
 ColorSpace getRawColorSpace()
          Returns the color space without throwing any exceptions.
 GraphicServer4a getServer()
          Return the server.
 URL getUrl()
           
 boolean isImageLoaded()
          Indicates whether the image has been loaded.
 boolean isValid()
          Indicates whether this graphic is valid.
protected abstract  void loadImage()
          Load image data and initialize its properties.
protected  void loadImageWrapper()
          Wrapper for the loadImage method which takes care of some housekeeping chores before and after.
protected  int maxBytesToParseBasics()
          Tells parseBasicsWrapper() how large to set the readlimit value when marking the beginning of the stream, so that is can be reused.
protected abstract  void parseBasics()
          This abstract method is implemented in subclasses to initiate parsing of enough of the image for it to be used in layout.
protected  void parseBasicsWrapper()
          This method handles some of the common housekeeping work for parseBasics() so that it can focus on parsing.
protected  void setBasicsParsed(boolean basicsParsed)
          Allows subclasses to set the "basics parsed" flag if they have already parsed the basics.
 void setBitDepth(int bitDepth)
          Sets the bit depth for this graphic.
 void setContent(byte[] content)
          Sets the content for this graphic.
 void setImageLoaded(boolean imageLoaded)
          Sets the "image loaded" value.
 void setInputStream(InputStream inputStream)
          Sets the input stream for this file.
protected  void setLinks(GraphicLink4a[] links)
          Sets the links for this graphic.
 void setValid(boolean isValid)
          Sets the validity of this graphic.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.axsl.graphic.Graphic
getColorSpace, getCompressionType, getGraphicType, getMimeType, getName, getRawSamples, getTransparentColor, isInverted, isTransparent, pixelHeight, pixelWidth
 

Field Detail

BIT_DEPTH_MONOCHROME

public static final byte BIT_DEPTH_MONOCHROME
The bit depth (bits per pixel) for a monochrome image.

See Also:
Constant Field Values

BIT_DEPTH_4

public static final byte BIT_DEPTH_4
The bit depth (bits per pixel) for a 4-bit image.

See Also:
Constant Field Values

BIT_DEPTH_GRAYSCALE

public static final byte BIT_DEPTH_GRAYSCALE
The bit depth (bits per pixel) for an 8-bit image.

See Also:
Constant Field Values

BIT_DEPTH_COLOR

public static final byte BIT_DEPTH_COLOR
The bit depth (bits per pixel) for a typical 3-channel color image.

See Also:
Constant Field Values
Constructor Detail

Graphic4a

public Graphic4a(GraphicServer4a server,
                 URL url,
                 BufferedInputStream bis)
Constructor.

Parameters:
server - The parent graphic server.
url - The URL which contains the graphic content.
bis - The reusable input stream containing the bytes from url.
Method Detail

getUrl

public URL getUrl()
Specified by:
getUrl in interface org.axsl.graphic.Graphic

getBitsPerComponent

public int getBitsPerComponent()
                        throws org.axsl.graphic.GraphicException
Specified by:
getBitsPerComponent in interface org.axsl.graphic.Graphic
Throws:
org.axsl.graphic.GraphicException

getContent

public byte[] getContent()
                  throws org.axsl.graphic.GraphicException
Specified by:
getContent in interface org.axsl.graphic.Graphic
Throws:
org.axsl.graphic.GraphicException

getContentSize

public int getContentSize()
                   throws org.axsl.graphic.GraphicException
Specified by:
getContentSize in interface org.axsl.graphic.Graphic
Throws:
org.axsl.graphic.GraphicException

close

public void close()
Specified by:
close in interface org.axsl.graphic.Graphic

loadImageWrapper

protected void loadImageWrapper()
                         throws org.axsl.graphic.GraphicException
Wrapper for the loadImage method which takes care of some housekeeping chores before and after.

Throws:
org.axsl.graphic.GraphicException - For errors during load of image.

loadImage

protected abstract void loadImage()
                           throws org.axsl.graphic.GraphicException
Load image data and initialize its properties. Subclasses need to implement this method.

Throws:
org.axsl.graphic.GraphicException - an error occured during loading

getLogger

public org.apache.commons.logging.Log getLogger()
Returns the logger.

Returns:
The logger.

parseBasicsWrapper

protected void parseBasicsWrapper()
                           throws org.axsl.graphic.GraphicException

This method handles some of the common housekeeping work for parseBasics() so that it can focus on parsing. Specifically, this method is responsible to:

Throws:
org.axsl.graphic.GraphicException - For any unrecoverable problems during parsing.

parseBasics

protected abstract void parseBasics()
                             throws IOException

This abstract method is implemented in subclasses to initiate parsing of enough of the image for it to be used in layout. This method is responsible to:

  1. store the image's intrinsic width in Graphic.pixelWidth()
  2. store the image's intrinsic height in Graphic.pixelHeight()

The housekeeping work related to resetting the buffer, handling IOExceptions, and managing whether this method should be run are handled elsewhere. In short, this method does not need to address the details handled there.

Throws:
IOException - For IO errors during reading of the file.

maxBytesToParseBasics

protected int maxBytesToParseBasics()
Tells parseBasicsWrapper() how large to set the readlimit value when marking the beginning of the stream, so that is can be reused. The default value is 1024. Subclasses that need to read more than this amount when parsing the basics from the stream should override this method and return a higher amount. Otherwise, subsequent attempts to use the stream will result in i/o errors.

Returns:
The maximum number of bytes that might need to be read from the stream to be able to parse the basics.

absoluteWidth

public final int absoluteWidth(int pixelsPerInch)
                        throws org.axsl.graphic.GraphicException
Specified by:
absoluteWidth in interface org.axsl.graphic.Graphic
Throws:
org.axsl.graphic.GraphicException

absoluteWidthReal

public abstract int absoluteWidthReal()
                               throws org.axsl.graphic.GraphicException
Returns the absolute width, in millipoints, of the graphic.

Returns:
The absolute width, in millipoints, of this graphic, if known. If not known, returns -1.
Throws:
org.axsl.graphic.GraphicException - For errors during reading of image file.

absoluteHeight

public final int absoluteHeight(int pixelsPerInch)
                         throws org.axsl.graphic.GraphicException
Specified by:
absoluteHeight in interface org.axsl.graphic.Graphic
Throws:
org.axsl.graphic.GraphicException

absoluteHeightReal

public abstract int absoluteHeightReal()
                                throws org.axsl.graphic.GraphicException
Returns the absolute height, in millipoints, of the graphic.

Returns:
The absolute height, in millipoints, of this graphic, if known. If not known, returns -1.
Throws:
org.axsl.graphic.GraphicException - For errors during reading of image file.

getServer

public GraphicServer4a getServer()
Return the server.

Returns:
Returns the server.

isValid

public boolean isValid()
Indicates whether this graphic is valid.

Returns:
Returns true iff this graphic is valid.

setValid

public void setValid(boolean isValid)
Sets the validity of this graphic.

Parameters:
isValid - The new validity value.

isImageLoaded

public boolean isImageLoaded()
Indicates whether the image has been loaded.

Returns:
Returns true iff the image has been loaded.

setImageLoaded

public void setImageLoaded(boolean imageLoaded)
Sets the "image loaded" value.

Parameters:
imageLoaded - The new "image loaded" value.

setContent

public void setContent(byte[] content)
Sets the content for this graphic.

Parameters:
content - The new content.

setBitDepth

public void setBitDepth(int bitDepth)
Sets the bit depth for this graphic.

Parameters:
bitDepth - The new bit depth.

getBitDepth

public int getBitDepth()
Returns the bit depth for this graphic.

Returns:
The bit depth for this graphic.

getRawColorSpace

public ColorSpace getRawColorSpace()
Returns the color space without throwing any exceptions.

Returns:
The color space.
See Also:
Graphic.getColorSpace()

getInputStream

public InputStream getInputStream()
Returns the input stream for this file.

Returns:
Returns the input stream.

setInputStream

public void setInputStream(InputStream inputStream)
Sets the input stream for this file.

Parameters:
inputStream - The new input stream.

setBasicsParsed

protected void setBasicsParsed(boolean basicsParsed)
Allows subclasses to set the "basics parsed" flag if they have already parsed the basics.

Parameters:
basicsParsed - Set to true to indicate that the basics have already been parsed and do not need to be parsed again.

getLinks

public GraphicLink4a[] getLinks()
Returns the links associated with this graphic.

Specified by:
getLinks in interface org.axsl.graphic.Graphic
Returns:
The links associated with this graphic.

setLinks

protected void setLinks(GraphicLink4a[] links)
Sets the links for this graphic.

Parameters:
links - The new array of links for this graphic.

getGraphicOutput

public org.axsl.graphic.output.GraphicOutput getGraphicOutput(String mimeType)
Specified by:
getGraphicOutput in interface org.axsl.graphic.Graphic

canMakeGraphicOutput

public boolean canMakeGraphicOutput(String mimeType)
Specified by:
canMakeGraphicOutput in interface org.axsl.graphic.Graphic


Copyright © 2017. All rights reserved.