com.jrefinery.chart
Class DateAxis

java.lang.Object
  |
  +--com.jrefinery.chart.Axis
        |
        +--com.jrefinery.chart.ValueAxis
              |
              +--com.jrefinery.chart.DateAxis
All Implemented Interfaces:
AxisConstants
Direct Known Subclasses:
HorizontalDateAxis

public abstract class DateAxis
extends ValueAxis

The base class for axes that display java.util.Date values.

You will find it easier to understand how this axis works if you bear in mind that it really displays/measures integer (or long) data, where the integers are milliseconds since midnight, 1-Jan-1970. When displaying tick labels, the millisecond values are converted back to dates using a DateFormat instance.

Author:
DG
See Also:
HorizontalDateAxis

Field Summary
static java.util.Date DEFAULT_ANCHOR_DATE
          The default anchor date.
static java.util.Date DEFAULT_CROSSHAIR_DATE
          The default crosshair date.
static DateTickUnit DEFAULT_DATE_TICK_UNIT
          The default date tick unit.
 
Fields inherited from class com.jrefinery.chart.ValueAxis
DEFAULT_AUTO_RANGE, DEFAULT_AUTO_RANGE_MINIMUM_SIZE, DEFAULT_CROSSHAIR_PAINT, DEFAULT_CROSSHAIR_STROKE, DEFAULT_CROSSHAIR_VISIBLE, DEFAULT_GRID_LINE_PAINT, DEFAULT_GRID_LINE_STROKE, DEFAULT_LOWER_BOUND, DEFAULT_LOWER_MARGIN, DEFAULT_RANGE, DEFAULT_UPPER_BOUND, DEFAULT_UPPER_MARGIN, MAXIMUM_TICK_COUNT
 
Fields inherited from class com.jrefinery.chart.Axis
fixedDimension, label, labelFont, labelInsets, labelPaint, plot, tickLabelFont, tickLabelInsets, tickLabelPaint, tickLabelsVisible, tickMarkPaint, tickMarkStroke, tickMarksVisible, ticks, visible
 
Fields inherited from interface com.jrefinery.chart.AxisConstants
DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_PAINT, DEFAULT_TICK_STROKE
 
Constructor Summary
protected DateAxis(java.lang.String label)
          Constructs a date axis, using default values where necessary.
protected DateAxis(java.lang.String label, java.awt.Font labelFont, java.awt.Paint labelPaint, java.awt.Insets labelInsets, boolean tickLabelsVisible, java.awt.Font tickLabelFont, java.awt.Paint tickLabelPaint, java.awt.Insets tickLabelInsets, boolean tickMarksVisible, java.awt.Stroke tickMarkStroke, java.awt.Paint tickMarkPaint, boolean autoRange, java.lang.Number autoRangeMinimumSize, Range range, boolean autoTickUnitSelection, TickUnits standardTickUnits, DateTickUnit tickUnit, java.text.SimpleDateFormat tickLabelFormatter, boolean gridLinesVisible, java.awt.Stroke gridStroke, java.awt.Paint gridPaint, java.util.Date anchorDate, boolean crosshairVisible, java.util.Date crosshairDate, java.awt.Stroke crosshairStroke, java.awt.Paint crosshairPaint)
          Constructs a date axis.
 
Method Summary
 java.util.Date calculateHighestVisibleTickValue(DateTickUnit unit)
          Calculates the value of the highest visible tick on the axis.
 java.util.Date calculateLowestVisibleTickValue(DateTickUnit unit)
          Calculates the value of the lowest visible tick on the axis.
static TickUnits createStandardDateTickUnits()
          Returns a collection of standard date tick units.
 java.util.Date getAnchorDate()
          Returns the anchor date for the axis.
 java.util.Date getCrosshairDate()
          Returns the crosshair date for the axis.
 java.util.Date getMaximumDate()
          Returns the latest date visible on the axis.
 java.util.Date getMinimumDate()
          Returns the earliest date visible on the axis.
 DateTickUnit getTickUnit()
          Returns the tick unit for the axis.
protected  java.util.Date nextStandardDate(java.util.Date date, DateTickUnit unit)
          Returns the first "standard" date (based on the specified field and units).
protected  java.util.Date previousStandardDate(java.util.Date date, DateTickUnit unit)
          Returns the previous "standard" date, for a given date and tick unit.
 void setAnchorDate(java.util.Date anchorDate)
          Sets the anchor date for the axis.
 void setAnchorValue(double value)
          Sets the anchor value.
 void setAxisRange(double lower, double upper)
          Deprecated. use setRange(double, double) method.
 void setCrosshairDate(java.util.Date crosshairDate)
          Sets the crosshair date for the axis.
 void setMaximumDate(java.util.Date maximumDate)
          Sets the maximum date visible on the axis.
 void setMinimumDate(java.util.Date minimumDate)
          Sets the minimum date visible on the axis.
 void setRange(java.util.Date lower, java.util.Date upper)
          Sets the axis range.
 void setRange(double lower, double upper)
          Sets the axis range.
 void setRange(Range range)
          Sets the upper and lower bounds for the axis.
 void setTickUnit(DateTickUnit unit)
          Sets the tick unit for the axis.
protected  void setTickUnitAttribute(DateTickUnit unit)
          Sets the tick unit attribute without any other side effects.
 
Methods inherited from class com.jrefinery.chart.ValueAxis
autoAdjustRange, centerRange, getAnchorValue, getAutoRangeMinimumSize, getAutoTickIndex, getCrosshairPaint, getCrosshairStroke, getCrosshairValue, getFixedAutoRange, getGridPaint, getGridStroke, getLowerMargin, getMaximumAxisValue, getMinimumAxisValue, getRange, getStandardTickUnits, getUpperMargin, isAutoRange, isAutoTickUnitSelection, isCrosshairLockedOnData, isCrosshairVisible, isGridLinesVisible, resizeRange, resizeRange, setAnchoredRange, setAnchorValueAttribute, setAutoRange, setAutoRangeAttribute, setAutoRangeMinimumSize, setAutoRangeMinimumSizeAttribute, setAutoTickIndex, setAutoTickUnitSelection, setAutoTickUnitSelectionAttribute, setCrosshairLockedOnData, setCrosshairPaint, setCrosshairStroke, setCrosshairValue, setCrosshairValue, setCrosshairValueAttribute, setCrosshairVisible, setFixedAutoRange, setGridLinesVisible, setGridPaint, setGridStroke, setLowerMargin, setMaximumAxisValue, setMinimumAxisValue, setRangeAboutValue, setRangeAttribute, setStandardTickUnits, setUpperMargin, translateJava2DtoValue, translateValueToJava2D
 
Methods inherited from class com.jrefinery.chart.Axis
addChangeListener, configure, draw, getFixedDimension, getLabel, getLabelFont, getLabelInsets, getLabelPaint, getMaxTickLabelWidth, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkPaint, getTickMarkStroke, isCompatiblePlot, isTickLabelsVisible, isTickMarksVisible, isVisible, notifyListeners, refreshTicks, removeChangeListener, setFixedDimension, setLabel, setLabelFont, setLabelInsets, setLabelPaint, setPlot, setTickLabelFont, setTickLabelInsets, setTickLabelPaint, setTickLabelsVisible, setTickMarkPaint, setTickMarkStroke, setTickMarksVisible, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DATE_TICK_UNIT

public static final DateTickUnit DEFAULT_DATE_TICK_UNIT
The default date tick unit.

DEFAULT_ANCHOR_DATE

public static final java.util.Date DEFAULT_ANCHOR_DATE
The default anchor date.

DEFAULT_CROSSHAIR_DATE

public static final java.util.Date DEFAULT_CROSSHAIR_DATE
The default crosshair date.
Constructor Detail

DateAxis

protected DateAxis(java.lang.String label)
Constructs a date axis, using default values where necessary.
Parameters:
label - the axis label (null permitted).

DateAxis

protected DateAxis(java.lang.String label,
                   java.awt.Font labelFont,
                   java.awt.Paint labelPaint,
                   java.awt.Insets labelInsets,
                   boolean tickLabelsVisible,
                   java.awt.Font tickLabelFont,
                   java.awt.Paint tickLabelPaint,
                   java.awt.Insets tickLabelInsets,
                   boolean tickMarksVisible,
                   java.awt.Stroke tickMarkStroke,
                   java.awt.Paint tickMarkPaint,
                   boolean autoRange,
                   java.lang.Number autoRangeMinimumSize,
                   Range range,
                   boolean autoTickUnitSelection,
                   TickUnits standardTickUnits,
                   DateTickUnit tickUnit,
                   java.text.SimpleDateFormat tickLabelFormatter,
                   boolean gridLinesVisible,
                   java.awt.Stroke gridStroke,
                   java.awt.Paint gridPaint,
                   java.util.Date anchorDate,
                   boolean crosshairVisible,
                   java.util.Date crosshairDate,
                   java.awt.Stroke crosshairStroke,
                   java.awt.Paint crosshairPaint)
Constructs a date axis.
Parameters:
label - the axis label (null permitted).
labelFont - the font for displaying the axis label.
labelPaint - the paint used to draw the axis label.
labelInsets - determines the amount of blank space around the label.
tickLabelsVisible - flag indicating whether or not tick labels are visible.
tickLabelFont - the font used to display tick labels.
tickLabelPaint - the paint used to draw tick labels.
tickLabelInsets - determines the amount of blank space around tick labels.
tickMarksVisible - flag indicating whether or not tick marks are visible.
tickMarkStroke - the stroke used to draw tick marks (if visible).
tickMarkPaint - the paint used to draw tick marks (if visible).
autoRange - flag indicating whether the axis range is automatically adjusted to fit the data.
autoRangeMinimumSize - the smallest range allowed when the axis range is calculated to fit the data.
range - the axis range.
autoTickUnitSelection - a flag indicating whether the tick unit is automatically selected.
standardTickUnits - the standard tick units.
tickUnit - the tick unit.
tickLabelFormatter - formatter to use for date formatting.
gridLinesVisible - flag indicating whether or not grid lines are visible.
gridStroke - the Stroke used to display grid lines (if visible).
gridPaint - the Paint used to display grid lines (if visible).
anchorDate - the anchor date.
crosshairVisible - a flag controlling whether the crosshair is visible for this axis.
crosshairDate - the crosshair date.
crosshairStroke - the crosshair stroke.
crosshairPaint - the crosshair paint.
Method Detail

setRange

public void setRange(Range range)
Sets the upper and lower bounds for the axis. Registered listeners are notified of the change.

As a side-effect, the auto-range flag is set to false.

Overrides:
setRange in class ValueAxis
Parameters:
range - the new range.

setRange

public void setRange(java.util.Date lower,
                     java.util.Date upper)
Sets the axis range.
Parameters:
lower - the lower bound for the axis.
upper - the upper bound for the axis.

setRange

public void setRange(double lower,
                     double upper)
Sets the axis range.
Overrides:
setRange in class ValueAxis
Parameters:
lower - the lower bound for the axis.
upper - the upper bound for the axis.

getMinimumDate

public java.util.Date getMinimumDate()
Returns the earliest date visible on the axis.
Returns:
the earliest date visible on the axis.

setMinimumDate

public void setMinimumDate(java.util.Date minimumDate)
Sets the minimum date visible on the axis.
Parameters:
minimumDate - the new minimum date.

getMaximumDate

public java.util.Date getMaximumDate()
Returns the latest date visible on the axis.
Returns:
the latest date visible on the axis.

setMaximumDate

public void setMaximumDate(java.util.Date maximumDate)
Sets the maximum date visible on the axis.
Parameters:
maximumDate - the new maximum date.

getTickUnit

public DateTickUnit getTickUnit()
Returns the tick unit for the axis.
Returns:
the tick unit for the axis.

setTickUnit

public void setTickUnit(DateTickUnit unit)
Sets the tick unit for the axis.
Parameters:
unit - the new date unit.

setTickUnitAttribute

protected void setTickUnitAttribute(DateTickUnit unit)
Sets the tick unit attribute without any other side effects.
Parameters:
unit - the new tick unit.

getAnchorDate

public java.util.Date getAnchorDate()
Returns the anchor date for the axis.
Returns:
the anchor date for the axis (possibly null).

setAnchorDate

public void setAnchorDate(java.util.Date anchorDate)
Sets the anchor date for the axis.
Parameters:
anchorDate - the new anchor date (null permitted).

setAnchorValue

public void setAnchorValue(double value)
Sets the anchor value.

This method keeps the anchorDate and anchorValue in synch.

Overrides:
setAnchorValue in class ValueAxis
Parameters:
value - the new value.

getCrosshairDate

public java.util.Date getCrosshairDate()
Returns the crosshair date for the axis.
Returns:
the crosshair date for the axis (possibly null).

setCrosshairDate

public void setCrosshairDate(java.util.Date crosshairDate)
Sets the crosshair date for the axis.
Parameters:
crosshairDate - the new crosshair date (null permitted).

calculateLowestVisibleTickValue

public java.util.Date calculateLowestVisibleTickValue(DateTickUnit unit)
Calculates the value of the lowest visible tick on the axis.
Parameters:
unit - date unit to use.
Returns:
The value of the lowest visible tick on the axis.

calculateHighestVisibleTickValue

public java.util.Date calculateHighestVisibleTickValue(DateTickUnit unit)
Calculates the value of the highest visible tick on the axis.
Parameters:
unit - date unit to use.
Returns:
the value of the highest visible tick on the axis.

previousStandardDate

protected java.util.Date previousStandardDate(java.util.Date date,
                                              DateTickUnit unit)
Returns the previous "standard" date, for a given date and tick unit.
Parameters:
date - the reference date.
unit - the tick unit.
Returns:
the previous "standard" date.

nextStandardDate

protected java.util.Date nextStandardDate(java.util.Date date,
                                          DateTickUnit unit)
Returns the first "standard" date (based on the specified field and units).
Parameters:
date - the reference date.
unit - the date tick unit.
Returns:
the next "standard" date.

createStandardDateTickUnits

public static TickUnits createStandardDateTickUnits()
Returns a collection of standard date tick units. This collection will be used by default, but you are free to create your own collection if you want to (see the setStandardTickUnits(...) method inherited from the ValueAxis class).
Returns:
a collection of standard date tick units.

setAxisRange

public void setAxisRange(double lower,
                         double upper)
Deprecated. use setRange(double, double) method.

Sets the axis range.
Parameters:
lower - the lower bound for the axis.
upper - the upper bound for the axis.