org.corpstein.image
Class ChartFactory

java.lang.Object
  extended by org.corpstein.image.ChartFactory

public class ChartFactory
extends java.lang.Object

Creates chart images and write them to files using common encodings. ChartFactory relies on the helper classes ChartData, ChartStyle, and ChartMetrics to encapsulate all of the parameters related to a chart. Since ChartFactory follows the Singleton pattern, all constructors are private. To obtain a ChartFactory, use the static getInstance method.

Version:
$Revision: 1.4 $ $Date: 2005/04/24 20:46:54 $
Author:
David Corpstein

Method Summary
 boolean canReadFormat(java.lang.String format)
          Returns true if a there exists a registered ImageReader that can decode the specified format
 boolean canWriteFormat(java.lang.String format)
          Returns true if there exists a registered ImageWriter that can encode the specified format
 java.awt.Image createBarChart(ChartData data)
          Creates a bar chart based on the specified ChartData.
 java.awt.Image createBarChart(ChartData data, ChartStyle style)
          Creates a bar chart based on the specified ChartData and ChartStyle.
 java.awt.Image createBarChart(ChartData data, ChartStyle style, ChartMetrics metrics)
          Creates a bar chart based on the specified ChartData, ChartStyle, and ChartMetrics.
 java.awt.Image createChart(ChartData data, ChartStyle style)
          Creates a chart based on the specified ChartData and ChartStyle.
 java.awt.Image createChart(ChartData data, ChartStyle style, ChartMetrics metrics)
          Creates a chart based on the specified ChartData, ChartStyle, and ChartMetrics.
 java.awt.Image createLineChart(ChartData data)
          Creates a line chart based on the specified ChartData
 java.awt.Image createLineChart(ChartData data, ChartStyle style)
          Creates a line chart based on the specified ChartData and ChartStyle
 java.awt.Image createLineChart(ChartData data, ChartStyle style, ChartMetrics metrics)
          Creates a line chart based on the specified ChartData, ChartStyle, and ChartMetrics
 java.awt.Image createPieChart(ChartData data)
          Creates a pie chart based on the specified ChartData and default ChartStyle and ChartMetrics
 java.awt.Image createPieChart(ChartData data, ChartStyle style)
          Creates a pie chart based on the specified ChartData and ChartStyle using default ChartMetrics
 java.awt.Image createPieChart(ChartData data, ChartStyle style, ChartMetrics metrics)
          Creates a pie chart based on the specified ChartData, ChartStyle, and ChartMetrics
static ChartFactory getInstance()
          If a ChartFactory is not already allocated, create it.
 void writeImage(java.awt.Image image, java.lang.String filename)
          Writes the specified image to the file specified using the file extension to determine the image format
 void writeImage(java.awt.Image image, java.lang.String format, java.lang.String filename)
          Writes the specified image to the file and format specified
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

canReadFormat

public boolean canReadFormat(java.lang.String format)
Returns true if a there exists a registered ImageReader that can decode the specified format

Parameters:
format - String The image format to use (png, jpeg, tiff, etc.)
Returns:
true if an ImageReader exists for the specified format

canWriteFormat

public boolean canWriteFormat(java.lang.String format)
Returns true if there exists a registered ImageWriter that can encode the specified format

Parameters:
format - The image format to use (png, jpeg, tiff, etc.)
Returns:
true if an ImageWriter exists for the specified format

createBarChart

public java.awt.Image createBarChart(ChartData data)
Creates a bar chart based on the specified ChartData. Uses the default ChartStyle and ChartMetrics objects since none are specified.

Parameters:
data - A ChartData object containing the chart title, labels and values to be used
Returns:
A bar chart based on the specified ChartData

createBarChart

public java.awt.Image createBarChart(ChartData data,
                                     ChartStyle style)
Creates a bar chart based on the specified ChartData and ChartStyle. Uses the default ChartMetrics since none are specified.

Parameters:
data - A ChartData object containing the chart title, labels and values to be used
style - A ChartStyle object containing the color and style options to be used
Returns:
A bar chart based on the specified parameters

createBarChart

public java.awt.Image createBarChart(ChartData data,
                                     ChartStyle style,
                                     ChartMetrics metrics)
Creates a bar chart based on the specified ChartData, ChartStyle, and ChartMetrics.

Parameters:
data - A ChartData object containing the chart title, labels and values to be used
style - A ChartStyle object containing the color and style options to be used
metrics - A ChartMetrics object overriding the specific sizes, distances, offsets, etc. to be used
Returns:
A bar chart based on the specified parameters

createChart

public java.awt.Image createChart(ChartData data,
                                  ChartStyle style)
Creates a chart based on the specified ChartData and ChartStyle. The type of chart (bar, line, etc.) is determined by the ChartStyle object.

Parameters:
data - A ChartData object containing the chart title, labels and values to be used
style - A ChartStyle object containing the color and style options to be used
Returns:
A chart based on the specified parameters

createChart

public java.awt.Image createChart(ChartData data,
                                  ChartStyle style,
                                  ChartMetrics metrics)
Creates a chart based on the specified ChartData, ChartStyle, and ChartMetrics. The type of chart (bar, line, etc.) is determined by the ChartStyle object.

Parameters:
data - A ChartData object containing the chart title, labels and values to be used
style - A ChartStyle object containing the color and style options to be used
metrics - A ChartMetrics object overriding the specific sizes, distances, offsets, etc. to be used
Returns:
A chart based on the specified parameters

createLineChart

public java.awt.Image createLineChart(ChartData data)
Creates a line chart based on the specified ChartData

Parameters:
data - A ChartData object containing the chart title, labels and values to be used
Returns:
A line chart based on the specified ChartData

createLineChart

public java.awt.Image createLineChart(ChartData data,
                                      ChartStyle style)
Creates a line chart based on the specified ChartData and ChartStyle

Parameters:
data - A ChartData object containing the chart title, labels and values to be used
style - A ChartStyle object containing the color and style options to be used
Returns:
A line chart based on the specified parameters

createLineChart

public java.awt.Image createLineChart(ChartData data,
                                      ChartStyle style,
                                      ChartMetrics metrics)
Creates a line chart based on the specified ChartData, ChartStyle, and ChartMetrics

Parameters:
data - A ChartData object containing the chart title, labels and values to be used
style - A ChartStyle object containing the color and style options to be used
metrics - A ChartMetrics object overriding the specific sizes, distances, offsets, etc. to be used
Returns:
A line chart based on the specified parameters

createPieChart

public java.awt.Image createPieChart(ChartData data)
Creates a pie chart based on the specified ChartData and default ChartStyle and ChartMetrics

Parameters:
data - A ChartData object containing the chart title, labels and values to be used
Returns:
A pie chart based on the specified parameters

createPieChart

public java.awt.Image createPieChart(ChartData data,
                                     ChartStyle style)
Creates a pie chart based on the specified ChartData and ChartStyle using default ChartMetrics

Parameters:
data - A ChartData object containing the chart title, labels and values to be used
style - A ChartStyle object containing the color and style options to be used
Returns:
A pie chart based on the specified parameters

createPieChart

public java.awt.Image createPieChart(ChartData data,
                                     ChartStyle style,
                                     ChartMetrics metrics)
Creates a pie chart based on the specified ChartData, ChartStyle, and ChartMetrics

Parameters:
data - A ChartData object containing the chart title, labels and values to be used
style - A ChartStyle object containing the color and style options to be used
metrics - A ChartMetrics object overriding the specific sizes, distances, offsets, etc. to be used
Returns:
A pie chart based on the specified parameters

getInstance

public static ChartFactory getInstance()
If a ChartFactory is not already allocated, create it. Then return the instance to the caller. As part of the Singleton pattern, this ensures that only 1 instance of the object exists.

Returns:
a ChartFactory instance

writeImage

public void writeImage(java.awt.Image image,
                       java.lang.String filename)
                throws java.io.IOException
Writes the specified image to the file specified using the file extension to determine the image format

Parameters:
image - The image to write
filename - The filename to use
Throws:
java.io.IOException - if unable to write to the specified file

writeImage

public void writeImage(java.awt.Image image,
                       java.lang.String format,
                       java.lang.String filename)
                throws java.io.IOException
Writes the specified image to the file and format specified

Parameters:
image - java.awt.Image The image to write
format - String The image format to use (png, jpeg, tiff, etc.)
filename - String The filename to use
Throws:
java.io.IOException - if unable to write to the specified file


Last update: 20050424 1651