JIDE 3.5.15

com.jidesoft.chart.model
Class DefaultChartModel

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

public class DefaultChartModel
extends Object
implements AnnotatedChartModel, RangeProvider, Comparable<ChartModel>

A default implementation of the ChartModel interface; now with improved API such that the add and remove methods return the ChartModel instance.

This allows chaining of method calls, as in:

 ChartModel m = new DefaultChartModel();
 m.addPoint(1, 2).addPoint(2, 3).addPoint(6, 7);
 

DefaultChartModel now also implements Comparable so it is easy to sort multiple model alphabetically by their names

Note It is no longer possible to specify the order in which points are iterated by setting an orientation property. They are iterated in the order in which they were added. If they should be iterated over along the x or y axis, then wrap this model in a SortedChartModel.

Author:
Simon White (swhite@catalysoft.com)

Constructor Summary
DefaultChartModel()
          Zero argument constructor creates a DefaultChartModel with no points
DefaultChartModel(DefaultChartModel model)
          Creates a DefaultChartModel as a copy of an existing DefaultChartModel
DefaultChartModel(Object key)
          The key provided here is used in the equals() method and can be used to help uniquely identify the model.
 
Method Summary
 void addAnnotation(Annotation annotation)
          Add the supplied annotation
 void addChartModelListener(ChartModelListener listener)
          Register the listener's interest in this chart model.
 DefaultChartModel addPoint(Chartable point)
          Appends a point to the model and fires an update event
 DefaultChartModel addPoint(Chartable point, boolean fireUpdate)
          Adds a point to the chart model as a Chartable, and specifying whether a change event should be fired following the change.
 DefaultChartModel addPoint(double x, double y)
          Adds a point to the chart model, then fires an update event
 DefaultChartModel addPoint(double x, double y, boolean fireUpdate)
          Adds a point to the chart model using doubles and specifying whether an event should be fired
 DefaultChartModel addPoint(double x, int y)
          Adds a point to the ChartModel using the supplied x and y values, then fires an update event
 DefaultChartModel addPoint(double x, Positionable y)
          Adds a point to the chart model using a double and a Positionable, then fires an update event
 DefaultChartModel addPoint(double x, Positionable y, boolean fireUpdate)
          Adds a point to the chart model using a double and a Positionable and specifying whether an event should be fired
 DefaultChartModel addPoint(int index, Chartable point)
          Inserts a point in the chart model at the given index.
 DefaultChartModel addPoint(int index, Chartable point, boolean fireUpdate)
          Inserts a point to the chart model at the given index, also specifying whether a change event should be fired following the change.
 DefaultChartModel addPoint(int x, double y)
          Adds a point to the ChartModel using the supplied x and y values, then fires an update event
 DefaultChartModel addPoint(int x, int y)
          Adds a point to the ChartModel using the supplied x and y values, then fires an update event.
 DefaultChartModel addPoint(Positionable x, double y)
          Adds a point to the chart model using a Positionable and a double, then fires an update event
 DefaultChartModel addPoint(Positionable x, double y, boolean fireUpdate)
          Adds a point to the chart model using a Positionable and a double and specifying whether an event should be fired
 DefaultChartModel addPoint(Positionable x, Positionable y)
          Adds a point to the chart model using two Positionable instances, then fires an update event
 DefaultChartModel addPoint(Positionable x, Positionable y, boolean fireUpdate)
          Adds a point to the chart model using Positionables and specifying whether an event should be fired
 void clearAnnotations()
          Clear all the annotations in the model
 void clearPoints()
          Remove all the points in the model and fire a model change event
 int compareTo(ChartModel other)
           
 boolean equals(Object other)
           
protected  void fireModelChanged()
          Fire an 'all bets off' change event to the listeners
protected  void fireModelChanged(ChartModelChangeEvent changeEvent)
          Fire the supplied change event to the listeners
 Annotation getAnnotation(int n)
          Gets the nth annotation.
 int getAnnotationCount()
          Returns the number of annotations on this model
 Object getKey()
          A key is a more generalised association than a name.
 String getName()
          The name of a ChartModel is important, as different chart models are assumed to have different names.
 Chartable getPoint(int index)
          Gets the nth point.
 int getPointCount()
          Gets the number of points in the data set
 double getXLeadingMarginProportion()
          Deprecated. this method will be removed some time after release 3.3.3
 Range<Double> getXRange()
          Returns the X range of the points of the model
 Range<Double> getXRange(double leadingMarginProportion, double trailingMarginProportion)
           
 double getXTrailingMarginProportion()
          Deprecated. this method will be removed some time after release 3.3.3
 double getYLeadingMarginProportion()
          Deprecated. this method will be removed some time after release 3.3.3
 Range<Double> getYRange()
          Returns the Y Range of the points of the model
 Range<Double> getYRange(double leadingMarginProportion, double trailingMarginProportion)
          Returns a range, but applies a margin to the start and end of the range.
 double getYTrailingMarginProportion()
          Deprecated. this method will be removed some time after release 3.3.3
 int hashCode()
           
 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?
 boolean isFiringEventsOnEDT()
           
 Iterator<Chartable> iterator()
           
 void removeAnnotation(Annotation annotation)
          Remove the supplied annotation
 void removeChartModelListener(ChartModelListener listener)
          De-register the listener's interest in this chart model.
 DefaultChartModel removePoint(Chartable p)
          Remove the supplied point from the model.
 DefaultChartModel removePoint(Chartable p, boolean fireUpdate)
          Remove the supplied point from the model, and indicate whether a change event should be fired from this model to its listeners.
 DefaultChartModel removePoint(int index)
          Remove the point from the model at the supplied index
 DefaultChartModel removePoint(int index, boolean fireUpdate)
          Remove the point from the model at the supplied index, and indicate whether a change event should be fired from this model to its listeners.
 DefaultChartModel replacePoint(int index, Chartable c)
          Replace the point in the model at the specified index
 DefaultChartModel replacePoint(int index, Chartable c, boolean fireUpdate)
          Replace the point in the model at the specified index, and specify whether an event should be fired to notify interested listeners.
 void setAnnotationsVisible(boolean visible)
          Specify whether annotations should be displayed.
 void setCyclical(boolean cyclical)
          Specify whether the model is cyclical.
 void setFiringEventsOnEDT(boolean firingEventsOnEDT)
           
 void setName(String name)
          Sets the name of the ChartModel.
 void setXLeadingMarginProportion(double marginProportion)
          Deprecated. this method will be removed some time after release 3.3.3
 void setXTrailingMarginProportion(double marginProportion)
          Deprecated. this method will be removed some time after release 3.3.3
 void setYLeadingMarginProportion(double marginProportion)
          Deprecated. this method will be removed some time after release 3.3.3
 void setYTrailingMarginProportion(double marginProportion)
          Deprecated. this method will be removed some time after release 3.3.3
 String toString()
           
 void update()
          You can call this if you make changes to the model that would not normally fire an update event.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultChartModel

public DefaultChartModel()
Zero argument constructor creates a DefaultChartModel with no points


DefaultChartModel

public DefaultChartModel(DefaultChartModel model)
Creates a DefaultChartModel as a copy of an existing DefaultChartModel

Parameters:
model - the ChartModel to copy

DefaultChartModel

public DefaultChartModel(Object key)
The key provided here is used in the equals() method and can be used to help uniquely identify the model. It can be used for debugging or for storing a closely associated object within the model.

Parameters:
key - the key object that uniquely identifies the object
Method Detail

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

getKey

public Object getKey()
A key is a more generalised association than a name. Usually this is simply a string but allowing the use of an object is useful.

Returns:
the key (name) of the model

setName

public void setName(String name)
Sets the name of the ChartModel. This is important as the name is used as part of the identity of the object (for example, in the equals() method).

Note: Do not change the name of a model once it has been added to a chart.

Parameters:
name - the new name of the ChartModel

isFiringEventsOnEDT

public boolean isFiringEventsOnEDT()

setFiringEventsOnEDT

public void setFiringEventsOnEDT(boolean firingEventsOnEDT)

getPoint

public Chartable getPoint(int index)
Gets the nth point. The first point has index 0.

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

clearPoints

public void clearPoints()
Remove all the points in the model and fire a model change event


clearAnnotations

public void clearAnnotations()
Clear all the annotations in the model


getPointCount

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

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

addPoint

public DefaultChartModel addPoint(Chartable point)
Appends a point to the model and fires an update event

Parameters:
point - the point to add
Returns:
this model

addPoint

public DefaultChartModel addPoint(int x,
                                  int y)
Adds a point to the ChartModel using the supplied x and y values, then fires an update event.

If you're working in pure Java, this method is subsumed by the addPoint(double, double) method, but if you're accessing the library through, say, Clojure, then it won't match on the signature if you provide whole numbers. So we provide this signature too.

Parameters:
x - the x coordinate as an int
y - the y coordinate as an int
Returns:
this DefaultChartModel instance

addPoint

public DefaultChartModel addPoint(int x,
                                  double y)
Adds a point to the ChartModel using the supplied x and y values, then fires an update event

Parameters:
x - the x coordinate as an int
y - the y coordinate as a double
Returns:
this DefaultChartModel instance
See Also:
addPoint(int, int)

addPoint

public DefaultChartModel addPoint(double x,
                                  int y)
Adds a point to the ChartModel using the supplied x and y values, then fires an update event

Parameters:
x - the x coordinate as a double
y - the y coordinate as an int
Returns:
this DefaultChartModel instance
See Also:
addPoint(int, int)

addPoint

public DefaultChartModel addPoint(double x,
                                  double y)
Adds a point to the chart model, then fires an update event

Parameters:
x - the x coordinate
y - the y coordinate
Returns:
this ChartModel instance

addPoint

public DefaultChartModel addPoint(Positionable x,
                                  Positionable y)
Adds a point to the chart model using two Positionable instances, then fires an update event

Parameters:
x - the x coordinate
y - the y coordinate
Returns:
this ChartModel instance

addPoint

public DefaultChartModel addPoint(double x,
                                  Positionable y)
Adds a point to the chart model using a double and a Positionable, then fires an update event

Parameters:
x - the x coordinate
y - the y coordinate
Returns:
this ChartModel instance

addPoint

public DefaultChartModel addPoint(Positionable x,
                                  double y)
Adds a point to the chart model using a Positionable and a double, then fires an update event

Parameters:
x - the x coordinate
y - the y coordinate
Returns:
this ChartModel instance

addPoint

public DefaultChartModel addPoint(double x,
                                  double y,
                                  boolean fireUpdate)
Adds a point to the chart model using doubles and specifying whether an event should be fired

Parameters:
x - the x coordinate
y - the y coordinate
fireUpdate - whether an event should be fired following the change
Returns:
this ChartModel instance

addPoint

public DefaultChartModel addPoint(Positionable x,
                                  Positionable y,
                                  boolean fireUpdate)
Adds a point to the chart model using Positionables and specifying whether an event should be fired

Parameters:
x - the x coordinate
y - the y coordinate
fireUpdate - whether an event should be fired following the change
Returns:
this ChartModel instance

addPoint

public DefaultChartModel addPoint(double x,
                                  Positionable y,
                                  boolean fireUpdate)
Adds a point to the chart model using a double and a Positionable and specifying whether an event should be fired

Parameters:
x - the x coordinate
y - the y coordinate
fireUpdate - whether an event should be fired following the change
Returns:
this ChartModel instance

addPoint

public DefaultChartModel addPoint(Positionable x,
                                  double y,
                                  boolean fireUpdate)
Adds a point to the chart model using a Positionable and a double and specifying whether an event should be fired

Parameters:
x - the x coordinate
y - the y coordinate
fireUpdate - whether an event should be fired following the change
Returns:
this ChartModel instance

addPoint

public DefaultChartModel addPoint(Chartable point,
                                  boolean fireUpdate)
Adds a point to the chart model as a Chartable, and specifying whether a change event should be fired following the change. Usually you would want to fire a change event so that interested listeners, such as a Chart object, are informed of the change immediately. There may be cases, however, where it makes more sense to defer notification. For example, if you are making multiple changes to the DefaultChartModel, it may be more efficient to wait until the end of the batch of changes and then fire a single event rather than fire an event for each individual change.

Parameters:
point - the Chartable point to add
fireUpdate - whether to fire an update event to interested listeners
Returns:
this ChartModel instance

addPoint

public DefaultChartModel addPoint(int index,
                                  Chartable point)
Inserts a point in the chart model at the given index.

Parameters:
index - the index at which the point will be added
point - the point to add
Returns:
this ChartModel instance

addPoint

public DefaultChartModel addPoint(int index,
                                  Chartable point,
                                  boolean fireUpdate)
Inserts a point to the chart model at the given index, also specifying whether a change event should be fired following the change. Usually you would want to fire a change event so that interested listeners, such as a Chart object, are informed of the change immediately. There may be cases, however, where it makes more sense to defer notification. For example, if you are making multiple changes to the DefaultChartModel, it may be more efficient to wait until the end of the batch of changes and then fire a single event rather than fire an event for each individual change.

Parameters:
index - the index at which the point will be added
point - the Chartable point to add
fireUpdate - whether to fire an update event to interested listeners
Returns:
this ChartModel instance

replacePoint

public DefaultChartModel replacePoint(int index,
                                      Chartable c)
Replace the point in the model at the specified index

Parameters:
index - the index of the point to replace. The first index is 0.
c - the new Chartable point to place in the model at the specified index
Returns:
this ChartModel instance

replacePoint

public DefaultChartModel replacePoint(int index,
                                      Chartable c,
                                      boolean fireUpdate)
Replace the point in the model at the specified index, and specify whether an event should be fired to notify interested listeners.

Parameters:
index - the index of the point to replace. The first index is 0
c - the new Chartable point to place in the model at the specified index
fireUpdate - whether an event should be fired to notify listeners
Returns:
this ChartModel instance

removePoint

public DefaultChartModel removePoint(int index)
Remove the point from the model at the supplied index

Parameters:
index - the index of the point to remove. The first index is 0.
Returns:
this ChartModel instance

removePoint

public DefaultChartModel removePoint(int index,
                                     boolean fireUpdate)
Remove the point from the model at the supplied index, and indicate whether a change event should be fired from this model to its listeners.

Parameters:
index - the index of the point to remove. The first index is 0.
fireUpdate - whether a change event should be fired to listeners following the change.
Returns:
this ChartModel instance

removePoint

public DefaultChartModel removePoint(Chartable p)
Remove the supplied point from the model. Note that for this to work, the hashCode() and equals() methods of the supplied Chartable object should behave properly.

Parameters:
p - the point to remove
Returns:
this ChartModel instance

removePoint

public DefaultChartModel removePoint(Chartable p,
                                     boolean fireUpdate)
Remove the supplied point from the model, and indicate whether a change event should be fired from this model to its listeners.

Parameters:
p - the point to remove
fireUpdate - whether a change event should be fired to listeners following the change.
Returns:
this ChartModel instance

getAnnotationCount

public int getAnnotationCount()
Returns the number of annotations on this model

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

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 annotation with index n

addAnnotation

public void addAnnotation(Annotation annotation)
Add the supplied annotation

Parameters:
annotation - the annotation to add

removeAnnotation

public void removeAnnotation(Annotation annotation)
Remove the supplied annotation

Parameters:
annotation - the annotation object to remove from the model

getXLeadingMarginProportion

public double getXLeadingMarginProportion()
Deprecated. this method will be removed some time after release 3.3.3


setXLeadingMarginProportion

public void setXLeadingMarginProportion(double marginProportion)
Deprecated. this method will be removed some time after release 3.3.3

You can set a 10% margin by supplying 0.1 here to make sure all points are clearly within the Range


getYLeadingMarginProportion

public double getYLeadingMarginProportion()
Deprecated. this method will be removed some time after release 3.3.3


setYLeadingMarginProportion

public void setYLeadingMarginProportion(double marginProportion)
Deprecated. this method will be removed some time after release 3.3.3

You can set a 10% margin by supplying 0.1 here to make sure all points are clearly within the Range


getXTrailingMarginProportion

public double getXTrailingMarginProportion()
Deprecated. this method will be removed some time after release 3.3.3


setXTrailingMarginProportion

public void setXTrailingMarginProportion(double marginProportion)
Deprecated. this method will be removed some time after release 3.3.3

You can set a 10% margin by supplying 0.1 here to make sure all points are clearly within the Range


getYTrailingMarginProportion

public double getYTrailingMarginProportion()
Deprecated. this method will be removed some time after release 3.3.3


setYTrailingMarginProportion

public void setYTrailingMarginProportion(double marginProportion)
Deprecated. this method will be removed some time after release 3.3.3

You can set a 10% margin by supplying 0.1 here to make sure all points are clearly within the Range


getXRange

public Range<Double> getXRange()
Returns the X range of the points of the model

Specified by:
getXRange in interface RangeProvider
Returns:
the x range of the points of the model

getXRange

public Range<Double> getXRange(double leadingMarginProportion,
                               double trailingMarginProportion)

getYRange

public Range<Double> getYRange()
Returns the Y Range of the points of the model

Specified by:
getYRange in interface RangeProvider
Returns:
the y range of the points of the model

getYRange

public Range<Double> getYRange(double leadingMarginProportion,
                               double trailingMarginProportion)
Returns a range, but applies a margin to the start and end of the range. This can be useful to refine the visual appearance of a chart, where the margin makes it easy to show that the data is wholly contained within the displayed range.

Parameters:
leadingMarginProportion - a number between 0 and 1, typical value 0.05 = 5%
trailingMarginProportion - a number between 0 and 1, typical value 0.05 = 5%
Returns:
a range of values

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 are currently visible. The Chart object calls this before painting annotations.

setAnnotationsVisible

public void setAnnotationsVisible(boolean visible)
Specify whether annotations should be displayed.

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

addChartModelListener

public void addChartModelListener(ChartModelListener listener)
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)
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>

isCyclical

public boolean isCyclical()
Should a line be drawn from the last to the first point?

Specified by:
isCyclical in interface ChartModel
Returns:
whether the model represents a cycle of values

setCyclical

public void setCyclical(boolean cyclical)
Specify whether the model is cyclical. If cyclical, then when rendered with line segments the last point is joined to the first.

Parameters:
cyclical - whether the model is cyclical

update

public void update()
You can call this if you make changes to the model that would not normally fire an update event. For example, if you change all the x and y coordinates by transposing all the points of a model, you can call this so that the listening chart object is updated accordingly.


fireModelChanged

protected void fireModelChanged(ChartModelChangeEvent changeEvent)
Fire the supplied change event to the listeners

Parameters:
changeEvent - the object describing the change that occurred

fireModelChanged

protected void fireModelChanged()
Fire an 'all bets off' change event to the listeners


hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object

compareTo

public int compareTo(ChartModel other)
Specified by:
compareTo in interface Comparable<ChartModel>

toString

public String toString()
Overrides:
toString in class Object

JIDE 3.5.15