org.progeeks.jfreechart
Class ChartContext

java.lang.Object
  extended by org.progeeks.util.beans.BeanChangeSupport
      extended by org.progeeks.util.DefaultViewContext
          extended by org.progeeks.util.DefaultObjectViewContext
              extended by org.progeeks.jfreechart.ChartContext
All Implemented Interfaces:
java.io.Serializable, StandardBean, FocusedContext, ObjectViewContext, ViewContext

public class ChartContext
extends DefaultObjectViewContext
implements FocusedContext

Context which allows rendering of a List of data objects in a chart using the JFreeChart package.

Version:
$Revision: 1.10 $
Author:
esword
See Also:
Serialized Form

Field Summary
protected static Log log
           
static java.lang.String PROP_CHART
          Property storing the generated JFreeChart.
static java.lang.String PROP_CHART_CONFIG
          Property storing the configurator for the chart.
static java.lang.String PROP_CHART_PLOT
          Property storing the plot the chart.
static java.lang.String PROP_DATA_TRANSFORM
          Property storing the DataTransformer for the input data object.
static java.lang.String PROP_DATASET_PRODUCERS
          Property storing the DatasetProducers for the chart.
static java.lang.String PROP_PANEL_CONFIG
          Property storing the panel configuration for the chart.
 
Fields inherited from interface org.progeeks.util.FocusedContext
PROP_FOCUS
 
Fields inherited from interface org.progeeks.util.ObjectViewContext
PROP_OBJECT
 
Constructor Summary
ChartContext()
           
ChartContext(java.lang.Object obj)
          Init the ChartContext.
 
Method Summary
protected  void addDatasetsToChart(org.jfree.chart.JFreeChart chart, org.jfree.data.general.Dataset[] datasets)
          Extract the plot(s) and set the datasets to it
protected  void addDatasetsToPlot(org.jfree.chart.plot.Plot chartPlot, org.jfree.data.general.Dataset[] datasets)
          Determines what type of plot this is and casts the datasets appropriately.
protected  void addDatasetsToPlots(java.util.List chartPlots, org.jfree.data.general.Dataset[] datasets)
          Distribute the Datasets into a list of plots.
protected  void createChart()
          Generate the chart with current data and configuration
protected  void createTransform()
          Update the listeners on the transform
 org.jfree.chart.JFreeChart getChart()
          Invoked by corresponding view to (if necessary) and return it.
 BeanConfigurator getChartConfig()
           
 MetaDatasetProducer getDatasetProducer()
          Return the primary dataset producer.
 java.util.List getDatasetProducers()
           
 BeanConfigurator getDataTransformConfig()
           
 java.lang.Object getFocus()
          Returns the object that is the current focus of this context.
 ChartFocusHandler getFocusHandler()
           
 BeanConfigurator getPanelConfig()
           
 org.jfree.chart.plot.Plot getPlot()
           
protected  void handleFocus(java.lang.Object focus)
          Invokes the focus handler and actually sets the focus property.
 void setChartConfig(BeanConfigurator chartConfig)
           
 void setDatasetProducer(MetaDatasetProducer producer)
          Set the PROP_DATASET_PRODUCERS property.
 void setDatasetProducers(java.util.List datasetProducers)
          Set the PROP_DATASET_PRODUCERS property.
 void setDataTransformConfig(BeanConfigurator chartDataTransform)
           
 void setFocus(java.lang.Object focus)
          Handles setting the focus by both outside objects and if the user clicks in the ChartPanel.
 void setFocusHandler(ChartFocusHandler focusHandler)
           
 void setPanelConfig(BeanConfigurator panelConfig)
           
 void setPlot(org.jfree.chart.plot.Plot chartPlot)
          Set the PROP_CHART_CONFIG property.
 void setPlots(java.util.List chartPlots)
          Set the PROP_CHART_CONFIG property with the first Plot in the list.
 void setUserFocus(org.jfree.chart.entity.ChartEntity entity)
          Called by corresponding panel when the user clicks in the chart.
protected  void updateDatasets(java.util.List dataList)
          Create or update the datasets that will be used in the chart.
protected  void updateDatasets(java.lang.Object value)
          Create or update the dataset that will be used in the chart.
 
Methods inherited from class org.progeeks.util.DefaultObjectViewContext
getObject, setObject
 
Methods inherited from class org.progeeks.util.DefaultViewContext
findContext, getBooleanProperty, getDoubleProperty, getIntProperty, getObjectProperty, getObjectProperty, getParentContext, getRootContext, getStringProperty, setBooleanProperty, setDoubleProperty, setIntProperty, setObjectProperty, setParentContext, setStringProperty
 
Methods inherited from class org.progeeks.util.beans.BeanChangeSupport
addPropertyChangeListener, addPropertyChangeListener, clearAllListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, hasListeners, hasListeners, removePropertyChangeListener, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.progeeks.util.ViewContext
getParentContext, setParentContext
 
Methods inherited from interface org.progeeks.util.beans.StandardBean
addPropertyChangeListener, addPropertyChangeListener, hasListeners, hasListeners, removePropertyChangeListener, removePropertyChangeListener, removePropertyChangeListener
 

Field Detail

log

protected static final Log log

PROP_CHART_CONFIG

public static final java.lang.String PROP_CHART_CONFIG
Property storing the configurator for the chart. This is usually pretty basic because most settings that affect how the chart is drawn are done to the plot.

See Also:
Constant Field Values

PROP_CHART_PLOT

public static final java.lang.String PROP_CHART_PLOT
Property storing the plot the chart.

See Also:
Constant Field Values

PROP_PANEL_CONFIG

public static final java.lang.String PROP_PANEL_CONFIG
Property storing the panel configuration for the chart. This is optional. The corresponding ChartContextPanel will check the context to see if this exists and create its ChartPanel with it if so. Otherwise, it will create a ChartPanel with default settings.

See Also:
Constant Field Values

PROP_DATASET_PRODUCERS

public static final java.lang.String PROP_DATASET_PRODUCERS
Property storing the DatasetProducers for the chart. Most charts will only have a single DatasetProducer. However, if multiple Datasets are desired (for example, to render the data using two different renderers), then multiple DatasetProducers can be passed in. The type of Dataset created by each producer must match the type that the Plot generated by plotConfig expects.

See Also:
Constant Field Values

PROP_DATA_TRANSFORM

public static final java.lang.String PROP_DATA_TRANSFORM
Property storing the DataTransformer for the input data object. Used to translate the main data object into a list of data items which will then be sent to the DatasetProducer. If the main object is the actual list that contains the data items, this field can be left unset. A DefaultChartDataTransform will automatically be created, and it will just pass the List straight through to the DatasetProducer.

See Also:
Constant Field Values

PROP_CHART

public static final java.lang.String PROP_CHART
Property storing the generated JFreeChart. This is NOT set from any outside call. The corresponding view should listen to this property to see when the chart is totally regenerated.

See Also:
Constant Field Values
Constructor Detail

ChartContext

public ChartContext()

ChartContext

public ChartContext(java.lang.Object obj)
Init the ChartContext.

Parameters:
obj - Either a List of data objects or an object that a ChartDataTransform can extract a list from
Method Detail

getChart

public org.jfree.chart.JFreeChart getChart()
Invoked by corresponding view to (if necessary) and return it.

Returns:
The generated chart or null if there is an error.

createChart

protected void createChart()
Generate the chart with current data and configuration


createTransform

protected void createTransform()
Update the listeners on the transform

Parameters:
localList -

updateDatasets

protected void updateDatasets(java.util.List dataList)
                       throws de.laures.cewolf.DatasetProduceException
Create or update the datasets that will be used in the chart. This may be called with an entirely new list or with items to add to any existing Datasets.

Parameters:
dataList - List of items to give to each DatasetProducer
Throws:
de.laures.cewolf.DatasetProduceException

updateDatasets

protected void updateDatasets(java.lang.Object value)
                       throws de.laures.cewolf.DatasetProduceException
Create or update the dataset that will be used in the chart.

Parameters:
value - A new or changed value for the dataset
Throws:
de.laures.cewolf.DatasetProduceException

addDatasetsToChart

protected void addDatasetsToChart(org.jfree.chart.JFreeChart chart,
                                  org.jfree.data.general.Dataset[] datasets)
Extract the plot(s) and set the datasets to it

Parameters:
chart -
dataset -

addDatasetsToPlot

protected void addDatasetsToPlot(org.jfree.chart.plot.Plot chartPlot,
                                 org.jfree.data.general.Dataset[] datasets)
Determines what type of plot this is and casts the datasets appropriately. As each dataset is added to the chart, checks if there are axes beyond the default one. If there is a domain or range axis whose index equals the index of the dataset, then the dataset is mapped to use that axis. Otherwise, a dataset is mapped to the highest axes that exist (which are normally just the default axes).

Parameters:
chartPlot -
dataset -

addDatasetsToPlots

protected void addDatasetsToPlots(java.util.List chartPlots,
                                  org.jfree.data.general.Dataset[] datasets)
Distribute the Datasets into a list of plots. Useful with combined charts.

Parameters:
chartPlot -
datasets -

setFocus

public void setFocus(java.lang.Object focus)
Handles setting the focus by both outside objects and if the user clicks in the ChartPanel.

Specified by:
setFocus in interface FocusedContext

getFocus

public java.lang.Object getFocus()
Description copied from interface: FocusedContext
Returns the object that is the current focus of this context.

Specified by:
getFocus in interface FocusedContext
See Also:
FocusedContext.getFocus()

setUserFocus

public void setUserFocus(org.jfree.chart.entity.ChartEntity entity)
Called by corresponding panel when the user clicks in the chart. Figures out what item in the original data set corresponds to the clicked display data point and sets the context focus to that item. If no correspondance can be established, no change is made to the focus.

Parameters:
entity -

handleFocus

protected void handleFocus(java.lang.Object focus)
Invokes the focus handler and actually sets the focus property. Outside objects that want to set the context focus will invoke setFocus(Object) which will then call here. When the user sets the focus directly (by clicking on the chart), the chart panel will call setUserFocus(ChartEntity) which will then call here. Both methods first translate the focus object into a standard form for acting upon.

Parameters:
focus - An object that is already translated into the proper form for passing to the focusHandler (and the DatasetProducer).

getDatasetProducers

public java.util.List getDatasetProducers()
Returns:
Returns the datasetProducer.

getDatasetProducer

public MetaDatasetProducer getDatasetProducer()
Return the primary dataset producer. This will rarely, if ever, be called. It's here so that the MetaJb ObjectXmlReader can figure out how to resolve factories as parameters for the setDatasetProducer call.


setDatasetProducer

public void setDatasetProducer(MetaDatasetProducer producer)
Set the PROP_DATASET_PRODUCERS property. This is a shortcut method for when only a single DatasetProducer will be used. Do not use both this call and setDatasetProducers on the same object. Also set the focusHandler's producer property to the first item in the list.

Parameters:
producer - The MetaDatasetProducer to user.

setDatasetProducers

public void setDatasetProducers(java.util.List datasetProducers)
Set the PROP_DATASET_PRODUCERS property. The passed in list should contain DatasetProducers objects. Do not use both this call and setDatasetProducer on the same object. Also set the focusHandler's producer property to the first item in the list.

Parameters:
datasetProducers - The DatasetProducers

getChartConfig

public BeanConfigurator getChartConfig()
Returns:
Returns the chartConfig.

setChartConfig

public void setChartConfig(BeanConfigurator chartConfig)
Parameters:
chartConfig - The chartConfig to set.

getPanelConfig

public BeanConfigurator getPanelConfig()
Returns:
Returns the panelConfig.

setPanelConfig

public void setPanelConfig(BeanConfigurator panelConfig)
Parameters:
panelConfig - The panelConfig to set.

getDataTransformConfig

public BeanConfigurator getDataTransformConfig()
Returns:
Returns the chartDataTransform.

setDataTransformConfig

public void setDataTransformConfig(BeanConfigurator chartDataTransform)
Parameters:
chartDataTransform - The chartDataTransform to set.

getPlot

public org.jfree.chart.plot.Plot getPlot()
Returns:
Returns the chartPlot.

setPlot

public void setPlot(org.jfree.chart.plot.Plot chartPlot)
Set the PROP_CHART_CONFIG property. This is a shortcut method for when only a single Plot will be used (which is the case all the time unless a combined plot is used. Do not use both this call and setPlotConfigs on the same object.

Parameters:
chartPlot - The plot to set.

setPlots

public void setPlots(java.util.List chartPlots)
Set the PROP_CHART_CONFIG property with the first Plot in the list. If the first Plot is one of the combined plot types, then any additional Plots in the list are added as sub-plots to the primary one. Otherwise, additional plots are ignored. Note: At this time, there is no way to set the weight (i.e. percentage of space occupied) by individual sub-plots. They are all displayed with equal size.

Parameters:
chartPlots -

getFocusHandler

public ChartFocusHandler getFocusHandler()
Returns:
Returns the focusHandler.

setFocusHandler

public void setFocusHandler(ChartFocusHandler focusHandler)
Parameters:
focusHandler - The focusHandler to set.


Copyright © 2002-2003 Paul Speed. All Rights Reserved.