ca.odell.glazedlists.jfreechart
Class EventListCategoryDataset<R extends Comparable,C extends Comparable>

java.lang.Object
  extended by org.jfree.data.general.AbstractDataset
      extended by ca.odell.glazedlists.jfreechart.EventListCategoryDataset<R,C>
All Implemented Interfaces:
ListEventListener<ValueSegment<C,R>>, ObjectInputValidation, Serializable, Cloneable, EventListener, CategoryDataset, Dataset, KeyedValues2D, Values2D

public abstract class EventListCategoryDataset<R extends Comparable,C extends Comparable>
extends AbstractDataset
implements CategoryDataset, ListEventListener<ValueSegment<C,R>>

This class helps adapt an EventList to the CategoryDataset interface which is the necessary model for JFreeChart views such as

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

If it is possible to create a pipeline of list transformations such that your source is an EventList of ValueSegment objects then this class can aid you in showing and maintaining that data within a JFreeChart. It handles the maintenance of efficient data structures for implementing getValue(int, int) and leaves subclasses the task of defining the logic for maintaining the lists of rowkeys and columnkeys.

If the rowkeys and columnkeys are statically determined, they can be set like so:

   EventList myValueSegments = ...
   CategoryDataset dataset = new EventListCategoryDataset(myValueSegments);
   dataset.getColumnKeys().add(...);
   dataset.getRowKeys().add(...);
 
If the rowkeys and/or columnkeys are dynamically maintained as ValueSegments are added and removed from the EventList, then two hooks have been given for the benefit of subclasses:

Note: If this EventListCategoryDataset 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

Field Summary
protected  List<? extends Comparable> columnKeys
          An ordered list of keys identifying the chart's columns.
protected  List<? extends Comparable> rowKeys
          An ordered list of keys identifying the chart's rows.
 
Constructor Summary
EventListCategoryDataset(EventList<ValueSegment<C,R>> source)
          Constructs an implementation of CategoryDataset which presents the data contained in the given source.
 
Method Summary
protected  List<? extends Comparable> createColumnKeyList()
          A local factory method for creating the list containing the column keys.
protected  List<? extends Comparable> createRowKeyList()
          A local factory method for creating the list containing the row keys.
 void dispose()
          Releases the resources consumed by this EventListCategoryDataset 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.
 int getColumnCount()
          Returns the number of columns in the table.
 int getColumnIndex(Comparable key)
          Returns the column index for a given key.
 Comparable getColumnKey(int column)
          Returns the column key for a given index.
 List getColumnKeys()
          Returns the column keys.
 int getCount(R rowKey)
          Returns the number of values associated with the given rowKey.
 int getCount(R rowKey, C start, C end)
          Returns the number of values associated with the given rowKey between the given start and end values.
 int getRowCount()
          Returns the number of rows in the table.
 int getRowIndex(Comparable key)
          Returns the row index for a given key.
 Comparable getRowKey(int row)
          Returns the row key for a given index.
 List getRowKeys()
          Returns the row keys.
abstract  Number getValue(Comparable rowKey, Comparable columnKey)
          Returns the value associated with the specified keys.
 Number getValue(int row, int column)
          Returns a value from the table.
 void listChanged(ListEvent<ValueSegment<C,R>> listChanges)
          This listener maintains a fast set of TreePairs for each unique value found in the ValueSegments of the source list.
protected  void postDelete(ValueSegment<C,R> valueSegment)
          This no-op method is left as a hook for subclasses.
protected  void postInsert(ValueSegment<C,R> valueSegment)
          This no-op method is left as a hook for subclasses.
 
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
 

Field Detail

rowKeys

protected List<? extends Comparable> rowKeys
An ordered list of keys identifying the chart's rows.


columnKeys

protected List<? extends Comparable> columnKeys
An ordered list of keys identifying the chart's columns.

Constructor Detail

EventListCategoryDataset

public EventListCategoryDataset(EventList<ValueSegment<C,R>> source)
Constructs an implementation of CategoryDataset which presents the data contained in the given source.

Parameters:
source - the EventList of data to be charted
Method Detail

createRowKeyList

protected List<? extends Comparable> createRowKeyList()
A local factory method for creating the list containing the row keys.


createColumnKeyList

protected List<? extends Comparable> createColumnKeyList()
A local factory method for creating the list containing the column keys.


getRowKey

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

Specified by:
getRowKey in interface KeyedValues2D
Parameters:
row - the row index (zero-based)
Returns:
the row key
Throws:
IndexOutOfBoundsException - if row is out of bounds

getRowIndex

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

Specified by:
getRowIndex in interface KeyedValues2D
Parameters:
key - the row key
Returns:
the row index, or -1 if the key is unrecognized

getRowKeys

public List getRowKeys()
Returns the row keys.

Specified by:
getRowKeys in interface KeyedValues2D

getRowCount

public int getRowCount()
Returns the number of rows in the table.

Specified by:
getRowCount in interface Values2D

getColumnKey

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

Specified by:
getColumnKey in interface KeyedValues2D
Parameters:
column - the column index (zero-based)
Returns:
the column key
Throws:
IndexOutOfBoundsException - if column is out of bounds

getColumnIndex

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

Specified by:
getColumnIndex in interface KeyedValues2D
Parameters:
key - the column key
Returns:
the column index, or -1 if the key is unrecognized

getColumnKeys

public List getColumnKeys()
Returns the column keys.

Specified by:
getColumnKeys in interface KeyedValues2D

getColumnCount

public int getColumnCount()
Returns the number of columns in the table.

Specified by:
getColumnCount in interface Values2D

getValue

public Number getValue(int row,
                       int column)
Returns a value from the table.

Specified by:
getValue in interface Values2D
Parameters:
row - the row index (zero-based)
column - the column index (zero-based)
Returns:
the value (possibly null)
Throws:
IndexOutOfBoundsException - if the row or column is out of bounds

getValue

public abstract Number getValue(Comparable rowKey,
                                Comparable columnKey)
Returns the value associated with the specified keys.

Specified by:
getValue in interface KeyedValues2D
Parameters:
rowKey - the row key (null not permitted)
columnKey - the column key (null not permitted)
Returns:
the value
Throws:
UnknownKeyException - if either key is not recognized

dispose

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

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

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


getCount

public int getCount(R rowKey)
Returns the number of values associated with the given rowKey.


getCount

public int getCount(R rowKey,
                    C start,
                    C end)
Returns the number of values associated with the given rowKey between the given start and end values.


postInsert

protected void postInsert(ValueSegment<C,R> valueSegment)
This no-op method is left as a hook for subclasses. It is called after an element has been inserted into the value data structure in this dataset. Subclasses typically override this method to provide extra logic for maintaining the lists of rowkeys and columnkeys dynamically.

Parameters:
valueSegment - the data element inserted into this data set

postDelete

protected void postDelete(ValueSegment<C,R> valueSegment)
This no-op method is left as a hook for subclasses. It is called after an element has been removed from the value data structure in this dataset. Subclasses typically override this method to provide extra logic for maintaining the lists of rowkeys and columnkeys dynamically.

Parameters:
valueSegment - the data element removed from this data set

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 AbstractDataset

listChanged

public void listChanged(ListEvent<ValueSegment<C,R>> listChanges)
This listener maintains a fast set of TreePairs for each unique value found in the ValueSegments of the source list. The TreePairs, in turn, are efficient at answering questions about the number of values which fall in the certain segment of the value's continuum. This listener also rebroadcasts ListEvents as DatasetChangeEvents.

Specified by:
listChanged in interface ListEventListener<ValueSegment<C extends Comparable,R extends Comparable>>


Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by mockbuild at 2013-02-07 9:25