JIDE 3.5.15

com.jidesoft.chart.model
Class SortedChartModel

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

public class SortedChartModel
extends Object
implements AnnotatedChartModel, ChartModelListener

Sorts the points of a chart model in increasing order. Note that the underlying unsorted model remains unchanged, but this class presents a sorted wrapper for it so that, for example, an unordered scatter plot can be displayed as a line chart in which the line progresses left to right or top to bottom instead of a random squiggle.

The class allows you to specify an orientation for the sort, which means whether the sort is based on the x or the y values. If the orientation is horizontal the sort order is based on the y values and if the orientation is vertical the sort order is based on the x values (to understand the orientation consider sorting the bars of a bar chart).


Constructor Summary
SortedChartModel()
          Create an empty SortedChartModel.
SortedChartModel(ChartModel delegate, Orientation orientation)
          Create a SortedChartModel as a ChartModel that wraps the delegate, and with the sort orientation (x or y) defined by the orientation parameter.
SortedChartModel(ChartModel delegate, Orientation orientation, boolean sortIncreasing)
          Create a SortedChartModel as a ChartModel that wraps the delegate, and with the sort orientation (x or y) defined by the orientation parameter.
 
Method Summary
 void addChartModelListener(ChartModelListener listener)
          Adds the supplied ChartModelListener as a listener to this model
 void chartModelChanged()
          Forces a re-computation of the sort order and fires a change event.
protected  void fireModelChanged()
           
 Annotation getAnnotation(int n)
          Gets the nth annotation.
 int getAnnotationCount()
          Returns the number of annotations
 ChartModel getDelegate()
          Returns the underlying unsorted model
 Integer getDelegateIndex(int n)
          Returns the index in the delegate model of the nth point of this model
 String getName()
          returns the name of the model
 Orientation getOrientation()
          Returns the orientation of the sort - vertical for x values and horizontal for y values
 Chartable getPoint(int n)
          Returns the Chartable object for the nth point of this model
 int getPointCount()
          Returns the number of points in the model
 boolean isAnnotationsVisible()
          Use this method to discover whether annotations should be shown or hidden.
 boolean isCyclical()
          Returns whether the model is cyclical
 boolean isSortIncreasing()
          Returns a boolean to indicate whether the sort is increasing.
 Iterator<Chartable> iterator()
          Returns an iterator over all the points of the model
 void removeChartModelListener(ChartModelListener listener)
          Removes the supplied ChartModelListener from this class
 void setAnnotationsVisible(boolean visible)
          Specify whether annotations should be shown
 void setDelegate(ChartModel delegate)
          Specify the delegate model that is to be sorted
 void setOrientation(Orientation orientation)
          Specify the orientation of the sort
 void setSortIncreasing(boolean sortIncreasing)
          Specify the order of the sort
 void update()
          Recomputes the sort order
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SortedChartModel

public SortedChartModel()
Create an empty SortedChartModel. You can set a delegate by calling the setDelegate() method


SortedChartModel

public SortedChartModel(ChartModel delegate,
                        Orientation orientation)
Create a SortedChartModel as a ChartModel that wraps the delegate, and with the sort orientation (x or y) defined by the orientation parameter.

Parameters:
delegate - the ChartModel to be sorted
orientation - the orientation of the sort; use vertical for x values and horizontal for y values.

SortedChartModel

public SortedChartModel(ChartModel delegate,
                        Orientation orientation,
                        boolean sortIncreasing)
Create a SortedChartModel as a ChartModel that wraps the delegate, and with the sort orientation (x or y) defined by the orientation parameter.

Parameters:
delegate - the ChartModel to be sorted
orientation - the orientation of the sort; use vertical for x values and horizontal for y values.
sortIncreasing - Specify whether the sort should be for increasing or decreasing values
Method Detail

getOrientation

public Orientation getOrientation()
Returns the orientation of the sort - vertical for x values and horizontal for y values

Returns:
the orientation of the sort

setOrientation

public void setOrientation(Orientation orientation)
Specify the orientation of the sort

Parameters:
orientation - whether the sort is on x or y values (vertical for x values and horizontal for y values)

setDelegate

public void setDelegate(ChartModel delegate)
Specify the delegate model that is to be sorted

Parameters:
delegate - the model that is to be sorted

getDelegate

public ChartModel getDelegate()
Returns the underlying unsorted model

Returns:
the underlying unsorted model

isSortIncreasing

public boolean isSortIncreasing()
Returns a boolean to indicate whether the sort is increasing. If false, the sort order is decreasing.

Returns:
a boolean to indicate whether the sort is increasing.

setSortIncreasing

public void setSortIncreasing(boolean sortIncreasing)
Specify the order of the sort

Parameters:
sortIncreasing - whether the sort is to increasing (true) or decreasing (false)

addChartModelListener

public void addChartModelListener(ChartModelListener listener)
Adds the supplied ChartModelListener as a listener to this model

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

removeChartModelListener

public void removeChartModelListener(ChartModelListener listener)
Removes the supplied ChartModelListener from this class

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

fireModelChanged

protected void fireModelChanged()

chartModelChanged

public void chartModelChanged()
Forces a re-computation of the sort order and fires a change event.

Specified by:
chartModelChanged in interface ChartModelListener

getDelegateIndex

public Integer getDelegateIndex(int n)
Returns the index in the delegate model of the nth point of this model

Parameters:
n - the index of the point in this model
Returns:
the index of the same point in the underlying model

update

public void update()
Recomputes the sort order


getName

public String getName()
returns the name of the model

Specified by:
getName in interface ChartModel
Specified by:
getName in interface Named
Returns:
the name of the model

getPoint

public Chartable getPoint(int n)
Returns the Chartable object for the nth point of this model

Specified by:
getPoint in interface ChartModel
Parameters:
n - the index
Returns:
the corresponding Chartable object

getPointCount

public int getPointCount()
Returns the number of points in the model

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

isCyclical

public boolean isCyclical()
Returns whether the model is cyclical

Specified by:
isCyclical in interface ChartModel
Returns:
whether the model is cyclical

iterator

public Iterator<Chartable> iterator()
Returns an iterator over all the points of the model

Specified by:
iterator in interface Iterable<Chartable>
Returns:
an Iterator over all the points of the model

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

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

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

JIDE 3.5.15