A delegate that handles the specification or automatic calculation of the
interval surrounding the x-values in a dataset. This is used to extend
a regular
interface.
The decorator pattern was not used because of the several possibly
implemented interfaces of the decorated instance (e.g.
TableXYDataset , RangeInfo , DomainInfo etc.).
The width can be set manually or calculated automatically. The switch
autoWidth allows to determine which behavior is used. The auto width
calculation tries to find the smallest gap between two x-values in the
dataset. If there is only one item in the series, the auto width
calculation fails and falls back on the manually set interval width (which
is itself defaulted to 1.0).
| Method from org.jfree.data.xy.IntervalXYDelegate Detail: |
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
|
public void datasetChanged(DatasetChangeEvent e) {
// TODO: by coding the event with some information about what changed
// in the dataset, we could make the recalculation of the interval
// more efficient in some cases...
if (this.autoWidth) {
this.autoIntervalWidth = recalculateInterval();
}
}
Handles events from the dataset by recalculating the interval if
necessary. |
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof IntervalXYDelegate)) {
return false;
}
IntervalXYDelegate that = (IntervalXYDelegate) obj;
if (this.autoWidth != that.autoWidth) {
return false;
}
if (this.intervalPositionFactor != that.intervalPositionFactor) {
return false;
}
if (this.fixedIntervalWidth != that.fixedIntervalWidth) {
return false;
}
return true;
}
Tests the delegate for equality with an arbitrary object. |
public Range getDomainBounds(boolean includeInterval) {
// first get the range without the interval, then expand it for the
// interval width
Range range = DatasetUtilities.findDomainBounds(this.dataset, false);
if (includeInterval && range != null) {
double lowerAdj = getIntervalWidth() * getIntervalPositionFactor();
double upperAdj = getIntervalWidth() - lowerAdj;
range = new Range(range.getLowerBound() - lowerAdj,
range.getUpperBound() + upperAdj);
}
return range;
}
Returns the range of the values in the dataset's domain, including
or excluding the interval around each x-value as specified. |
public double getDomainLowerBound(boolean includeInterval) {
double result = Double.NaN;
Range r = getDomainBounds(includeInterval);
if (r != null) {
result = r.getLowerBound();
}
return result;
}
Returns the minimum x-value in the dataset. |
public double getDomainUpperBound(boolean includeInterval) {
double result = Double.NaN;
Range r = getDomainBounds(includeInterval);
if (r != null) {
result = r.getUpperBound();
}
return result;
}
Returns the maximum x-value in the dataset. |
public Number getEndX(int series,
int item) {
Number endX = null;
Number x = this.dataset.getX(series, item);
if (x != null) {
endX = new Double(x.doubleValue()
+ ((1.0 - getIntervalPositionFactor()) * getIntervalWidth()));
}
return endX;
}
Returns the end value of the x-interval for an item within a series. |
public double getEndXValue(int series,
int item) {
return this.dataset.getXValue(series, item)
+ (1.0 - getIntervalPositionFactor()) * getIntervalWidth();
}
Returns the end value of the x-interval for an item within a series. |
public double getFixedIntervalWidth() {
return this.fixedIntervalWidth;
}
Returns the fixed interval width. |
public double getIntervalPositionFactor() {
return this.intervalPositionFactor;
}
Returns the interval position factor. |
public double getIntervalWidth() {
if (isAutoWidth() && !Double.isInfinite(this.autoIntervalWidth)) {
// everything is fine: autoWidth is on, and an autoIntervalWidth
// was set.
return this.autoIntervalWidth;
}
else {
// either autoWidth is off or autoIntervalWidth was not set.
return this.fixedIntervalWidth;
}
}
Returns the interval width. This method will return either the
auto calculated interval width or the manually specified interval
width, depending on the #isAutoWidth() result. |
public Number getStartX(int series,
int item) {
Number startX = null;
Number x = this.dataset.getX(series, item);
if (x != null) {
startX = new Double(x.doubleValue()
- (getIntervalPositionFactor() * getIntervalWidth()));
}
return startX;
}
Returns the start value of the x-interval for an item within a series. |
public double getStartXValue(int series,
int item) {
return this.dataset.getXValue(series, item)
- getIntervalPositionFactor() * getIntervalWidth();
}
Returns the start value of the x-interval for an item within a series. |
public boolean isAutoWidth() {
return this.autoWidth;
}
Returns true if the interval width is automatically
calculated, and false otherwise. |
public void setAutoWidth(boolean b) {
this.autoWidth = b;
if (b) {
this.autoIntervalWidth = recalculateInterval();
}
}
Sets the flag that indicates whether the interval width is automatically
calculated. If the flag is set to true, the interval is
recalculated.
Note: recalculating the interval amounts to changing the data values
represented by the dataset. The calling dataset must fire an
appropriate DatasetChangeEvent . |
public void setFixedIntervalWidth(double w) {
if (w < 0.0) {
throw new IllegalArgumentException("Negative 'w' argument.");
}
this.fixedIntervalWidth = w;
this.autoWidth = false;
}
Sets the fixed interval width and, as a side effect, sets the
autoWidth flag to false.
Note that changing the interval width amounts to changing the data
values represented by the dataset. Therefore, the dataset
that is using this delegate is responsible for generating the
appropriate DatasetChangeEvent . |
public void setIntervalPositionFactor(double d) {
if (d < 0.0 || 1.0 < d) {
throw new IllegalArgumentException(
"Argument 'd' outside valid range.");
}
this.intervalPositionFactor = d;
}
Sets the interval position factor. This controls how the interval is
aligned to the x-value. For a value of 0.5, the interval is aligned
with the x-value in the center. For a value of 0.0, the interval is
aligned with the x-value at the lower end of the interval, and for a
value of 1.0, the interval is aligned with the x-value at the upper
end of the interval.
Note that changing the interval position factor amounts to changing the
data values represented by the dataset. Therefore, the dataset that is
using this delegate is responsible for generating the
appropriate DatasetChangeEvent . |