org.corpstein.image
Class ChartStyle

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

public class ChartStyle
extends java.lang.Object

Encapsulates the style elements (colors, fonts, etc) needed to create a chart using ChartFactory.

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

Field Summary
static int CHART_TYPE_BAR
           
static int CHART_TYPE_LINE
           
static int CHART_TYPE_PIE
           
static int COLOR_BACKGROUND
           
static int COLOR_EDGE
           
static int COLOR_LABEL
           
static int COLOR_SHADOW
           
static int COLOR_WALL
           
static int DEFAULT_CHART_TYPE
           
static java.awt.Font DEFAULT_KEY_FONT
           
static int DEFAULT_KEY_FONT_MINIMUM_SIZE
           
static java.lang.String DEFAULT_KEY_FONT_NAME
           
static int DEFAULT_KEY_FONT_SIZE
           
static int DEFAULT_KEY_FONT_STYLE
           
static int DEFAULT_KEY_TYPE
           
static java.awt.Font DEFAULT_LABEL_FONT
           
static java.lang.String DEFAULT_LABEL_FONT_NAME
           
static int DEFAULT_LABEL_FONT_SIZE
           
static int DEFAULT_LABEL_FONT_STYLE
           
static int DEFAULT_POINT_MARK_SIZE
           
static java.awt.Font DEFAULT_SCALE_FONT
           
static int DEFAULT_SCALE_FONT_MINIMUM_SIZE
           
static java.lang.String DEFAULT_SCALE_FONT_NAME
           
static int DEFAULT_SCALE_FONT_SIZE
           
static int DEFAULT_SCALE_FONT_STYLE
           
static boolean DEFAULT_SHOW_POINT_MARKS
           
static java.awt.Font DEFAULT_TITLE_FONT
           
static int DEFAULT_TITLE_FONT_MINIMUM_SIZE
           
static java.lang.String DEFAULT_TITLE_FONT_NAME
           
static int DEFAULT_TITLE_FONT_SIZE
           
static int DEFAULT_TITLE_FONT_STYLE
           
static int KEY_TYPE_BAR_COLOR_ASSOCIATION
           
static int KEY_TYPE_DIAGONAL_BAR_LABELS
           
static int KEY_TYPE_HORIZONTAL_BAR_LABELS
           
static int MAX_BARS
           
static int MAX_COLUMNS
           
static int MAX_LINES
           
static float MINIMUM_LABEL_ALPHA
           
 
Constructor Summary
ChartStyle()
          Sole constructor.
 
Method Summary
 void addLayer(Layer layer)
           
 java.awt.Paint getBarPaint(int column)
          Returns the Paint of the bar for the specified column
 boolean getBorderEnabled()
          Returns true if the chart border is enabled
 int getChartType()
          Returns the chart type of the ChartStyle object
 int getImageHeight()
          Returns the image height in pixels
 int getImageWidth()
          Returns the image width in pixels
 java.awt.Font getKeyFont()
          Returns the Font used for the chart key
 int getKeyFontMinimumSize()
          Returns the minimum size allowed for the key font
 int getKeyType()
          Returns the type of key used for the chart
 java.awt.Font getLabelFont()
          Returns the Font used for the chart labels
 Layer getLayer(java.lang.String key)
          Returns the layer with the given key
 java.util.Iterator getLayerIterator()
          Returns an iterator of keys that can be used to loop through the layers
 java.awt.Paint getPaint(int attribute)
          Returns the Paint of the specified attribute
 float[] getPaintValues(int attribute)
          Returns an array of float containing the individual RGB values for the paint of the specified attribute
 int getPointMarkSize()
          Returns the size of the point marks for the chart
 java.awt.Font getScaleFont()
          Returns the Font used for the chart scale
 boolean getShowPointMarks()
          Returns true if point marks are enabled for the chart
 java.awt.Font getTitleFont()
          Returns the Font used for the chart title
 int getTitleFontMinimumSize()
          Returns the minimum size allowed for the title font
 boolean getValueLabelsEnabled()
          Returns true if value labels are enabled for the chart
 void prepareKey(ChartData data, ChartMetrics metrics)
          Validates the font to be used for the chart labels.
 void prepareKeyType(ChartData data)
          Validates that the key type matches the chart data.
 void prepareLabelKey(ChartData data, ChartMetrics metrics)
          Validates the font to be used for the chart key.
 void prepareScale(java.lang.String label)
          Validates the font to be used for the chart scale.
 void prepareStyle(ChartData data, ChartMetrics metrics)
          Prepares the title, key, and key type
 java.lang.String prepareTitle(java.lang.String oldTitle)
          Validates the font to be used for the chart title.
 void setBarPaint(int column, java.awt.Paint paint)
          Sets the bar Paint for the specific column.
 void setBarPaint(java.awt.Paint paint)
          Sets the bar paint for all columns.
 void setBorderEnabled(boolean isBorderEnabled)
          Sets the border enabled attribute for the chart
 void setChartType(int type)
          Sets the chart type to the specified type
 void setKeyFont(java.awt.Font font)
          Sets the key font to the specified Font
 void setKeyFontMinimumSize(int size)
          Sets the minimum font size for chart keys
 void setKeyType(int keyType)
          Sets the key type to one of KEY_TYPE_BAR_COLOR_ASSOCIATION, KEY_TYPE_DIAGONAL_BAR_LABELS, or KEY_TYPE_HORIZONTAL_BAR_LABELS
 void setLabelFont(java.awt.Font font)
          Sets the Font to use for chart labels
 void setPaint(int attribute, java.awt.Paint paint)
          Sets the specified attribute to the paint parameter.
 void setPointMarkSize(int pointMarkSize)
          Sets the size of the chart point marks
 void setScaleFont(java.awt.Font font)
          Sets the Font to use for the chart scale
 void setShowPointMarks(boolean showPointMarks)
          Sets whether to show point marks in line charts
 void setTitleFont(java.awt.Font font)
          Sets the Font to use for the chart title
 void setTitleFontMinimumSize(int size)
          Sets the minimum size to use for the title font
 void setValueLabelsEnabled(boolean isValueLabelsEnabled)
          Sets whether to enable value labels
 java.lang.String toString()
          Creates and returns a String describing all of the contents of the ChartStyle object for debugging use
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CHART_TYPE_BAR

public static final int CHART_TYPE_BAR
See Also:
Constant Field Values

CHART_TYPE_LINE

public static final int CHART_TYPE_LINE
See Also:
Constant Field Values

CHART_TYPE_PIE

public static final int CHART_TYPE_PIE
See Also:
Constant Field Values

DEFAULT_CHART_TYPE

public static final int DEFAULT_CHART_TYPE
See Also:
Constant Field Values

DEFAULT_SHOW_POINT_MARKS

public static final boolean DEFAULT_SHOW_POINT_MARKS
See Also:
Constant Field Values

DEFAULT_POINT_MARK_SIZE

public static final int DEFAULT_POINT_MARK_SIZE
See Also:
Constant Field Values

COLOR_LABEL

public static final int COLOR_LABEL
See Also:
Constant Field Values

COLOR_SHADOW

public static final int COLOR_SHADOW
See Also:
Constant Field Values

COLOR_BACKGROUND

public static final int COLOR_BACKGROUND
See Also:
Constant Field Values

COLOR_WALL

public static final int COLOR_WALL
See Also:
Constant Field Values

COLOR_EDGE

public static final int COLOR_EDGE
See Also:
Constant Field Values

MAX_COLUMNS

public static final int MAX_COLUMNS
See Also:
Constant Field Values

MAX_LINES

public static final int MAX_LINES
See Also:
Constant Field Values

MAX_BARS

public static final int MAX_BARS
See Also:
Constant Field Values

DEFAULT_KEY_FONT_NAME

public static final java.lang.String DEFAULT_KEY_FONT_NAME
See Also:
Constant Field Values

DEFAULT_KEY_FONT_SIZE

public static final int DEFAULT_KEY_FONT_SIZE
See Also:
Constant Field Values

DEFAULT_KEY_FONT_STYLE

public static final int DEFAULT_KEY_FONT_STYLE
See Also:
Constant Field Values

DEFAULT_KEY_FONT

public static final java.awt.Font DEFAULT_KEY_FONT

DEFAULT_LABEL_FONT_NAME

public static final java.lang.String DEFAULT_LABEL_FONT_NAME
See Also:
Constant Field Values

DEFAULT_LABEL_FONT_SIZE

public static final int DEFAULT_LABEL_FONT_SIZE
See Also:
Constant Field Values

DEFAULT_LABEL_FONT_STYLE

public static final int DEFAULT_LABEL_FONT_STYLE
See Also:
Constant Field Values

DEFAULT_LABEL_FONT

public static final java.awt.Font DEFAULT_LABEL_FONT

DEFAULT_SCALE_FONT_NAME

public static final java.lang.String DEFAULT_SCALE_FONT_NAME
See Also:
Constant Field Values

DEFAULT_SCALE_FONT_SIZE

public static final int DEFAULT_SCALE_FONT_SIZE
See Also:
Constant Field Values

DEFAULT_SCALE_FONT_STYLE

public static final int DEFAULT_SCALE_FONT_STYLE
See Also:
Constant Field Values

DEFAULT_SCALE_FONT

public static final java.awt.Font DEFAULT_SCALE_FONT

DEFAULT_TITLE_FONT_NAME

public static final java.lang.String DEFAULT_TITLE_FONT_NAME
See Also:
Constant Field Values

DEFAULT_TITLE_FONT_SIZE

public static final int DEFAULT_TITLE_FONT_SIZE
See Also:
Constant Field Values

DEFAULT_TITLE_FONT_STYLE

public static final int DEFAULT_TITLE_FONT_STYLE
See Also:
Constant Field Values

DEFAULT_TITLE_FONT

public static final java.awt.Font DEFAULT_TITLE_FONT

DEFAULT_KEY_FONT_MINIMUM_SIZE

public static final int DEFAULT_KEY_FONT_MINIMUM_SIZE
See Also:
Constant Field Values

DEFAULT_SCALE_FONT_MINIMUM_SIZE

public static final int DEFAULT_SCALE_FONT_MINIMUM_SIZE
See Also:
Constant Field Values

DEFAULT_TITLE_FONT_MINIMUM_SIZE

public static final int DEFAULT_TITLE_FONT_MINIMUM_SIZE
See Also:
Constant Field Values

MINIMUM_LABEL_ALPHA

public static final float MINIMUM_LABEL_ALPHA
See Also:
Constant Field Values

KEY_TYPE_BAR_COLOR_ASSOCIATION

public static final int KEY_TYPE_BAR_COLOR_ASSOCIATION
See Also:
Constant Field Values

KEY_TYPE_DIAGONAL_BAR_LABELS

public static final int KEY_TYPE_DIAGONAL_BAR_LABELS
See Also:
Constant Field Values

KEY_TYPE_HORIZONTAL_BAR_LABELS

public static final int KEY_TYPE_HORIZONTAL_BAR_LABELS
See Also:
Constant Field Values

DEFAULT_KEY_TYPE

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

ChartStyle

public ChartStyle()
Sole constructor. Sets the values to defaults

Method Detail

addLayer

public void addLayer(Layer layer)

getBarPaint

public java.awt.Paint getBarPaint(int column)
Returns the Paint of the bar for the specified column

Parameters:
column - The column of the bar in question
Returns:
The Paint of the bar
Throws:
java.lang.IllegalArgumentException - if the column value is out of bounds

getBorderEnabled

public boolean getBorderEnabled()
Returns true if the chart border is enabled

Returns:
true if the chart border is enabled

getPaint

public java.awt.Paint getPaint(int attribute)
Returns the Paint of the specified attribute

Parameters:
attribute - The attribute in question
Returns:
The paint of the attribute
Throws:
java.lang.IllegalArgumentException - if the attribute parameter is out of bounds

getPaintValues

public float[] getPaintValues(int attribute)
Returns an array of float containing the individual RGB values for the paint of the specified attribute

Parameters:
attribute - The attribute in question
Returns:
An array of float containing the individual RGB values
Throws:
java.lang.IllegalArgumentException - if attribute value is out of bounds

getChartType

public int getChartType()
Returns the chart type of the ChartStyle object

Returns:
the chart type

getImageHeight

public int getImageHeight()
Returns the image height in pixels

Returns:
the image height

getImageWidth

public int getImageWidth()
Returns the image width in pixels

Returns:
the image width

getKeyFont

public java.awt.Font getKeyFont()
Returns the Font used for the chart key

Returns:
the Font used for the chart key

getKeyFontMinimumSize

public int getKeyFontMinimumSize()
Returns the minimum size allowed for the key font

Returns:
the minimum size allowed for the key font

getKeyType

public int getKeyType()
Returns the type of key used for the chart

Returns:
the type of key used for the chart

getLayer

public Layer getLayer(java.lang.String key)
Returns the layer with the given key

Returns:
the layer with the given key

getLayerIterator

public java.util.Iterator getLayerIterator()
Returns an iterator of keys that can be used to loop through the layers

Returns:
an iterator for the layers key set

getLabelFont

public java.awt.Font getLabelFont()
Returns the Font used for the chart labels

Returns:
the Font used for the chart labels

getPointMarkSize

public int getPointMarkSize()
Returns the size of the point marks for the chart

Returns:
the size of the point marks for the chart

getScaleFont

public java.awt.Font getScaleFont()
Returns the Font used for the chart scale

Returns:
the Font used for the chart scale

getShowPointMarks

public boolean getShowPointMarks()
Returns true if point marks are enabled for the chart

Returns:
true if point marks are enabled for the chart

getTitleFont

public java.awt.Font getTitleFont()
Returns the Font used for the chart title

Returns:
the Font used for the chart title

getTitleFontMinimumSize

public int getTitleFontMinimumSize()
Returns the minimum size allowed for the title font

Returns:
the minimum size allowed for the title font

getValueLabelsEnabled

public boolean getValueLabelsEnabled()
Returns true if value labels are enabled for the chart

Returns:
true if value labels are enabled for the chart

prepareKey

public void prepareKey(ChartData data,
                       ChartMetrics metrics)
Validates the font to be used for the chart labels. If any of the labels are too long to fit within the max label width, decrements the key font as much as is necessary but never less than the key font minimum size. If the labels are still too long, updates the ChartData object with truncated label Strings.

Parameters:
data - The ChartData object that contains the label values
metrics - The ChartMetrics object that contains the max label width

prepareLabelKey

public void prepareLabelKey(ChartData data,
                            ChartMetrics metrics)
Validates the font to be used for the chart key. If any of the key labels are too long to fit within the max label width, decrements the key font as much as is necessary but never less than the key font minimum size. If the labels are still too long, updates the ChartData object with truncated key label Strings.

Parameters:
data - The ChartData object that contains the label values
metrics - The ChartMetrics object that contains the max label width

prepareKeyType

public void prepareKeyType(ChartData data)
Validates that the key type matches the chart data. Charts that have multiple values per column do not support the key type KEY_TYPE_BAR_COLOR_ASSOCIATION.

Parameters:
data - The ChartData object that contains the total values per column
Throws:
java.lang.IllegalStateException - if the key type does not match the chart data

prepareScale

public void prepareScale(java.lang.String label)
Validates the font to be used for the chart scale. If any of the scale labels are too long to fit within the max scale label width, decrements the scale font as much as is necessary but never less than the scale label font minimum size.


prepareStyle

public void prepareStyle(ChartData data,
                         ChartMetrics metrics)
Prepares the title, key, and key type

Parameters:
data - The ChartData object that contains the data for the chart
metrics - The ChartMetrics object that contains the metrics for the chart

prepareTitle

public java.lang.String prepareTitle(java.lang.String oldTitle)
Validates the font to be used for the chart title. If the title is too long to fit within the title area, decrements the title font as much as is necessary but never less than the image width. If the title is still too long, truncates the title as much as is necessary.

Parameters:
oldTitle - The title for the chart

setBarPaint

public void setBarPaint(int column,
                        java.awt.Paint paint)
Sets the bar Paint for the specific column.

Parameters:
column - The column in question
paint - The paint to use
Throws:
java.lang.IllegalArgumentException - if the specified paint is null or the column parameter is out of bounds

setBarPaint

public void setBarPaint(java.awt.Paint paint)
Sets the bar paint for all columns.

Parameters:
paint - The Paint to use
Throws:
java.lang.IllegalArgumentException - if the paint parameter is null

setBorderEnabled

public void setBorderEnabled(boolean isBorderEnabled)
Sets the border enabled attribute for the chart

Parameters:
isBorderEnabled - The new value for the border enabled attribute

setPaint

public void setPaint(int attribute,
                     java.awt.Paint paint)
Sets the specified attribute to the paint parameter.

Parameters:
attribute - The attribute in question
paint - The Paint to use
Throws:
java.lang.IllegalArgumentException - if the paint parameter is null or if the attribute is out of range

setChartType

public void setChartType(int type)
Sets the chart type to the specified type

Parameters:
type - The chart type to use
Throws:
java.lang.IllegalArgumentException - if the chart type is out of bounds

setKeyFont

public void setKeyFont(java.awt.Font font)
Sets the key font to the specified Font

Parameters:
font - The Font to use
Throws:
java.lang.IllegalArgumentException - if the specified font is null

setKeyFontMinimumSize

public void setKeyFontMinimumSize(int size)
Sets the minimum font size for chart keys

Parameters:
size - The size to use
Throws:
java.lang.IllegalArgumentException - if the size is less than 1

setKeyType

public void setKeyType(int keyType)
Sets the key type to one of KEY_TYPE_BAR_COLOR_ASSOCIATION, KEY_TYPE_DIAGONAL_BAR_LABELS, or KEY_TYPE_HORIZONTAL_BAR_LABELS

Parameters:
keyType - The key type to use
Throws:
java.lang.IllegalArgumentException - if the key type is invalid

setLabelFont

public void setLabelFont(java.awt.Font font)
Sets the Font to use for chart labels

Parameters:
font - The Font to use
Throws:
java.lang.IllegalArgumentException - if the font is null

setPointMarkSize

public void setPointMarkSize(int pointMarkSize)
Sets the size of the chart point marks

Parameters:
pointMarkSize - The size to use
Throws:
java.lang.IllegalArgumentException - if the size is less than 1

setScaleFont

public void setScaleFont(java.awt.Font font)
Sets the Font to use for the chart scale

Parameters:
font - The Font to use
Throws:
java.lang.IllegalArgumentException - if the font is null

setTitleFont

public void setTitleFont(java.awt.Font font)
Sets the Font to use for the chart title

Parameters:
font - The Font to use
Throws:
java.lang.IllegalArgumentException - if the font is null

setShowPointMarks

public void setShowPointMarks(boolean showPointMarks)
Sets whether to show point marks in line charts

Parameters:
showPointMarks - the value to use

setTitleFontMinimumSize

public void setTitleFontMinimumSize(int size)
Sets the minimum size to use for the title font

Parameters:
size - The size to use
Throws:
java.lang.IllegalArgumentException - if the size is less than 1

setValueLabelsEnabled

public void setValueLabelsEnabled(boolean isValueLabelsEnabled)
Sets whether to enable value labels

Parameters:
isValueLabelsEnabled - The value to use

toString

public java.lang.String toString()
Creates and returns a String describing all of the contents of the ChartStyle object for debugging use

Overrides:
toString in class java.lang.Object
Returns:
a String describing all of the contents of the ChartStyle object


Last update: 20050424 1651