JIDE 3.5.15

com.jidesoft.chart.model
Class TableToChartAdapter

java.lang.Object
  extended by com.jidesoft.chart.model.TableToChartAdapter
All Implemented Interfaces:
AnnotatedChartModel, AnnotationModel, ChartModel, Named, Iterable<Chartable>, EventListener, TableModelListener

public class TableToChartAdapter
extends Object
implements AnnotatedChartModel, TableModelListener

This class converts a table model to a chart model. You can specify the columns to use for the x and y axes respectively, with setXColumn() and setYColumn().

As a table model doesn't contain highlight information, this class also provides a facility to store highlights for points. (These points are usually part of the ChartPoints rather than the ChartModel).

Author:
Simon White (swhite@catalysoft.com)

Field Summary
static String PROPERTY_X_COLUMN
           
static String PROPERTY_Y_COLUMN
           
 
Constructor Summary
TableToChartAdapter(String name, TableModel delegate)
          Construct a Chart Model from a TableModel using columns of the table model
 
Method Summary
 void addAnnotation(Annotation dec)
           
 void addChartModelListener(ChartModelListener listener)
          Register the listener's interest in this chart model.
 void addHighlight(int n, Highlight h)
          Add a highlight for the point with index n
 void addPropertyChangeListener(PropertyChangeListener listener)
          Add a listener to listen for changes in bound properties
 void clearAnnotations()
           
protected  void fireModelChanged()
           
 Annotation getAnnotation(int n)
          Gets the nth annotation.
 int getAnnotationCount()
          Returns the number of annotations
 TableModel getDelegate()
           
 Integer getMaxRow()
           
 Integer getMinRow()
           
 String getName()
          The name of a ChartModel is important, as different chart models are assumed to have different names.
 Chartable getPoint(int n)
          Returns the nth point of the ChartModel by delegating down to the underlying TableModel.
 int getPointCount()
          Gets the number of points in the data set
 int getXColumn()
           
 Range<?> getXRange()
           
 int getYColumn()
           
 Range<?> getYRange()
           
 boolean isAnnotationsVisible()
          Use this method to discover whether annotations should be shown or hidden.
 boolean isCyclical()
          Should a line be drawn from the last to the first point?
 Iterator<Chartable> iterator()
           
 void removeAnnotation(Annotation dec)
           
 void removeChartModelListener(ChartModelListener listener)
          De-register the listener's interest in this chart model.
 void removeHighlight(int n)
          Remove the highlight for the point with index n
 void setAnnotationsVisible(boolean visible)
          Specify whether annotations should be shown
 void setCyclical(boolean cyclical)
           
 void setDelegate(TableModel tableModel)
          Set the delegate table model for this chart model.
 void setMaxRow(Integer maxRow)
          Sets the maximum row index for the points of interest in the table model
 void setMinRow(Integer minRow)
          Sets the minimum row index for the points of interest in the table model
 void setRowInterval(Integer from, Integer to)
          The preferred method to set the row interval in the underlying table model.
 void setXColumn(int xColumn)
          Set the column to use for the x axis
 void setYColumn(int yColumn)
          Set the column to use for the y axis
 void tableChanged(TableModelEvent e)
          This method fires a chart model event to its listeners.
 void update()
          Clear the cache of any points derived from the table model and notify listeners that the model has changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_X_COLUMN

public static final String PROPERTY_X_COLUMN
See Also:
Constant Field Values

PROPERTY_Y_COLUMN

public static final String PROPERTY_Y_COLUMN
See Also:
Constant Field Values
Constructor Detail

TableToChartAdapter

public TableToChartAdapter(String name,
                           TableModel delegate)
Construct a Chart Model from a TableModel using columns of the table model

Parameters:
name - the name of the chart model (used to differentiate from other chart models)
delegate - the underlying table model
Method Detail

setDelegate

public void setDelegate(TableModel tableModel)
Set the delegate table model for this chart model. Also attaches this model as a listener to the table model. You can detach the chart model from the table model by calling this method with either a different table model (and it will attach itself to that model instead) or null.

Parameters:
tableModel - the new delegate table model

getDelegate

public TableModel getDelegate()
Returns:
the underlying table model used as input to this chart model

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Add a listener to listen for changes in bound properties

Parameters:
listener - a property change listener

addHighlight

public void addHighlight(int n,
                         Highlight h)
Add a highlight for the point with index n

Parameters:
n - the index of the point for which we are adding a highlight
h - the highlight of the point

removeHighlight

public void removeHighlight(int n)
Remove the highlight for the point with index n

Parameters:
n - the index of the point for which we are removing a highlight

setRowInterval

public void setRowInterval(Integer from,
                           Integer to)
The preferred method to set the row interval in the underlying table model. This method is preferable over calling both setMinRow() and setMaxRow() because it fires one event for two changes.

Parameters:
from - the (included) start row for the interval
to - the (included) end row for the interval

getMinRow

public Integer getMinRow()

setMinRow

public void setMinRow(Integer minRow)
Sets the minimum row index for the points of interest in the table model

Parameters:
minRow - the minimum row index in the table model

getMaxRow

public Integer getMaxRow()

setMaxRow

public void setMaxRow(Integer maxRow)
Sets the maximum row index for the points of interest in the table model

Parameters:
maxRow - the maximum row index in the table model

getName

public String getName()
The name of a ChartModel is important, as different chart models are assumed to have different names. If you're adding multiple models to a Chart, make sure they have different names.

Specified by:
getName in interface ChartModel
Specified by:
getName in interface Named
Returns:
a distinct name for this data set

getXColumn

public int getXColumn()
Returns:
the table model column index currently being used for the x axis in the chart model

setXColumn

public void setXColumn(int xColumn)
Set the column to use for the x axis

Parameters:
xColumn - the column index in the delegate table model

getYColumn

public int getYColumn()
Returns:
the table model column index currently being used for the y axis in the chart model

setYColumn

public void setYColumn(int yColumn)
Set the column to use for the y axis

Parameters:
yColumn - the column index in the delegate table model

getXRange

public Range<?> getXRange()
Returns:
the Range of values for the x axis. If this is a non-numerical column then a CategoryRange is returned; otherwise a NumericRange is returned.

getYRange

public Range<?> getYRange()
Returns:
the Range of values for the x axis. If this is a non-numerical column then a CategoryRange is returned; otherwise a NumericRange is returned.

getPoint

public Chartable getPoint(int n)
Returns the nth point of the ChartModel by delegating down to the underlying TableModel. If the underlying model contains null(s) for the x or y coordinates, these are carried through to the Chartable that is returned by this method. This approach means that the user of this ChartModel can make decisions about how to deal with nulls; such as replacing them with a default value that can be plotted for example.

The delegate can supply any instance of Number, which includes Double and Integer, but also Float, BigDecimal, BigInteger and others. Regardless of the return type, non-null values are converted to a double so there may be the risk of loss of precision for some types. Make sure the values supplied by the delegate can be represented by a double.

Specified by:
getPoint in interface ChartModel
Parameters:
n - the index
Returns:
the nth point in the ChartModel.

getPointCount

public int getPointCount()
Gets the number of points in the data set

The rules for the point count are as follows:

Specified by:
getPointCount in interface ChartModel
Returns:
the number of points

isCyclical

public boolean isCyclical()
Description copied from interface: ChartModel
Should a line be drawn from the last to the first point?

Specified by:
isCyclical in interface ChartModel
Returns:
false by default

setCyclical

public void setCyclical(boolean cyclical)

getAnnotationCount

public int getAnnotationCount()
Description copied from interface: AnnotationModel
Returns the number of annotations

Specified by:
getAnnotationCount in interface AnnotationModel
Returns:
the number of annotations

clearAnnotations

public void clearAnnotations()

getAnnotation

public Annotation getAnnotation(int n)
Description copied from interface: AnnotationModel
Gets the nth annotation.

Specified by:
getAnnotation in interface AnnotationModel
Parameters:
n - the index.
Returns:
the nth annotation

addAnnotation

public void addAnnotation(Annotation dec)

removeAnnotation

public void removeAnnotation(Annotation dec)

isAnnotationsVisible

public boolean isAnnotationsVisible()
Description copied from interface: AnnotationModel
Use this method to discover whether annotations should be shown or hidden.

Specified by:
isAnnotationsVisible in interface AnnotationModel
Returns:
whether annotations should be shown

setAnnotationsVisible

public void setAnnotationsVisible(boolean visible)
Description copied from interface: AnnotationModel
Specify whether annotations should be shown

Specified by:
setAnnotationsVisible in interface AnnotationModel
Parameters:
visible - whether annotations should be shown

addChartModelListener

public void addChartModelListener(ChartModelListener listener)
Description copied from interface: ChartModel
Register the listener's interest in this chart model.

Specified by:
addChartModelListener in interface ChartModel
Parameters:
listener - the listener that will receive events

removeChartModelListener

public void removeChartModelListener(ChartModelListener listener)
Description copied from interface: ChartModel
De-register the listener's interest in this chart model.

Specified by:
removeChartModelListener in interface ChartModel
Parameters:
listener - the listener that will no longer receive events

iterator

public Iterator<Chartable> iterator()
Specified by:
iterator in interface Iterable<Chartable>

update

public void update()
Clear the cache of any points derived from the table model and notify listeners that the model has changed.


fireModelChanged

protected void fireModelChanged()

tableChanged

public void tableChanged(TableModelEvent e)
This method fires a chart model event to its listeners. If the underlying table model has changed, then the chart model has changed too.

Specified by:
tableChanged in interface TableModelListener

JIDE 3.5.15