schmitzm.jfree.chart.selection
Class AbstractDatasetSelectionModel<D extends Dataset,E,F>

java.lang.Object
  extended by schmitzm.jfree.chart.selection.AbstractDatasetSelectionModel<D,E,F>
All Implemented Interfaces:
DatasetSelectionModel<D,E,F>
Direct Known Subclasses:
CategoryDatasetSelectionModel, SeriesDatasetSelectionModel

public abstract class AbstractDatasetSelectionModel<D extends Dataset,E,F>
extends Object
implements DatasetSelectionModel<D,E,F>

This class is a general implementation of DatasetSelectionModel and maintains whether items of a Dataset are selected in a chart or not. The model connects to the Dataset as DatasetChangeListener to recognize the moment a series is removed. Subclasses must implement #datasetChanged(org.jfree.data.general.DatasetChangeEvent) to react with an automatic unselect.

D = the dataset type the model handles
E = the data type the series are identified with in the dataset
F = the data type the data items are identified with in each series

Author:
Martin Schmitz (University of Bonn/Germany)

Field Summary
protected  D dataset
          Holds the Dataset whose data can be selected.
protected   listeners
          Holds the listeners to the DatasetSelectionModel.
protected  Logger LOGGER
          Logger to log waring, debug or error messages.
protected  Map<E,Set<F>> selectedSeriesIdx
          Contains a Set for each series.
 
Constructor Summary
AbstractDatasetSelectionModel(D dataset)
          Creates a new selection model.
 
Method Summary
 void addSelectionListener(DatasetSelectionListener listener)
          Adds a listener which will be informed about changed on the selection model.
 boolean changeItemSelection(E seriesKey, F item)
          Changes the selection of a series item.
 void clearSelection()
          Clears the selection.
static AbstractDatasetSelectionModel<?,?,?> createInstanceFor(Dataset dataset)
          Creates a AbstractDatasetSelectionModel for a Dataset.
protected  DatasetSelectionChangeEvent createSelectionChangeEvent()
          Creates a DatasetSelectionChangeEvent.
 D getDataset()
          Returns the Dataset whose data can be selected.
 boolean getValueIsAdjusting()
          Returns whether the current selection change is a part of multiple changes.
 boolean isItemSelected(E seriesKey, F item)
          Checks if an series item is selected.
 void refreshSelection()
          Informs all listeners about a general selection change.
 void removeSelectionListener(DatasetSelectionListener listener)
          Removes a listener from the selection model.
 void setItemSelected(E seriesKey, F item, boolean selected)
          Sets whether a series item is selected or not.
 void setValueIsAdjusting(boolean valueIsAdjusting)
          Sets whether the following selection changes are part of multiple changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface schmitzm.jfree.chart.selection.DatasetSelectionModel
datasetChanged
 

Field Detail

LOGGER

protected Logger LOGGER
Logger to log waring, debug or error messages.


dataset

protected D extends Dataset dataset
Holds the Dataset whose data can be selected.


selectedSeriesIdx

protected Map<E,Set<F>> selectedSeriesIdx
Contains a Set for each series. In each of these sets the selected items are stored.


listeners

protected  listeners
Holds the listeners to the DatasetSelectionModel.

Constructor Detail

AbstractDatasetSelectionModel

public AbstractDatasetSelectionModel(D dataset)
Creates a new selection model.

Parameters:
dataset - Dataset whose data can be selected
Method Detail

createInstanceFor

public static AbstractDatasetSelectionModel<?,?,?> createInstanceFor(Dataset dataset)
Creates a AbstractDatasetSelectionModel for a Dataset.

Parameters:
dataset - a dataset
Returns:
null if selection is not supported for dataset

getDataset

public D getDataset()
Returns the Dataset whose data can be selected.

Specified by:
getDataset in interface DatasetSelectionModel<D extends Dataset,E,F>

isItemSelected

public boolean isItemSelected(E seriesKey,
                              F item)
Checks if an series item is selected.

Specified by:
isItemSelected in interface DatasetSelectionModel<D extends Dataset,E,F>
Parameters:
seriesKey - key of the series
item - the item in the series

setItemSelected

public void setItemSelected(E seriesKey,
                            F item,
                            boolean selected)
Sets whether a series item is selected or not.

Specified by:
setItemSelected in interface DatasetSelectionModel<D extends Dataset,E,F>
Parameters:
seriesKey - key of the series
item - the item in the series
selected - flag to (de)select the item

changeItemSelection

public boolean changeItemSelection(E seriesKey,
                                   F item)
Changes the selection of a series item.

Specified by:
changeItemSelection in interface DatasetSelectionModel<D extends Dataset,E,F>
Parameters:
seriesKey - key of the series
item - the item in the series
Returns:
true if the item changed to selected

clearSelection

public void clearSelection()
Clears the selection.

Specified by:
clearSelection in interface DatasetSelectionModel<D extends Dataset,E,F>

addSelectionListener

public void addSelectionListener(DatasetSelectionListener listener)
Adds a listener which will be informed about changed on the selection model.

Specified by:
addSelectionListener in interface DatasetSelectionModel<D extends Dataset,E,F>
Parameters:
listener - the listener to be added

removeSelectionListener

public void removeSelectionListener(DatasetSelectionListener listener)
Removes a listener from the selection model.

Specified by:
removeSelectionListener in interface DatasetSelectionModel<D extends Dataset,E,F>
Parameters:
listener - the listener to be remove

getValueIsAdjusting

public boolean getValueIsAdjusting()
Returns whether the current selection change is a part of multiple changes. If true refreshSelection() has no effect and no DatasetSelectionChangeEvent is fired until setValueIsAdjusting(false) is called.

Specified by:
getValueIsAdjusting in interface DatasetSelectionModel<D extends Dataset,E,F>

setValueIsAdjusting

public void setValueIsAdjusting(boolean valueIsAdjusting)
Sets whether the following selection changes are part of multiple changes. If true refreshSelection() has no effect and no DatasetSelectionChangeEvent event is fired. If the value is set from true to false an automatic refresh is initiated.

Specified by:
setValueIsAdjusting in interface DatasetSelectionModel<D extends Dataset,E,F>
See Also:
refreshSelection()

refreshSelection

public void refreshSelection()
Informs all listeners about a general selection change. Does nothing if getValueIsAdjusting() is true.

Specified by:
refreshSelection in interface DatasetSelectionModel<D extends Dataset,E,F>

createSelectionChangeEvent

protected DatasetSelectionChangeEvent createSelectionChangeEvent()
Creates a DatasetSelectionChangeEvent.