com.jrefinery.chart
Class HorizontalDateAxis

java.lang.Object
  extended by com.jrefinery.chart.Axis
      extended by com.jrefinery.chart.ValueAxis
          extended by com.jrefinery.chart.DateAxis
              extended by com.jrefinery.chart.HorizontalDateAxis
All Implemented Interfaces:
AxisConstants, HorizontalAxis

public class HorizontalDateAxis
extends DateAxis
implements HorizontalAxis

A horizontal axis that displays date values. Used in XY plots where the x-values in the dataset are interpreted as milliseconds, encoded in the same way as java.util.Date.

See Also:
XYPlot

Field Summary
protected  boolean verticalTickLabels
          A flag indicating whether or not tick labels are drawn vertically.
 
Fields inherited from class com.jrefinery.chart.DateAxis
anchorDate, crosshairDate, DEFAULT_CROSSHAIR_DATE, standardTickFormats, standardTickUnitMagnitudes, standardTickUnits, tickLabelFormatter, tickUnit
 
Fields inherited from class com.jrefinery.chart.ValueAxis
anchorValue, autoRange, autoTickIndex, autoTickUnitSelection, crosshairLockedOnData, crosshairPaint, crosshairStroke, crosshairValue, crosshairVisible, DEFAULT_AUTO_RANGE, DEFAULT_CROSSHAIR_PAINT, DEFAULT_CROSSHAIR_STROKE, DEFAULT_CROSSHAIR_VISIBLE, DEFAULT_GRID_LINE_PAINT, DEFAULT_GRID_LINE_STROKE, DEFAULT_MAXIMUM_AXIS_VALUE, DEFAULT_MINIMUM_AXIS_VALUE, fixedAutoRange, gridLinesVisible, gridPaint, gridStroke, maximumRangeLength, minimumRangeLength, range
 
Fields inherited from class com.jrefinery.chart.Axis
fixedDimension, label, labelFont, labelInsets, labelPaint, listeners, plot, tickLabelFont, tickLabelInsets, tickLabelPaint, tickLabelsVisible, 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_STROKE
 
Constructor Summary
HorizontalDateAxis()
          Constructs a HorizontalDateAxis, using default values where necessary.
HorizontalDateAxis(java.lang.String label)
          Constructs a horizontal date axis, using default values where necessary.
HorizontalDateAxis(java.lang.String label, java.awt.Font labelFont, java.awt.Paint labelPaint, java.awt.Insets labelInsets, boolean showTickLabels, java.awt.Font tickLabelFont, java.awt.Paint tickLabelPaint, java.awt.Insets tickLabelInsets, boolean verticalTickLabels, boolean showTickMarks, java.awt.Stroke tickMarkStroke, boolean autoRange, Range range, boolean autoUnits, DateUnit tickUnits, java.text.SimpleDateFormat tickLabelFormatter, boolean gridVisible, java.awt.Stroke gridStroke, java.awt.Paint gridPaint, boolean crosshairVisible, java.util.Date crosshairDate, java.awt.Stroke crosshairStroke, java.awt.Paint crosshairPaint)
          Constructs a HorizontalDateAxis.
HorizontalDateAxis(java.lang.String label, java.awt.Font labelFont, Range range)
          Constructs a HorizontalDateAxis, using default values where necessary.
 
Method Summary
protected  void autoAdjustRange()
          Rescales the axis to ensure that all data is visible.
 void configure()
          Configures the axis to work with the specified plot.
 void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D drawArea, java.awt.geom.Rectangle2D plotArea)
          Draws the plot on a Java 2D graphics device (such as the screen or a printer).
 boolean getVerticalTickLabels()
          Returns true if the tick labels should be rotated to vertical, and false for standard horizontal labels.
protected  boolean isCompatiblePlot(Plot plot)
          Returns true if the specified plot is compatible with the axis, and false otherwise.
 void refreshTicks(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D drawArea, java.awt.geom.Rectangle2D plotArea)
          Recalculates the ticks for the date axis.
 java.awt.geom.Rectangle2D reserveAxisArea(java.awt.Graphics2D g2, Plot plot, java.awt.geom.Rectangle2D drawArea, double reservedWidth)
          Returns area in which the axis will be displayed.
 double reserveHeight(java.awt.Graphics2D g2, Plot plot, java.awt.geom.Rectangle2D drawArea)
          Returns the height required to draw the axis in the specified draw area.
 void setVerticalTickLabels(boolean flag)
          Sets the flag that determines the orientation of the tick labels.
 double translateDateToJava2D(java.util.Date date, java.awt.geom.Rectangle2D dataArea)
          Translates a date to Java2D coordinates, based on the range displayed by this axis for the specified data area.
 double translateJava2DtoValue(float java2DValue, java.awt.geom.Rectangle2D dataArea)
          Translates the Java2D (horizontal) coordinate back to the corresponding data value.
 double translateValueToJava2D(double value, java.awt.geom.Rectangle2D dataArea)
          Translates the data value to the display coordinates (Java 2D User Space) of the chart.
 
Methods inherited from class com.jrefinery.chart.DateAxis
calculateHighestVisibleTickValue, calculateLowestVisibleTickValue, findAxisMagnitudeIndex, getAnchorDate, getCrosshairDate, getMaximumDate, getMinimumDate, getTickLabelFormatter, getTickUnit, nextStandardDate, previousStandardDate, setAnchorDate, setAnchorValue, setAxisRange, setCrosshairDate, setMaximumDate, setMinimumDate, setRange, setTickUnit
 
Methods inherited from class com.jrefinery.chart.ValueAxis
centerRange, getAnchorValue, getCrosshairPaint, getCrosshairStroke, getCrosshairValue, getFixedAutoRange, getGridPaint, getGridStroke, getMaximumAxisValue, getMinimumAxisValue, getRange, isAutoRange, isAutoTickUnitSelection, isCrosshairLockedOnData, isCrosshairVisible, isGridLinesVisible, resizeRange, resizeRange, setAnchoredRange, setAutoRange, setAutoTickUnitSelection, setCrosshairLockedOnData, setCrosshairPaint, setCrosshairStroke, setCrosshairValue, setCrosshairVisible, setFixedAutoRange, setGridLinesVisible, setGridPaint, setGridStroke, setMaximumAxisValue, setMinimumAxisValue, setRange, setRangeAboutValue
 
Methods inherited from class com.jrefinery.chart.Axis
addChangeListener, getFixedDimension, getLabel, getLabelFont, getLabelInsets, getLabelPaint, getMaxTickLabelWidth, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkStroke, isTickLabelsVisible, isTickMarksVisible, isVisible, notifyListeners, removeChangeListener, setFixedDimension, setLabel, setLabelFont, setLabelInsets, setLabelPaint, setPlot, setTickLabelFont, setTickLabelInsets, setTickLabelPaint, setTickLabelsVisible, setTickMarkStroke, setTickMarksVisible, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

verticalTickLabels

protected boolean verticalTickLabels
A flag indicating whether or not tick labels are drawn vertically.

Constructor Detail

HorizontalDateAxis

public HorizontalDateAxis()
Constructs a HorizontalDateAxis, using default values where necessary.


HorizontalDateAxis

public HorizontalDateAxis(java.lang.String label)
Constructs a horizontal date axis, using default values where necessary.

Parameters:
label - The axis label.

HorizontalDateAxis

public HorizontalDateAxis(java.lang.String label,
                          java.awt.Font labelFont,
                          Range range)
Constructs a HorizontalDateAxis, using default values where necessary.

Parameters:
label - The axis label.
labelFont - The font for displaying the axis label.
range - The axis range.

HorizontalDateAxis

public HorizontalDateAxis(java.lang.String label,
                          java.awt.Font labelFont,
                          java.awt.Paint labelPaint,
                          java.awt.Insets labelInsets,
                          boolean showTickLabels,
                          java.awt.Font tickLabelFont,
                          java.awt.Paint tickLabelPaint,
                          java.awt.Insets tickLabelInsets,
                          boolean verticalTickLabels,
                          boolean showTickMarks,
                          java.awt.Stroke tickMarkStroke,
                          boolean autoRange,
                          Range range,
                          boolean autoUnits,
                          DateUnit tickUnits,
                          java.text.SimpleDateFormat tickLabelFormatter,
                          boolean gridVisible,
                          java.awt.Stroke gridStroke,
                          java.awt.Paint gridPaint,
                          boolean crosshairVisible,
                          java.util.Date crosshairDate,
                          java.awt.Stroke crosshairStroke,
                          java.awt.Paint crosshairPaint)
Constructs a HorizontalDateAxis.

Parameters:
label - The axis label.
labelFont - The font for displaying the axis label.
labelPaint - The paint used to draw the axis label.
labelInsets - The blank space around the axis label.
showTickLabels - Flag indicating whether or not tick labels are visible.
tickLabelFont - Font for displaying tick labels.
tickLabelPaint - The paint used to display the tick labels.
tickLabelInsets - The blank space around the tick labels.
verticalTickLabels - A flag indicating whether or not tick labels are drawn vertically.
showTickMarks - Flag indicating whether or not tick marks are visible.
tickMarkStroke - The stroke used to draw tick marks (if visible).
autoRange - Flag indicating whether or not the axis is automatically scaled to fit the data.
range - The axis range.
autoUnits - A flag indicating whether or not the tick units are automatically selected.
tickUnits - The tick units.
tickLabelFormatter - The format object used to display tick labels.
gridVisible - Flag indicating whether or not grid lines are visible for this axis.
gridStroke - The Stroke used to display grid lines (if visible).
gridPaint - The Paint used to display grid lines (if visible).
crosshairDate - The date at which to draw the crosshair line (null permitted).
crosshairStroke - The pen/brush used to draw the data line.
crosshairPaint - The color used to draw the data line.
Method Detail

getVerticalTickLabels

public boolean getVerticalTickLabels()
Returns true if the tick labels should be rotated to vertical, and false for standard horizontal labels.

Returns:
A flag indicating the orientation of the tick labels.

setVerticalTickLabels

public void setVerticalTickLabels(boolean flag)
Sets the flag that determines the orientation of the tick labels. Registered listeners are notified that the axis has been changed.

Parameters:
flag - The flag.

configure

public void configure()
Configures the axis to work with the specified plot. If the axis has auto-scaling, then sets the maximum and minimum values.

Specified by:
configure in class Axis

translateDateToJava2D

public double translateDateToJava2D(java.util.Date date,
                                    java.awt.geom.Rectangle2D dataArea)
Translates a date to Java2D coordinates, based on the range displayed by this axis for the specified data area.

Parameters:
date - The date.
dataArea - The rectangle (in Java2D space) where the data is to be plotted.
Returns:
The horizontal coordinate corresponding to the supplied date.

translateValueToJava2D

public double translateValueToJava2D(double value,
                                     java.awt.geom.Rectangle2D dataArea)
Translates the data value to the display coordinates (Java 2D User Space) of the chart.

Specified by:
translateValueToJava2D in class ValueAxis
Parameters:
date - The date to be plotted.
dataArea - The rectangle (in Java2D space) where the data is to be plotted.
Returns:
The horizontal coordinate corresponding to the supplied data value.

translateJava2DtoValue

public double translateJava2DtoValue(float java2DValue,
                                     java.awt.geom.Rectangle2D dataArea)
Translates the Java2D (horizontal) coordinate back to the corresponding data value.

Specified by:
translateJava2DtoValue in class ValueAxis
Parameters:
java2DValue - The coordinate in Java2D space.
dataArea - The rectangle (in Java2D space) where the data is to be plotted.
Returns:
The data value corresponding to the Java2D coordinate.

autoAdjustRange

protected void autoAdjustRange()
Rescales the axis to ensure that all data is visible.

Specified by:
autoAdjustRange in class ValueAxis

refreshTicks

public void refreshTicks(java.awt.Graphics2D g2,
                         java.awt.geom.Rectangle2D drawArea,
                         java.awt.geom.Rectangle2D plotArea)
Recalculates the ticks for the date axis.

Specified by:
refreshTicks in class Axis
Parameters:
g2 - The graphics device.
drawArea - The area in which the axes and data are to be drawn.
plotArea - The area in which the data is to be drawn.

draw

public void draw(java.awt.Graphics2D g2,
                 java.awt.geom.Rectangle2D drawArea,
                 java.awt.geom.Rectangle2D plotArea)
Draws the plot on a Java 2D graphics device (such as the screen or a printer).

Specified by:
draw in class Axis
Parameters:
g2 - The graphics device.
drawArea - The area within which the chart should be drawn.
plotArea - The area within which the plot should be drawn (a subset of the drawArea).

reserveHeight

public double reserveHeight(java.awt.Graphics2D g2,
                            Plot plot,
                            java.awt.geom.Rectangle2D drawArea)
Returns the height required to draw the axis in the specified draw area.

Specified by:
reserveHeight in interface HorizontalAxis
Parameters:
g2 - The graphics device.
plot - The plot that the axis belongs to.
drawArea - The area within which the plot should be drawn.
Returns:
The height.

reserveAxisArea

public java.awt.geom.Rectangle2D reserveAxisArea(java.awt.Graphics2D g2,
                                                 Plot plot,
                                                 java.awt.geom.Rectangle2D drawArea,
                                                 double reservedWidth)
Returns area in which the axis will be displayed.

Specified by:
reserveAxisArea in interface HorizontalAxis
Parameters:
g2 - The graphics device.
plot - The plot.
drawArea - The drawing area.
reservedWidth - The width already reserved for the vertical axis.
Returns:
The area to reserve for the horizontal axis.

isCompatiblePlot

protected boolean isCompatiblePlot(Plot plot)
Returns true if the specified plot is compatible with the axis, and false otherwise.

The HorizontalDateAxis class expects the plot to implement the HorizontalValuePlot interface.

Specified by:
isCompatiblePlot in class Axis
Parameters:
plot - The plot.
Returns:
A flag indicating whether or not the plot is compatible with the axis.


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.