schmitzm.jfree.chart
Class SelectableChartPanel

java.lang.Object
  extended by org.jfree.chart.ChartPanel
      extended by schmitzm.jfree.chart.SelectableChartPanel
Direct Known Subclasses:
FeatureChartPanel

public class SelectableChartPanel
extends org.jfree.chart.ChartPanel

This class extends the org.jfree.chart.ChartPanel with some new functionalities.

Version:
1.0
Author:
Martin Schmitz

Nested Class Summary
static class SelectableChartPanel.WindowSelectionMode
          Types of window selection on chart panel.
 
Field Summary
static ImageIcon ICON_ZOOM_TO_SELECTED
           
protected  ChartMouseSelectionTracker selectionTracker
          Listens to mouse window selection on the chart.
protected  SelectableChartPanel.WindowSelectionMode windowSelectionMode
          Holds the behavior on window selection (Default: SelectableChartPanel.WindowSelectionMode.ZOOM_IN_CHART).
 
Constructor Summary
SelectableChartPanel(JFreeChart chart)
          Creates a new chart panel.
SelectableChartPanel(JFreeChart chart, boolean useBuffer)
          Creates a new chart panel.
SelectableChartPanel(JFreeChart chart, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips)
          Creates a new chart panel.
SelectableChartPanel(JFreeChart chart, int width, int height, int minimumDrawWidth, int minimumDrawHeight, int maximumDrawWidth, int maximumDrawHeight, boolean useBuffer, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips)
          Creates a new chart panel.
 
Method Summary
protected
<E> void
applyRendererPropertiesToSelectionRenderer(Dataset dataset, AbstractRenderer originRenderer, AbstractRenderer selRenderer)
          Applies some rendering properties to the (new) selection renderer.
 void chartChanged(ChartChangeEvent e)
          If a new dataset is added this method updates the selection renderers.
protected  SelectionRenderer<?> createSelectionRenderer(Dataset dataset)
          Creates an adequate selection renderer for a dataset.
 SelectableChartPanel.WindowSelectionMode getWindowSelectionMode()
          Returns the behavior of the chart panel on window selections via mouse.
protected  void init()
          Called by every constructor to initialize the extensions of this panel.
 void mouseDragged(MouseEvent e)
          Ignores the event if the window selection mode is not SelectableChartPanel.WindowSelectionMode.ZOOM_IN_CHART, to avoid conflicts between the two listeners.
 void mouseMoved(MouseEvent e)
          Ignores the event if the window selection mode is not SelectableChartPanel.WindowSelectionMode.ZOOM_IN_CHART, to avoid conflicts between the two listeners.
 void refresh()
          Repaints the chart.
 void setChart(JFreeChart chart)
          After setting a new chart the zoom relevant properties are reset according to the new chart.
 void setWindowSelectionMode(SelectableChartPanel.WindowSelectionMode mode)
          Sets the behavior of the chart panel on window selections via mouse.
protected  void updateSelectionRenderers()
          This methods creates a SelectionRenderer for each Dataset in the plot to realize the highlight of the selected items.
protected  void updateStatesForWindowSelectionMode()
          Configures the zoomable properties and selectionTracker according to the current windowSelectionMode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ICON_ZOOM_TO_SELECTED

public static final ImageIcon ICON_ZOOM_TO_SELECTED

windowSelectionMode

protected SelectableChartPanel.WindowSelectionMode windowSelectionMode
Holds the behavior on window selection (Default: SelectableChartPanel.WindowSelectionMode.ZOOM_IN_CHART).


selectionTracker

protected ChartMouseSelectionTracker selectionTracker
Listens to mouse window selection on the chart.

Constructor Detail

SelectableChartPanel

public SelectableChartPanel(JFreeChart chart)
Creates a new chart panel.


SelectableChartPanel

public SelectableChartPanel(JFreeChart chart,
                            boolean useBuffer)
Creates a new chart panel.


SelectableChartPanel

public SelectableChartPanel(JFreeChart chart,
                            boolean properties,
                            boolean save,
                            boolean print,
                            boolean zoom,
                            boolean tooltips)
Creates a new chart panel.


SelectableChartPanel

public SelectableChartPanel(JFreeChart chart,
                            int width,
                            int height,
                            int minimumDrawWidth,
                            int minimumDrawHeight,
                            int maximumDrawWidth,
                            int maximumDrawHeight,
                            boolean useBuffer,
                            boolean properties,
                            boolean save,
                            boolean print,
                            boolean zoom,
                            boolean tooltips)
Creates a new chart panel.

Method Detail

init

protected void init()
Called by every constructor to initialize the extensions of this panel.


refresh

public void refresh()
Repaints the chart.


setWindowSelectionMode

public void setWindowSelectionMode(SelectableChartPanel.WindowSelectionMode mode)
Sets the behavior of the chart panel on window selections via mouse.

Parameters:
mode - new selection mode

getWindowSelectionMode

public SelectableChartPanel.WindowSelectionMode getWindowSelectionMode()
Returns the behavior of the chart panel on window selections via mouse.

Parameters:
selectionMode - new selection mode

setChart

public void setChart(JFreeChart chart)
After setting a new chart the zoom relevant properties are reset according to the new chart. After calling the super-method, this methods resets the properties according to the current windowSelectionMode to keep its functionality remaining.

See Also:
updateStatesForWindowSelectionMode()

updateStatesForWindowSelectionMode

protected void updateStatesForWindowSelectionMode()
Configures the zoomable properties and selectionTracker according to the current windowSelectionMode.


updateSelectionRenderers

protected void updateSelectionRenderers()
This methods creates a SelectionRenderer for each Dataset in the plot to realize the highlight of the selected items.


createSelectionRenderer

protected SelectionRenderer<?> createSelectionRenderer(Dataset dataset)
Creates an adequate selection renderer for a dataset. This implementation returns a renderer which draws only the data points. Sub-classes can override this method to create different renderers or renderers with different selection models (e.g. FeatureSeriesDatasetSelectionModel) for special purposes.

Parameters:
dataset - a dataset
Returns:
besides SelectionRenderer the returned object must be an AbstractRenderer

applyRendererPropertiesToSelectionRenderer

protected <E> void applyRendererPropertiesToSelectionRenderer(Dataset dataset,
                                                              AbstractRenderer originRenderer,
                                                              AbstractRenderer selRenderer)
Applies some rendering properties to the (new) selection renderer. This methods simply sets the series shape of the selection renderer to the shape of the origin renderer, so that the highlighted data items are drawn the same way as the origin data items.

Parameters:
dataset - the dataset for the selection renderer
originRenderer - the origin renderer for the dataset (should not be changed!)
selRenderer - the selection renderer to apply the properties to

chartChanged

public void chartChanged(ChartChangeEvent e)
If a new dataset is added this method updates the selection renderers.


mouseDragged

public void mouseDragged(MouseEvent e)
Ignores the event if the window selection mode is not SelectableChartPanel.WindowSelectionMode.ZOOM_IN_CHART, to avoid conflicts between the two listeners.


mouseMoved

public void mouseMoved(MouseEvent e)
Ignores the event if the window selection mode is not SelectableChartPanel.WindowSelectionMode.ZOOM_IN_CHART, to avoid conflicts between the two listeners.