ca.odell.glazedlists.jfreechart
Class CalculationCategoryDataset

java.lang.Object
  extended by org.jfree.data.general.AbstractDataset
      extended by ca.odell.glazedlists.jfreechart.CalculationCategoryDataset
All Implemented Interfaces:
ListEventListener<Calculation<? extends java.lang.Number>>, java.io.ObjectInputValidation, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, org.jfree.data.category.CategoryDataset, org.jfree.data.general.Dataset, org.jfree.data.KeyedValues2D, org.jfree.data.Values2D

public class CalculationCategoryDataset
extends org.jfree.data.general.AbstractDataset
implements org.jfree.data.category.CategoryDataset, ListEventListener<Calculation<? extends java.lang.Number>>

An implementation of a CategoryDataset that is backed by a List<Calculation> where each Calculation reports a numeric value. Typical usage of this class resembles:

 // create the numeric Calculations we want to chart
 final Calculation<Number> appleStockPrice = ...
 final Calculation<Number> googleStockPrice = ...
 final Calculation<Number> microsoftStockPrice = ...

 // create the dataset
 final CalculationCategoryDataset dataset = new CalculationCategoryDataset();

 // add the numeric Calculations into the dataset; any change to the
 // Calculations induces a redraw of the corresponding chart
 dataset.getCalculations().add(appleStockPrice);
 dataset.getCalculations().add(googleStockPrice);
 dataset.getCalculations().add(microsoftStockPrice);

 ...

 // when the dataset is no longer needed, dispose() of it so it can be GC'd
 dataset.dispose();
 

Note: If this CalculationCategoryDataset is being shown in a Swing User Interface, and thus Dataset Changes should be broadcast on the Swing Event Dispatch Thread, it is the responsibility of the caller to ensure that ListEvents arrive on the Swing EDT.

Author:
James Lemieux
See Also:
GlazedListsSwing.swingThreadProxyList(ca.odell.glazedlists.EventList), Serialized Form

Constructor Summary
CalculationCategoryDataset()
           
 
Method Summary
 void dispose()
          Releases the resources consumed by this CalculationCategoryDataset so that it may eventually be garbage collected.
protected  void fireDatasetChanged()
          We override this method for speed reasons, since the super needlessly constructs a new DatasetChangeEvent each time this method is called.
 java.util.List<Calculation<? extends java.lang.Number>> getCalculations()
          Returns the mutable List of Calculations that create the data values in this CategoryDataset.
 int getColumnCount()
           
 int getColumnIndex(java.lang.Comparable key)
           
 java.lang.Comparable getColumnKey(int column)
           
 java.util.List getColumnKeys()
           
 int getRowCount()
           
 int getRowIndex(java.lang.Comparable key)
           
 java.lang.Comparable getRowKey(int row)
           
 java.util.List getRowKeys()
           
 java.lang.Number getValue(java.lang.Comparable rowKey, java.lang.Comparable columnKey)
           
 java.lang.Number getValue(int row, int column)
           
 void listChanged(ListEvent<Calculation<? extends java.lang.Number>> listChanges)
          This listener rebroadcasts ListEvents as DatasetChangeEvents.
 
Methods inherited from class org.jfree.data.general.AbstractDataset
addChangeListener, clone, getGroup, hasListener, notifyListeners, removeChangeListener, setGroup, validateObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jfree.data.general.Dataset
addChangeListener, getGroup, removeChangeListener, setGroup
 

Constructor Detail

CalculationCategoryDataset

public CalculationCategoryDataset()
Method Detail

getCalculations

public java.util.List<Calculation<? extends java.lang.Number>> getCalculations()
Returns the mutable List of Calculations that create the data values in this CategoryDataset. Any Calculation objects added to / removed from this List will be added to / removed from this CategoryDataset.

Returns:
the mutable List of Calculations backing this CategoryDataset

getRowKey

public java.lang.Comparable getRowKey(int row)
Specified by:
getRowKey in interface org.jfree.data.KeyedValues2D

getRowIndex

public int getRowIndex(java.lang.Comparable key)
Specified by:
getRowIndex in interface org.jfree.data.KeyedValues2D

getRowKeys

public java.util.List getRowKeys()
Specified by:
getRowKeys in interface org.jfree.data.KeyedValues2D

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface org.jfree.data.Values2D

getColumnKey

public java.lang.Comparable getColumnKey(int column)
Specified by:
getColumnKey in interface org.jfree.data.KeyedValues2D

getColumnIndex

public int getColumnIndex(java.lang.Comparable key)
Specified by:
getColumnIndex in interface org.jfree.data.KeyedValues2D

getColumnKeys

public java.util.List getColumnKeys()
Specified by:
getColumnKeys in interface org.jfree.data.KeyedValues2D

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface org.jfree.data.Values2D

getValue

public java.lang.Number getValue(java.lang.Comparable rowKey,
                                 java.lang.Comparable columnKey)
Specified by:
getValue in interface org.jfree.data.KeyedValues2D

getValue

public java.lang.Number getValue(int row,
                                 int column)
Specified by:
getValue in interface org.jfree.data.Values2D

listChanged

public void listChanged(ListEvent<Calculation<? extends java.lang.Number>> listChanges)
This listener rebroadcasts ListEvents as DatasetChangeEvents.

Specified by:
listChanged in interface ListEventListener<Calculation<? extends java.lang.Number>>

dispose

public void dispose()
Releases the resources consumed by this CalculationCategoryDataset so that it may eventually be garbage collected.

A CalculationCategoryDataset will be garbage collected without a call to dispose(), but not before its source Calculations are all garbage collected. By calling dispose(), you allow the CalculationCategoryDataset to be garbage collected before its source Calculations. This is necessary for situations where a CalculationCategoryDataset is short-lived but its source Calculations are long-lived.

Warning: It is an error to call any method on an CalculationCategoryDataset after it has been disposed.


fireDatasetChanged

protected void fireDatasetChanged()
We override this method for speed reasons, since the super needlessly constructs a new DatasetChangeEvent each time this method is called.

Overrides:
fireDatasetChanged in class org.jfree.data.general.AbstractDataset


Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by abuild at 2011-01-06 6:55