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:
- sample value
- sample legend label
- sample lagend label color
- a key that identifies the sample
For the chart itself you can set the following:
- set the number of decimals used for the values
- set chart title
- turn chart title on or off
- turn legend on or off
- legend position (top, bottom, left, or right)
- set 2D or 3D chart display
- turn sample value labels on or off
- set the chart background
- set the chart foreground
- turn the 3D frame around the chart on or off
- set the colors for each of the samples (in the legend)
- Author:
- Bjorn J. Kvande.
-
BOTTOM
- Bottom legend position.
-
LEFT
- Left legend position.
-
RIGHT
- Right legend position.
-
TOP
- Top legend position.
-
Chart(int)
- Creates a chart with the given number of samples and no title.
-
addItemListener(ItemListener)
- Adds an item listener to the chart.
-
checkSelection(Point)
- This method is called when the user releases the mouse and checks
if the given point is inside a sample.
-
clearSelection()
- Clears the selection of any chart sample.
-
getChartBackground()
- Gets the color of the chart background itself.
-
getChartForeground()
- Gets the color of the chart foreground itself.
-
getFloatMaxValue()
- Gets the largest value in the chart as a floating point.
-
getFloatMinValue()
- Gets the smallest value in the chart as a floating point.
-
getFloatSampleValue(int)
- Gets the value at the given index as a floating point.
-
getFloatSampleValues()
- Gets the sample values as a floating point array.
-
getGraphBounds(String[])
- This method returns the bounding box around the chart itself.
-
getLegendPosition()
- Gets the legend position.
-
getMaxValue()
- Gets the largest value in the chart.
-
getMinimumSize()
- This method returns the minimum size of the chart.
-
getMinValue()
- Gets the smallest value in the chart.
-
getPreferredSize()
- This method is called by the awt, and returns the preferred size of
the chart.
-
getSample(int)
- Gets the specified sample.
-
getSample(Object)
- Gets the sample with the given key.
-
getSampleColor(int)
- Gets the color of the specified sample.
-
getSampleColors()
- Gets the array of colors used for the samples.
-
getSampleCount()
- Gets the number of samples in the chart.
-
getSampleDecimalCount()
- Gets the number of decimals used for the sample values.
-
getSampleLabel(int)
- Gets the label of the specified sample.
-
getSampleLabelColor(int)
- Gets the color of the label of the specified sample.
-
getSampleLabels()
- Gets the sample labels as an array of strings.
-
getSamples()
- Gets the samples of the chart.
-
getSampleValue(int)
- Gets the value at the given index.
-
getSampleValues()
- Gets the sample values as an array of values.
-
getSelectedObjects()
- Gets the currently selected objects.
-
getTitle()
- Gets the chart title.
-
getTitleFont()
- Returns the font used for the title.
-
getVersion()
- Returns the current version of the charts.
-
is3DModeOn()
- Checks if the 3D mode is turned on.
-
isFrameOn()
- Checks if the 3D looking frame around the chart is on.
-
isLegendOn()
- Checks if the legend is turned on.
-
isTitleOn()
- Checks if the title is turned on.
-
isValueLabelsOn()
- Checks if the value labels are turned on.
-
main(String[])
- Prints out the current version number.
-
paint(Graphics)
- This method is overridden to paint the chart using double buffering.
-
removeItemListener(ItemListener)
- Removes the specified item listener from the chart.
-
render(Graphics)
- This method is called by paint(), and has to be implemented by the
subclass to render the chart.
-
set3DModeOn(boolean)
- Turns on or off 3D look of the chart.
-
setChartBackground(Color)
- Sets the background color of the chart itself.
-
setChartForeground(Color)
- Sets the foreground color of the chart itself.
-
setFrameOn(boolean)
- Turns on or off the 3D looking frame around the chart.
-
setLegendOn(boolean)
- Turns on or off the label legend.
-
setLegendPosition(int)
- Sets the legend position.
-
setSample(int, ChartSample)
- Sets the specified sample.
-
setSample(int, double, String, Object)
- Sets the specified sample.
-
setSampleColor(int, Color)
- Sets the color of the specified sample.
-
setSampleColors(Color[])
- Sets the sample colors.
-
setSampleCount(int)
- Sets the number of samples for the chart.
-
setSampleDecimalCount(int)
- Sets the number of decimals in the sample values.
-
setSampleLabel(int, String)
- Sets the label of the specified sample.
-
setSampleLabelColor(int, Color)
- Sets the color of of the label for the specified sample.
-
setSampleLabels(String[])
- Sets the labels for the samples.
-
setSamples(ChartSample[])
- Sets the samples of the chart to be the specified samples.
-
setSampleValue(int, double)
- Sets the value of the given sample.
-
setSampleValues(double[])
- Sets the sample values using a double array.
-
setSampleValues(long[])
- Sets the sample values using a long array.
-
setTitle(String)
- Sets the chart title.
-
setTitleFont(Font)
- Sets the font used for the title.
-
setTitleOn(boolean)
- Turns on or off the chart title.
-
setTrackSelectionOn(boolean)
- Turns on or off chart sample selection tracking.
-
setValueLabelsOn(boolean)
- Turns on or off the value labels.
-
toString()
-
Returns the title of the chart.
-
update(Graphics)
- This method is overridden to avoid flicker when the chart is repainted.
LEFT
public static final int LEFT
- Left legend position.
RIGHT
public static final int RIGHT
- Right legend position.
TOP
public static final int TOP
- Top legend position.
BOTTOM
public static final int BOTTOM
- Bottom legend position.
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.
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.
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
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.
getSamples
public ChartSample[] getSamples()
- Gets the samples of the chart.
- Returns:
- An array of the chart samples.
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
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
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
getSampleCount
public synchronized int getSampleCount()
- Gets the number of samples in the chart.
- See Also:
- setSampleCount
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
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
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.
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.
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
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.
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.
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.
getSampleDecimalCount
public int getSampleDecimalCount()
- Gets the number of decimals used for the sample values.
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
getSampleLabels
public String[] getSampleLabels()
- Gets the sample labels as an array of strings.
- Returns:
- A string array containing the labels.
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
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
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.
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).
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
getTitle
public String getTitle()
- Gets the chart title.
- See Also:
- setTitle
setTitleFont
public void setTitleFont(Font font)
- Sets the font used for the title.
- Parameters:
- font - The font to use.
getTitleFont
public Font getTitleFont()
- Returns the font used for the title.
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
isTitleOn
public boolean isTitleOn()
- Checks if the title is turned on.
- Returns:
- True if on, false if off.
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.
getLegendPosition
public int getLegendPosition()
- Gets the legend position.
- Returns:
- TOP, BOTTOM, LEFT, or RIGHT.
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
isLegendOn
public boolean isLegendOn()
- Checks if the legend is turned on.
- Returns:
- True for on, false for off.
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
isValueLabelsOn
public boolean isValueLabelsOn()
- Checks if the value labels are turned on.
- Returns:
- True for on, false for off.
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.
is3DModeOn
public boolean is3DModeOn()
- Checks if the 3D mode is turned on.
- Returns:
- True for on, false for off.
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.
isFrameOn
public boolean isFrameOn()
- Checks if the 3D looking frame around the chart is on.
- Returns:
- True for on, false for off.
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.
getChartBackground
public Color getChartBackground()
- Gets the color of the chart background itself.
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.
getChartForeground
public Color getChartForeground()
- Gets the color of the chart foreground itself.
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.
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.
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.
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.
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
removeItemListener
public void removeItemListener(ItemListener l)
- Removes the specified item listener from the chart.
- Parameters:
- l - The item listener to remove.
- See Also:
- addItemListener
getMaxValue
public long getMaxValue()
- Gets the largest value in the chart.
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.
getMinValue
public long getMinValue()
- Gets the smallest value in the chart.
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.
clearSelection
public void clearSelection()
- Clears the selection of any chart sample.
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.
getSelectedObjects
public Object[] getSelectedObjects()
- Gets the currently selected objects.
- Returns:
- The objects as an array, or null if none are selected.
toString
public String toString()
- Returns the title of the chart.
- Overrides:
- toString in class Component
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
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
update
public final void update(Graphics g)
- This method is overridden to avoid flicker when the chart is repainted.
- Overrides:
- update in class Component
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
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
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.
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.
getVersion
public static String getVersion()
- Returns the current version of the charts.
main
public static void main(String argv[])
- Prints out the current version number.
All Packages Class Hierarchy This Package Previous Next Index