ca.odell.glazedlists.jfreechart
Class EventListPieDataset<E,K>

java.lang.Object
  extended by org.jfree.data.general.AbstractDataset
      extended by ca.odell.glazedlists.jfreechart.EventListPieDataset<E,K>
All Implemented Interfaces:
ObjectInputValidation, Serializable, Cloneable, Dataset, PieDataset, KeyedValues, Values

public class EventListPieDataset<E,K>
extends AbstractDataset
implements PieDataset

This class adapts an EventList to the JFreeChart PieDataset interface. Changes to the backing EventList are rebroadcast as changes to this PieDataset.

Extension: JFreeChart
This Glazed Lists extension requires the third party library JFreeChart.
Tested Version:1.0.0
Home page:http://www.jfree.org/jfreechart/
License:LGPL

Note: The DataEvents broadcasted by this class occur on the Thread the ListEvents arrive on. If this PieDataset is attached to a swing component, like a ChartPanel, it is the responsibility of the client to ensure that the ListEvents are arriving on the Swing Event Dispatch Thread, perhaps by using the SwingThreadProxyEventList.

Author:
James Lemieux
See Also:
SwingThreadProxyEventList, Serialized Form

Constructor Summary
EventListPieDataset(EventList<E> source, Comparator<E> groupingComparator, FunctionList.Function<List<E>,Comparable<K>> keyFunction, FunctionList.Function<List<E>,Number> valueFunction)
          Adapts the given source to the PieDataset interface by applying the groupingComparator to forms groups to be represented in the pie chart.
EventListPieDataset(EventList<E> source, FunctionList.Function<E,Comparable<K>> keyFunction, FunctionList.Function<E,Number> valueFunction)
          Adapts the given source to the PieDataset interface.
 
Method Summary
 void dispose()
          Releases the resources consumed by this EventListPieDataset 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 DatasetChangedEvent each time this method is called.
 int getIndex(Comparable key)
          Returns the index for a given key.
 int getItemCount()
          Returns the number of items (values).
 Comparable getKey(int index)
          Returns the key of the value at the given index.
 List getKeys()
          Returns the keys for the values in this PieDataset.
 Number getValue(Comparable key)
          Returns the value for a given key.
 Number getValue(int index)
          Returns the value at the given index.
 
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

EventListPieDataset

public EventListPieDataset(EventList<E> source,
                           FunctionList.Function<E,Comparable<K>> keyFunction,
                           FunctionList.Function<E,Number> valueFunction)
Adapts the given source to the PieDataset interface. The given keyFunction is then applied to each element of the source to produce the unique key for the element and the given valueFunction is applied to produce the value for an element.

This constructor should be used when the elements in source do not need to be grouped together in order to represent pie data.

Parameters:
source - the EventList containing the data to chart
keyFunction - produces the keys of the source elements in the pie chart
valueFunction - produces the values of the source elements in the pie chart

EventListPieDataset

public EventListPieDataset(EventList<E> source,
                           Comparator<E> groupingComparator,
                           FunctionList.Function<List<E>,Comparable<K>> keyFunction,
                           FunctionList.Function<List<E>,Number> valueFunction)
Adapts the given source to the PieDataset interface by applying the groupingComparator to forms groups to be represented in the pie chart. The given keyFunction is then applied to produce the key for a group and the given valueFunction is applied to produce the value for a group.

Parameters:
source - the EventList containing the data to chart
groupingComparator - produces the groups in the pie chart
keyFunction - produces the keys of the groups in the pie chart
valueFunction - produces the values of the groups in the pie chart
Method Detail

getKey

public Comparable getKey(int index)
Returns the key of the value at the given index.

Specified by:
getKey in interface KeyedValues
Parameters:
index - the item index (zero-based)
Returns:
the key
Throws:
IndexOutOfBoundsException - if index is out of bounds

getIndex

public int getIndex(Comparable key)
Returns the index for a given key.

Specified by:
getIndex in interface KeyedValues
Parameters:
key - the key
Returns:
the index, or -1 if the key is unrecognised

getKeys

public List getKeys()
Returns the keys for the values in this PieDataset. Note that you can access the values in this PieDataset by key or by index. For this reason, the key order is important - this method should return the keys in order. The returned list may be unmodifiable.

Specified by:
getKeys in interface KeyedValues
Returns:
the keys (never null).

getValue

public Number getValue(Comparable key)
Returns the value for a given key.

Specified by:
getValue in interface KeyedValues
Parameters:
key - the key
Returns:
the value (possibly null)
Throws:
UnknownKeyException - if the key is not recognised

getItemCount

public int getItemCount()
Returns the number of items (values).

Specified by:
getItemCount in interface Values

getValue

public Number getValue(int index)
Returns the value at the given index.

Specified by:
getValue in interface Values
Parameters:
index - the index of interest (zero-based index).
Returns:
the value

dispose

public void dispose()
Releases the resources consumed by this EventListPieDataset so that it may eventually be garbage collected. This is important when the EventList that backs this EventListPieDataset should outlast this EventListPieDataset. This method should be called as soon as this EventListPieDataset is no longer useful.

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


fireDatasetChanged

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

Overrides:
fireDatasetChanged in class AbstractDataset


Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by James Lemieux at 2009-01-25 18:40