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

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

public final class SimpleEventCategoryDataset<R extends Comparable,C extends Comparable>
extends AbstractDataset
implements CategoryDataset, ListEventListener<Comparable>

This class helps adapt a pair of EventLists 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
CategoryDataset is essentially a data model for a large matrix where each unique row and unique column is identified by a Comparable key. CategoryDataset requires its implementer to do three distinct things: This implementation of CategoryDataset uses two distinct EventList to model the rows keys column keys. Thus, to add, remove, or change rows or columns you need only modify the corresponding EventList. Extracting a data value from a combination of a row key and column key is done via a FunctionList.Function. Specifically, this implementation creates an instance of a SimpleEventCategoryDataset.Context with information about which row key and column key to use when producing a data value for that position in the matrix. The logic of exactly how to produce that data value is left to the particular implementation of the function.

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

Nested Class Summary
static class SimpleEventCategoryDataset.Context<R,C>
          This object describes a cell within the "matrix" that is defined by CategoryDataset.
 
Field Summary
protected  EventList<C> columnKeys
          An ordered list of keys identifying the chart's columns.
protected  EventList<R> rowKeys
          An ordered list of keys identifying the chart's rows.
 
Constructor Summary
SimpleEventCategoryDataset(EventList<R> rowKeys, EventList<C> columnKeys, FunctionList.Function<SimpleEventCategoryDataset.Context<R,C>,Number> valueMaker)
          The given rowKeys and columnKeys represent the ordered lists of row and column keys presented by this CategoryDataset.
 
Method Summary
 void dispose()
          Releases the resources consumed by this SimpleEventCategoryDataset 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 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.
 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<Comparable> listChanges)
          Watch the row key and column key lists for changes and rebroadcast those 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
 

Field Detail

rowKeys

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


columnKeys

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

Constructor Detail

SimpleEventCategoryDataset

public SimpleEventCategoryDataset(EventList<R> rowKeys,
                                  EventList<C> columnKeys,
                                  FunctionList.Function<SimpleEventCategoryDataset.Context<R,C>,Number> valueMaker)
The given rowKeys and columnKeys represent the ordered lists of row and column keys presented by this CategoryDataset. Any modifications to either of those EventLists trigger this dataset to broadcast a change.

The given valueMaker is used to produce a Number value for a given pair: {row key, column key}. This effectively creates the data which is charted.

Parameters:
rowKeys - the keys identifying the unique rows
columnKeys - the keys identifying the unique columns
valueMaker - the function which maps {row key, column key} -> Number
Method Detail

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(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

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

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<Comparable> listChanges)
Watch the row key and column key lists for changes and rebroadcast those ListEvents as DatasetChangeEvents.

Specified by:
listChanged in interface ListEventListener<Comparable>

dispose

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

A SimpleEventCategoryDataset will be garbage collected without a call to dispose(), but not before its row key and column key EventLists are garbage collected. By calling dispose(), you allow the SimpleEventCategoryDataset to be garbage collected before its source EventLists. This is necessary for situations where a SimpleEventCategoryDataset is short-lived but its source EventLists are long-lived.

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



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