com.objectplanet.chart
Class ChartSample

java.lang.Object
  extended by com.objectplanet.chart.ChartSample
All Implemented Interfaces:
java.io.Serializable

public class ChartSample
extends java.lang.Object
implements java.io.Serializable

This class represents a sample in any chart. A chart sample has a value, label, label color, and a key. Each sample also has an index, which is the sample's position in the chart. A sample can also be selected.

Author:
Bjorn J. Kvande.
See Also:
Serialized Form

Field Summary
protected  java.lang.String label
          The label of the sample.
protected  java.lang.Double value
          The value of the sample.
 
Constructor Summary
ChartSample(int index)
          Creates a new empty sample with the given index.
ChartSample(int index, double value)
          Creates a new sample with the given index and value.
ChartSample(int index, double value, java.lang.String label, java.lang.Object key)
          Creates a new sample with the given values.
 
Method Summary
 void clearValue()
          Clears the value of the sample.
 double getFloatValue()
          Gets the value as a floating point.
 int getIndex()
          Gets the index of the sample.
 java.lang.Object getKey()
          Gets the key of the sample.
 java.lang.String getLabel()
          Gets the label of the sample.
 int getSeries()
          Gets the series index of the sample.
 long getValue()
          Gets the value of the sample.
 boolean hasValue()
          Returns true if a value has been set for this sample.
 boolean isSelected()
          Checks if the sample is selected.
 void set(double value, java.lang.String label, java.lang.Object key)
          Sets the chart sample's value, label, and the key.
 void setIndex(int index)
          Sets the index of the sample.
 void setLabel(java.lang.String label)
          Sets the label of the sample.
 void setLabelColor(java.awt.Color color)
          Sets the label color.
 boolean setSelection(boolean state)
          Selects or de-selects the sample.
 void setSeries(int series)
          Sets the series index of the sample.
 void setValue(double value)
          Sets the value of the sample.
 boolean toggleSelection()
          Toggles the selection of the sample.
 java.lang.String toString()
          Returns the label and value as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

label

protected java.lang.String label
The label of the sample.


value

protected java.lang.Double value
The value of the sample.

Constructor Detail

ChartSample

public ChartSample(int index)
Creates a new empty sample with the given index.

Parameters:
index - The index of the sample (should be position in the chart).

ChartSample

public ChartSample(int index,
                   double value)
Creates a new sample with the given index and value.

Parameters:
index - The index of the sample (should be position in the chart).
value - The value of the sample.

ChartSample

public ChartSample(int index,
                   double value,
                   java.lang.String label,
                   java.lang.Object key)
Creates a new sample with the given values.

Parameters:
index - The index of the sample (should be position in the chart).
value - The value of the sample.
label - The label of the sample.
key - The key of the sample.
Method Detail

clearValue

public void clearValue()
Clears the value of the sample. After this call it will not show up in the chart. You must do a repaint.


getFloatValue

public double getFloatValue()
Gets the value as a floating point. If the sample does not have a value, the value returned is Double.NaN (Not a Number).


getIndex

public int getIndex()
Gets the index of the sample. This is the position of the sample in the chart. The index will change if the sample changes position in the chart.


getKey

public java.lang.Object getKey()
Gets the key of the sample. The key is used to look up the sample in the chart again if it changed place in the chart.

Returns:
The key, or null if there is no key for this sample.

getLabel

public java.lang.String getLabel()
Gets the label of the sample.


getSeries

public int getSeries()
Gets the series index of the sample.


getValue

public long getValue()
Gets the value of the sample.


hasValue

public boolean hasValue()
Returns true if a value has been set for this sample.


isSelected

public boolean isSelected()
Checks if the sample is selected.

Returns:
True for selected, false otherwise.

set

public void set(double value,
                java.lang.String label,
                java.lang.Object key)
Sets the chart sample's value, label, and the key. The key is used to look up the sample in the chart again if it changed place in the chart.

Parameters:
value - The value of the sample.
label - The label of the sample.
key - The key of the sample.

setIndex

public void setIndex(int index)
Sets the index of the sample. This is the position of the sample in the chart. The index will change if the sample changes position.

Parameters:
index - The index of the sample.

setLabel

public void setLabel(java.lang.String label)
Sets the label of the sample.

Parameters:
label - The label to set.

setLabelColor

public void setLabelColor(java.awt.Color color)
Sets the label color. This is the color of the label in the legend. The default label color is black.

Parameters:
color - The color to use.

setSelection

public boolean setSelection(boolean state)
Selects or de-selects the sample.

Parameters:
state - True for selected, false otherwise.
Returns:
The new state of the sample.

setSeries

public void setSeries(int series)
Sets the series index of the sample.

Parameters:
series - The index of the series.

setValue

public void setValue(double value)
Sets the value of the sample.

Parameters:
value - The value to set.

toggleSelection

public boolean toggleSelection()
Toggles the selection of the sample.

Returns:
The new state of the sample.

toString

public java.lang.String toString()
Returns the label and value as a string.

Overrides:
toString in class java.lang.Object