All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.objectplanet.chart.Chart

java.lang.Object
   |
   +----java.awt.Component
           |
           +----com.objectplanet.chart.Chart

public abstract class Chart
extends Component
implements ItemSelectable
This class is the abstract superclass of all charts. Any chart contains a set of samples, where each sample has a value and a label. The type and look of the chart is up to the subclass to decide.

For each sample in a chart, you can set the following attributes:

For the chart itself you can set the following:

Author:
Bjorn J. Kvande.

Variable Index

 o BOTTOM
Bottom legend position.
 o LEFT
Left legend position.
 o RIGHT
Right legend position.
 o TOP
Top legend position.

Constructor Index

 o Chart(int)
Creates a chart with the given number of samples and no title.

Method Index

 o addItemListener(ItemListener)
Adds an item listener to the chart.
 o checkSelection(Point)
This method is called when the user releases the mouse and checks if the given point is inside a sample.
 o clearSelection()
Clears the selection of any chart sample.
 o getChartBackground()
Gets the color of the chart background itself.
 o getChartForeground()
Gets the color of the chart foreground itself.
 o getFloatMaxValue()
Gets the largest value in the chart as a floating point.
 o getFloatMinValue()
Gets the smallest value in the chart as a floating point.
 o getFloatSampleValue(int)
Gets the value at the given index as a floating point.
 o getFloatSampleValues()
Gets the sample values as a floating point array.
 o getGraphBounds(String[])
This method returns the bounding box around the chart itself.
 o getLegendPosition()
Gets the legend position.
 o getMaxValue()
Gets the largest value in the chart.
 o getMinimumSize()
This method returns the minimum size of the chart.
 o getMinValue()
Gets the smallest value in the chart.
 o getPreferredSize()
This method is called by the awt, and returns the preferred size of the chart.
 o getSample(int)
Gets the specified sample.
 o getSample(Object)
Gets the sample with the given key.
 o getSampleColor(int)
Gets the color of the specified sample.
 o getSampleColors()
Gets the array of colors used for the samples.
 o getSampleCount()
Gets the number of samples in the chart.
 o getSampleDecimalCount()
Gets the number of decimals used for the sample values.
 o getSampleLabel(int)
Gets the label of the specified sample.
 o getSampleLabelColor(int)
Gets the color of the label of the specified sample.
 o getSampleLabels()
Gets the sample labels as an array of strings.
 o getSamples()
Gets the samples of the chart.
 o getSampleValue(int)
Gets the value at the given index.
 o getSampleValues()
Gets the sample values as an array of values.
 o getSelectedObjects()
Gets the currently selected objects.
 o getTitle()
Gets the chart title.
 o getTitleFont()
Returns the font used for the title.
 o getVersion()
Returns the current version of the charts.
 o is3DModeOn()
Checks if the 3D mode is turned on.
 o isFrameOn()
Checks if the 3D looking frame around the chart is on.
 o isLegendOn()
Checks if the legend is turned on.
 o isTitleOn()
Checks if the title is turned on.
 o isValueLabelsOn()
Checks if the value labels are turned on.
 o main(String[])
Prints out the current version number.
 o paint(Graphics)
This method is overridden to paint the chart using double buffering.
 o removeItemListener(ItemListener)
Removes the specified item listener from the chart.
 o render(Graphics)
This method is called by paint(), and has to be implemented by the subclass to render the chart.
 o set3DModeOn(boolean)
Turns on or off 3D look of the chart.
 o setChartBackground(Color)
Sets the background color of the chart itself.
 o setChartForeground(Color)
Sets the foreground color of the chart itself.
 o setFrameOn(boolean)
Turns on or off the 3D looking frame around the chart.
 o setLegendOn(boolean)
Turns on or off the label legend.
 o setLegendPosition(int)
Sets the legend position.
 o setSample(int, ChartSample)
Sets the specified sample.
 o setSample(int, double, String, Object)
Sets the specified sample.
 o setSampleColor(int, Color)
Sets the color of the specified sample.
 o setSampleColors(Color[])
Sets the sample colors.
 o setSampleCount(int)
Sets the number of samples for the chart.
 o setSampleDecimalCount(int)
Sets the number of decimals in the sample values.
 o setSampleLabel(int, String)
Sets the label of the specified sample.
 o setSampleLabelColor(int, Color)
Sets the color of of the label for the specified sample.
 o setSampleLabels(String[])
Sets the labels for the samples.
 o setSamples(ChartSample[])
Sets the samples of the chart to be the specified samples.
 o setSampleValue(int, double)
Sets the value of the given sample.
 o setSampleValues(double[])
Sets the sample values using a double array.
 o setSampleValues(long[])
Sets the sample values using a long array.
 o setTitle(String)
Sets the chart title.
 o setTitleFont(Font)
Sets the font used for the title.
 o setTitleOn(boolean)
Turns on or off the chart title.
 o setTrackSelectionOn(boolean)
Turns on or off chart sample selection tracking.
 o setValueLabelsOn(boolean)
Turns on or off the value labels.
 o toString()
Returns the title of the chart.
 o update(Graphics)
This method is overridden to avoid flicker when the chart is repainted.

Variables

 o LEFT
 public static final int LEFT
Left legend position.

 o RIGHT
 public static final int RIGHT
Right legend position.

 o TOP
 public static final int TOP
Top legend position.

 o BOTTOM
 public static final int BOTTOM
Bottom legend position.

Constructors

 o Chart
 public Chart(int count)
Creates a chart with the given number of samples and no title.

Parameters:
count - The number of samples for the chart.

Methods

 o setSample
 public synchronized void setSample(int index,
                                    ChartSample sample)
Sets the specified sample. Not implemented yet.

Parameters:
index - The index of the sample (0-based).
sample - The sample to set.
 o setSample
 public synchronized void setSample(int index,
                                    double value,
                                    String label,
                                    Object key)
Sets the specified sample. Each sample consists of a value, label, and a unique key used to look up the sample.

Parameters:
index - The index of the sample (0-based).
value - The value of the sample.
label - The label of the sample, or null for no label.
key - The key of the sample, or null for no key.
See Also:
getSample, getSample
 o setSamples
 public void setSamples(ChartSample samples[])
Sets the samples of the chart to be the specified samples. Not implemented yet.

Parameters:
samples - The samples of the chart.
 o getSamples
 public ChartSample[] getSamples()
Gets the samples of the chart.

Returns:
An array of the chart samples.
 o getSample
 public synchronized ChartSample getSample(int index)
Gets the specified sample.

Parameters:
index - The index of the sample to get (0-based).
See Also:
setSample
 o getSample
 public synchronized ChartSample getSample(Object key)
Gets the sample with the given key.

Parameters:
key - The key of the sample to get.
Returns:
The sample with the key, or null if no sample has that key.
See Also:
setSample
 o setSampleCount
 public synchronized void setSampleCount(int count)
Sets the number of samples for the chart. If the number of samples are less than the current count, the samples with index larger than the new count is discarded. If the new count is larger then the current, new samples are created and initialized to zero.

Parameters:
count - The number of samples.
See Also:
getSampleCount
 o getSampleCount
 public synchronized int getSampleCount()
Gets the number of samples in the chart.

See Also:
setSampleCount
 o setSampleValues
 public synchronized void setSampleValues(long values[])
Sets the sample values using a long array. If the chart contains more samples than the number of values that are passed in, any trailing sample values will be set to null.

Parameters:
values - The values in an array.
See Also:
setSampleValue
 o setSampleValues
 public synchronized void setSampleValues(double values[])
Sets the sample values using a double array. If the chart contains more samples than the number of values that are passed in, any trailing sample values will be set to null.

Parameters:
values - The values in an array.
See Also:
setSampleValue
 o getSampleValues
 public long[] getSampleValues()
Gets the sample values as an array of values. Any samples in the chart that has not had a value set yet (it is null), will return a sample value of 0.

Returns:
An array containing integer values from the chart.
 o getFloatSampleValues
 public double[] getFloatSampleValues()
Gets the sample values as a floating point array. Any samples in the chart that has not had a value set yet (it is null), will return a sample value of 0.

Returns:
An array containing floating point values from the chart.
 o setSampleValue
 public synchronized void setSampleValue(int sample,
                                         double value)
Sets the value of the given sample.

Parameters:
sample - The number of the sample (0-based).
value - The value to set for the sample.
Throws: IndexOutOfBoundsException
if the sample number is not valid.
See Also:
setSampleValues
 o getSampleValue
 public long getSampleValue(int index)
Gets the value at the given index.

Parameters:
index - The index of the sample.
Throws: IndexOutOfBoundsException
if the sample number is not valid.
 o getFloatSampleValue
 public double getFloatSampleValue(int index)
Gets the value at the given index as a floating point.

Parameters:
index - The index of the sample.
Throws: IndexOutOfBoundsException
if the sample number is not valid.
 o setSampleDecimalCount
 public void setSampleDecimalCount(int count)
Sets the number of decimals in the sample values. The default value is 0.

Parameters:
count - The number of decimals to use.
 o getSampleDecimalCount
 public int getSampleDecimalCount()
Gets the number of decimals used for the sample values.

 o setSampleLabels
 public synchronized void setSampleLabels(String labels[])
Sets the labels for the samples. The labels are given as an array where the first label is the label of the first sample and so on.

Parameters:
labels - The labels as a string array.
See Also:
setSampleLabel
 o getSampleLabels
 public String[] getSampleLabels()
Gets the sample labels as an array of strings.

Returns:
A string array containing the labels.
 o setSampleLabel
 public synchronized void setSampleLabel(int sample,
                                         String label)
Sets the label of the specified sample.

Parameters:
sample - The number of the sample (0-based).
label - The label to use for the sample.
See Also:
setSampleLabels, getSampleLabel
 o getSampleLabel
 public synchronized String getSampleLabel(int index)
Gets the label of the specified sample.

Parameters:
index - The number of the sample (0-based).
Throws: IndexOutOfBoundsException
if the sample number is not valid.
See Also:
setSampleLabel
 o setSampleLabelColor
 public synchronized void setSampleLabelColor(int sample,
                                              Color color)
Sets the color of of the label for the specified sample. The label will be displayed in the legend with this color. Default coloe is black. This is not the color of the sample itself.

Parameters:
sample - The index of the sample (0-based).
color - The color to use, null for the default color.
 o getSampleLabelColor
 public Color getSampleLabelColor(int index)
Gets the color of the label of the specified sample.

Parameters:
index - The index of the sample (0-based).
 o setTitle
 public void setTitle(String title)
Sets the chart title. The chart title is displayed at the chart's top.

Parameters:
title - The title to set.
See Also:
getTitle, setTitleOn
 o getTitle
 public String getTitle()
Gets the chart title.

See Also:
setTitle
 o setTitleFont
 public void setTitleFont(Font font)
Sets the font used for the title.

Parameters:
font - The font to use.
 o getTitleFont
 public Font getTitleFont()
Returns the font used for the title.

 o setTitleOn
 public void setTitleOn(boolean on)
Turns on or off the chart title. The chart title is displayed at the top of the chart.

Parameters:
on - True for on, false for off.
See Also:
setTitle
 o isTitleOn
 public boolean isTitleOn()
Checks if the title is turned on.

Returns:
True if on, false if off.
 o setLegendPosition
 public void setLegendPosition(int position)
Sets the legend position. The legend can be displayed at the top, bottom, left, or right side of the chart.

Parameters:
position - TOP, BOTTOM, LEFT, or RIGHT.
 o getLegendPosition
 public int getLegendPosition()
Gets the legend position.

Returns:
TOP, BOTTOM, LEFT, or RIGHT.
 o setLegendOn
 public void setLegendOn(boolean on)
Turns on or off the label legend. The label legend displays the label for each of the samples with each sample keyed by its color code. The legend can be displayed on the top, bottom, left, or right of the chart.

Parameters:
on - True if the legend should be displayed.
See Also:
setLegendPosition
 o isLegendOn
 public boolean isLegendOn()
Checks if the legend is turned on.

Returns:
True for on, false for off.
 o setValueLabelsOn
 public void setValueLabelsOn(boolean on)
Turns on or off the value labels. The value labels display the value for each of the sample in the chart.

Parameters:
on - True for on, false for off.
See Also:
setSampleValue, setSampleValues
 o isValueLabelsOn
 public boolean isValueLabelsOn()
Checks if the value labels are turned on.

Returns:
True for on, false for off.
 o set3DModeOn
 public void set3DModeOn(boolean on)
Turns on or off 3D look of the chart. Not all chart types will have both a 2D and 3D mode.

Parameters:
on - True for 3D, false for 2D look.
 o is3DModeOn
 public boolean is3DModeOn()
Checks if the 3D mode is turned on.

Returns:
True for on, false for off.
 o setFrameOn
 public void setFrameOn(boolean on)
Turns on or off the 3D looking frame around the chart. It is off by default.

Parameters:
on - True for on, false for off.
 o isFrameOn
 public boolean isFrameOn()
Checks if the 3D looking frame around the chart is on.

Returns:
True for on, false for off.
 o setChartBackground
 public void setChartBackground(Color color)
Sets the background color of the chart itself. Use setBackground() to set the background color outside the chart grid itself.

Parameters:
color - The color to use.
 o getChartBackground
 public Color getChartBackground()
Gets the color of the chart background itself.

 o setChartForeground
 public void setChartForeground(Color color)
Sets the foreground color of the chart itself. Use setForeground() to set the color of the title, value labels, and other text.

Parameters:
color - The color to use.
 o getChartForeground
 public Color getChartForeground()
Gets the color of the chart foreground itself.

 o setSampleColors
 public void setSampleColors(Color colors[])
Sets the sample colors. If the number of samples is larger than the number of colors, the colors of the samples will cycle through the array. To use the default colors, use NULL as a parameter.

Parameters:
colors - An array with the colors to be used, null for default colors.
 o getSampleColors
 public Color[] getSampleColors()
Gets the array of colors used for the samples. This can also be used to find out the number of sample colors by taking the length of the array.

Returns:
An array containing the sample colors.
 o setSampleColor
 public void setSampleColor(int index,
                            Color color)
Sets the color of the specified sample. If the index is larger than or equal to the number of total sample colors, later samples that fall on that index will be given the same color.

Parameters:
index - The index of the sample (0-based).
color - The color to be used for the sample.
 o getSampleColor
 public Color getSampleColor(int index)
Gets the color of the specified sample. This is the color of the sample itself, not the color of the sample label.

Parameters:
index - The index of the sample.
 o addItemListener
 public void addItemListener(ItemListener l)
Adds an item listener to the chart. Any listener registered will be notified when a sample is selected or deselected.

Parameters:
l - The item listener to add.
See Also:
removeItemListener
 o removeItemListener
 public void removeItemListener(ItemListener l)
Removes the specified item listener from the chart.

Parameters:
l - The item listener to remove.
See Also:
addItemListener
 o getMaxValue
 public long getMaxValue()
Gets the largest value in the chart.

 o getFloatMaxValue
 public double getFloatMaxValue()
Gets the largest value in the chart as a floating point.

Returns:
The maximum value found, or 0 if no samples are present.
 o getMinValue
 public long getMinValue()
Gets the smallest value in the chart.

 o getFloatMinValue
 public double getFloatMinValue()
Gets the smallest value in the chart as a floating point.

Returns:
The smallest value found, or 0 if no samples are present.
 o clearSelection
 public void clearSelection()
Clears the selection of any chart sample.

 o setTrackSelectionOn
 public void setTrackSelectionOn(boolean on)
Turns on or off chart sample selection tracking. When this is on the selection follows the samples key, and not the position. This means that if the samples are sorted in another order, the selection will follow the same sample as before at another position.

Parameters:
on - True for on, false for off.
 o getSelectedObjects
 public Object[] getSelectedObjects()
Gets the currently selected objects.

Returns:
The objects as an array, or null if none are selected.
 o toString
 public String toString()
Returns the title of the chart.

Overrides:
toString in class Component
 o getPreferredSize
 public Dimension getPreferredSize()
This method is called by the awt, and returns the preferred size of the chart. The default size of the chart is 300 by 200 pixels.

Overrides:
getPreferredSize in class Component
 o getMinimumSize
 public Dimension getMinimumSize()
This method returns the minimum size of the chart. The default chart size is 100 by 70 pixels.

Overrides:
getMinimumSize in class Component
 o update
 public final void update(Graphics g)
This method is overridden to avoid flicker when the chart is repainted.

Overrides:
update in class Component
 o paint
 public final void paint(Graphics g)
This method is overridden to paint the chart using double buffering. This is done to avoid flickering, and the method render() has to be implemented by a subclass instead to paint the chart itself.

Overrides:
paint in class Component
See Also:
render
 o render
 protected abstract void render(Graphics g)
This method is called by paint(), and has to be implemented by the subclass to render the chart.

Parameters:
g - The graphics context used to paint with.
See Also:
paint
 o getGraphBounds
 protected Rectangle getGraphBounds(String labels[])
This method returns the bounding box around the chart itself. This method is called to find out where to place the chart title, legend, and other labels. If the subclass implements this method correctly, this class will render the title and legend in the correct positions.

Parameters:
labels - The labels used in the legend.
Returns:
The bounding rectangle for the chart itself.
 o checkSelection
 protected ChartSample checkSelection(Point point)
This method is called when the user releases the mouse and checks if the given point is inside a sample. The default behaviour is to check for selection on the legend. If any subclass wants to add selection behaviour, override this and call super.checkSelection().

Parameters:
point - The point to check for.
Returns:
The sample selected, or null if none was selected.
 o getVersion
 public static String getVersion()
Returns the current version of the charts.

 o main
 public static void main(String argv[])
Prints out the current version number.


All Packages  Class Hierarchy  This Package  Previous  Next  Index