org.jfree.chart.axis

Class PeriodAxis

Implemented Interfaces:
Cloneable, PublicCloneable, Serializable

public class PeriodAxis
extends ValueAxis
implements Cloneable, PublicCloneable, Serializable

An axis that displays a date scale based on a RegularTimePeriod. This axis works when displayed across the bottom or top of a plot, but is broken for display at the left or right of charts.

Field Summary

Fields inherited from class org.jfree.chart.axis.ValueAxis

DEFAULT_AUTO_RANGE, DEFAULT_AUTO_RANGE_MINIMUM_SIZE, DEFAULT_AUTO_TICK_UNIT_SELECTION, DEFAULT_INVERTED, DEFAULT_LOWER_BOUND, DEFAULT_LOWER_MARGIN, DEFAULT_RANGE, DEFAULT_UPPER_BOUND, DEFAULT_UPPER_MARGIN, MAXIMUM_TICK_COUNT

Fields inherited from class org.jfree.chart.axis.Axis

DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_AXIS_LINE_PAINT, DEFAULT_AXIS_LINE_STROKE, DEFAULT_AXIS_VISIBLE, DEFAULT_TICK_LABELS_VISIBLE, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_MARKS_VISIBLE, DEFAULT_TICK_MARK_INSIDE_LENGTH, DEFAULT_TICK_MARK_OUTSIDE_LENGTH, DEFAULT_TICK_MARK_PAINT, DEFAULT_TICK_MARK_STROKE

Constructor Summary

PeriodAxis(String label)
Creates a new axis.
PeriodAxis(String label, RegularTimePeriod first, RegularTimePeriod last)
Creates a new axis.
PeriodAxis(String label, RegularTimePeriod first, RegularTimePeriod last, TimeZone timeZone)
Creates a new axis.

Method Summary

protected void
autoAdjustRange()
Rescales the axis to ensure that all data is visible.
Object
clone()
Returns a clone of the axis.
void
configure()
Configures the axis to work with the current plot.
AxisState
draw(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState)
Draws the axis on a Java 2D graphics device (such as the screen or a printer).
protected AxisState
drawTickLabels(int band, Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge)
Draws the tick labels for one "band" of time periods.
protected void
drawTickMarks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge)
Draws the tick marks for the axis.
protected void
drawTickMarksHorizontal(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge)
Draws the major and minor tick marks for an axis that lies at the top or bottom of the plot.
protected void
drawTickMarksVertical(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge)
Draws the tick marks for a vertical axis.
boolean
equals(Object obj)
Tests the axis for equality with an arbitrary object.
Class
getAutoRangeTimePeriodClass()
Returns the class used to create the first and last time periods for the axis range when the auto-range flag is set to true.
RegularTimePeriod
getFirst()
Returns the first time period in the axis range.
PeriodAxisLabelInfo[]
getLabelInfo()
Returns an array of label info records.
RegularTimePeriod
getLast()
Returns the last time period in the axis range.
Class
getMajorTickTimePeriodClass()
Returns the class that controls the spacing of the major tick marks.
float
getMinorTickMarkInsideLength()
Returns the inside length for the minor tick marks.
float
getMinorTickMarkOutsideLength()
Returns the outside length for the minor tick marks.
Paint
getMinorTickMarkPaint()
Returns the paint used to display minor tick marks, if they are visible.
Stroke
getMinorTickMarkStroke()
Returns the stroke used to display minor tick marks, if they are visible.
Class
getMinorTickTimePeriodClass()
Returns the class that controls the spacing of the minor tick marks.
Range
getRange()
Returns the range for the axis.
TimeZone
getTimeZone()
Returns the time zone used to convert the periods defining the axis range into absolute milliseconds.
int
hashCode()
Returns a hash code for this object.
boolean
isMinorTickMarksVisible()
Returns the flag that controls whether or not minor tick marks are displayed for the axis.
double
java2DToValue(double java2DValue, Rectangle2D area, RectangleEdge edge)
Converts a coordinate in Java2D space to the corresponding data value, assuming that the axis runs along one edge of the specified dataArea.
List
refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge)
Calculates the positions of the ticks for the axis, storing the results in the tick list (ready for drawing).
AxisSpace
reserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge, AxisSpace space)
Estimates the space (height or width) required to draw the axis.
void
setAutoRangeTimePeriodClass(Class c)
Sets the class used to create the first and last time periods for the axis range when the auto-range flag is set to true and sends an AxisChangeEvent to all registered listeners.
void
setFirst(RegularTimePeriod first)
Sets the first time period in the axis range and sends an AxisChangeEvent to all registered listeners.
void
setLabelInfo(PeriodAxisLabelInfo[] info)
Sets the array of label info records.
void
setLast(RegularTimePeriod last)
Sets the last time period in the axis range and sends an AxisChangeEvent to all registered listeners.
void
setMajorTickTimePeriodClass(Class c)
Sets the class that controls the spacing of the major tick marks, and sends an AxisChangeEvent to all registered listeners.
void
setMinorTickMarkInsideLength(float length)
Sets the inside length of the minor tick marks and sends an AxisChangeEvent to all registered listeners.
void
setMinorTickMarkOutsideLength(float length)
Sets the outside length of the minor tick marks and sends an AxisChangeEvent to all registered listeners.
void
setMinorTickMarkPaint(Paint paint)
Sets the paint used to display minor tick marks, if they are visible, and sends a AxisChangeEvent to all registered listeners.
void
setMinorTickMarkStroke(Stroke stroke)
Sets the stroke used to display minor tick marks, if they are visible, and sends a AxisChangeEvent to all registered listeners.
void
setMinorTickMarksVisible(boolean visible)
Sets the flag that controls whether or not minor tick marks are displayed for the axis, and sends a AxisChangeEvent to all registered listeners.
void
setMinorTickTimePeriodClass(Class c)
Sets the class that controls the spacing of the minor tick marks, and sends an AxisChangeEvent to all registered listeners.
void
setRange(Range range, boolean turnOffAutoRange, boolean notify)
Sets the range for the axis, if requested, sends an AxisChangeEvent to all registered listeners.
void
setTimeZone(TimeZone zone)
Sets the time zone that is used to convert the time periods into absolute milliseconds.
double
valueToJava2D(double value, Rectangle2D area, RectangleEdge edge)
Converts a data value to a coordinate in Java2D space, assuming that the axis runs along one edge of the specified dataArea.

Methods inherited from class org.jfree.chart.axis.ValueAxis

autoAdjustRange, calculateAnchorPoint, centerRange, clone, drawAxisLine, drawTickMarksAndLabels, equals, findMaximumTickLabelHeight, findMaximumTickLabelWidth, getAutoRangeMinimumSize, getAutoTickIndex, getDefaultAutoRange, getDownArrow, getFixedAutoRange, getLeftArrow, getLowerBound, getLowerMargin, getRange, getRightArrow, getStandardTickUnits, getUpArrow, getUpperBound, getUpperMargin, isAutoRange, isAutoTickUnitSelection, isInverted, isNegativeArrowVisible, isPositiveArrowVisible, isVerticalTickLabels, java2DToValue, lengthToJava2D, reserveSpace, resizeRange, resizeRange, setAutoRange, setAutoRange, setAutoRangeMinimumSize, setAutoRangeMinimumSize, setAutoTickIndex, setAutoTickUnitSelection, setAutoTickUnitSelection, setDefaultAutoRange, setDownArrow, setFixedAutoRange, setInverted, setLeftArrow, setLowerBound, setLowerMargin, setNegativeArrowVisible, setPositiveArrowVisible, setRange, setRange, setRange, setRangeAboutValue, setRangeWithMargins, setRangeWithMargins, setRangeWithMargins, setRightArrow, setStandardTickUnits, setUpArrow, setUpperBound, setUpperMargin, setVerticalTickLabels, valueToJava2D, zoomRange

Methods inherited from class org.jfree.chart.axis.Axis

addChangeListener, clone, configure, draw, drawAxisLine, drawLabel, equals, getAxisLinePaint, getAxisLineStroke, getFixedDimension, getLabel, getLabelAngle, getLabelEnclosure, getLabelFont, getLabelInsets, getLabelPaint, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkInsideLength, getTickMarkOutsideLength, getTickMarkPaint, getTickMarkStroke, hasListener, isAxisLineVisible, isTickLabelsVisible, isTickMarksVisible, isVisible, notifyListeners, refreshTicks, removeChangeListener, reserveSpace, setAxisLinePaint, setAxisLineStroke, setAxisLineVisible, setFixedDimension, setLabel, setLabelAngle, setLabelFont, setLabelInsets, setLabelPaint, setPlot, setTickLabelFont, setTickLabelInsets, setTickLabelPaint, setTickLabelsVisible, setTickMarkInsideLength, setTickMarkOutsideLength, setTickMarkPaint, setTickMarkStroke, setTickMarksVisible, setVisible

Constructor Details

PeriodAxis

public PeriodAxis(String label)
Creates a new axis.
Parameters:
label - the axis label.

PeriodAxis

public PeriodAxis(String label,
                  RegularTimePeriod first,
                  RegularTimePeriod last)
Creates a new axis.
Parameters:
label - the axis label (null permitted).
first - the first time period in the axis range (null not permitted).
last - the last time period in the axis range (null not permitted).

PeriodAxis

public PeriodAxis(String label,
                  RegularTimePeriod first,
                  RegularTimePeriod last,
                  TimeZone timeZone)
Creates a new axis.
Parameters:
label - the axis label (null permitted).
first - the first time period in the axis range (null not permitted).
last - the last time period in the axis range (null not permitted).
timeZone - the time zone (null not permitted).

Method Details

autoAdjustRange

protected void autoAdjustRange()
Rescales the axis to ensure that all data is visible.
Overrides:
autoAdjustRange in interface ValueAxis

clone

public Object clone()
            throws CloneNotSupportedException
Returns a clone of the axis.
Overrides:
clone in interface ValueAxis
Returns:
A clone.

configure

public void configure()
Configures the axis to work with the current plot. Override this method to perform any special processing (such as auto-rescaling).
Overrides:
configure in interface Axis

draw

public AxisState draw(Graphics2D g2,
                      double cursor,
                      Rectangle2D plotArea,
                      Rectangle2D dataArea,
                      RectangleEdge edge,
                      PlotRenderingInfo plotState)
Draws the axis on a Java 2D graphics device (such as the screen or a printer).
Overrides:
draw in interface Axis
Parameters:
g2 - the graphics device (null not permitted).
cursor - the cursor location (determines where to draw the axis).
plotArea - the area within which the axes and plot should be drawn.
dataArea - the area within which the data should be drawn.
edge - the axis location (null not permitted).
plotState - collects information about the plot (null permitted).
Returns:
The axis state (never null).

drawTickLabels

protected AxisState drawTickLabels(int band,
                                   Graphics2D g2,
                                   AxisState state,
                                   Rectangle2D dataArea,
                                   RectangleEdge edge)
Draws the tick labels for one "band" of time periods.
Parameters:
band - the band index (zero-based).
g2 - the graphics device.
state - the axis state.
dataArea - the data area.
edge - the edge where the axis is located.
Returns:
The updated axis state.

drawTickMarks

protected void drawTickMarks(Graphics2D g2,
                             AxisState state,
                             Rectangle2D dataArea,
                             RectangleEdge edge)
Draws the tick marks for the axis.
Parameters:
g2 - the graphics device.
state - the axis state.
dataArea - the data area.
edge - the edge.

drawTickMarksHorizontal

protected void drawTickMarksHorizontal(Graphics2D g2,
                                       AxisState state,
                                       Rectangle2D dataArea,
                                       RectangleEdge edge)
Draws the major and minor tick marks for an axis that lies at the top or bottom of the plot.
Parameters:
g2 - the graphics device.
state - the axis state.
dataArea - the data area.
edge - the edge.

drawTickMarksVertical

protected void drawTickMarksVertical(Graphics2D g2,
                                     AxisState state,
                                     Rectangle2D dataArea,
                                     RectangleEdge edge)
Draws the tick marks for a vertical axis.
Parameters:
g2 - the graphics device.
state - the axis state.
dataArea - the data area.
edge - the edge.

equals

public boolean equals(Object obj)
Tests the axis for equality with an arbitrary object.
Overrides:
equals in interface ValueAxis
Parameters:
obj - the object (null permitted).
Returns:
A boolean.

getAutoRangeTimePeriodClass

public Class getAutoRangeTimePeriodClass()
Returns the class used to create the first and last time periods for the axis range when the auto-range flag is set to true.
Returns:
The class (never null).

getFirst

public RegularTimePeriod getFirst()
Returns the first time period in the axis range.
Returns:
The first time period (never null).

getLabelInfo

public PeriodAxisLabelInfo[] getLabelInfo()
Returns an array of label info records.
Returns:
An array.

getLast

public RegularTimePeriod getLast()
Returns the last time period in the axis range.
Returns:
The last time period (never null).

getMajorTickTimePeriodClass

public Class getMajorTickTimePeriodClass()
Returns the class that controls the spacing of the major tick marks.
Returns:
The class (never null).

getMinorTickMarkInsideLength

public float getMinorTickMarkInsideLength()
Returns the inside length for the minor tick marks.
Returns:
The length.

getMinorTickMarkOutsideLength

public float getMinorTickMarkOutsideLength()
Returns the outside length for the minor tick marks.
Returns:
The length.

getMinorTickMarkPaint

public Paint getMinorTickMarkPaint()
Returns the paint used to display minor tick marks, if they are visible.
Returns:
A paint (never null).

getMinorTickMarkStroke

public Stroke getMinorTickMarkStroke()
Returns the stroke used to display minor tick marks, if they are visible.
Returns:
A stroke (never null).

getMinorTickTimePeriodClass

public Class getMinorTickTimePeriodClass()
Returns the class that controls the spacing of the minor tick marks.
Returns:
The class (never null).

getRange

public Range getRange()
Returns the range for the axis.
Overrides:
getRange in interface ValueAxis
Returns:
The axis range (never null).

getTimeZone

public TimeZone getTimeZone()
Returns the time zone used to convert the periods defining the axis range into absolute milliseconds.
Returns:
The time zone (never null).

hashCode

public int hashCode()
Returns a hash code for this object.
Returns:
A hash code.

isMinorTickMarksVisible

public boolean isMinorTickMarksVisible()
Returns the flag that controls whether or not minor tick marks are displayed for the axis.
Returns:
A boolean.

java2DToValue

public double java2DToValue(double java2DValue,
                            Rectangle2D area,
                            RectangleEdge edge)
Converts a coordinate in Java2D space to the corresponding data value, assuming that the axis runs along one edge of the specified dataArea.
Overrides:
java2DToValue in interface ValueAxis
Parameters:
java2DValue - the coordinate in Java2D space.
area - the area in which the data is plotted.
edge - the edge along which the axis lies.
Returns:
The data value.

refreshTicks

public List refreshTicks(Graphics2D g2,
                         AxisState state,
                         Rectangle2D dataArea,
                         RectangleEdge edge)
Calculates the positions of the ticks for the axis, storing the results in the tick list (ready for drawing).
Overrides:
refreshTicks in interface Axis
Parameters:
g2 - the graphics device.
state - the axis state.
dataArea - the area inside the axes.
edge - the edge on which the axis is located.
Returns:
The list of ticks.

reserveSpace

public AxisSpace reserveSpace(Graphics2D g2,
                              Plot plot,
                              Rectangle2D plotArea,
                              RectangleEdge edge,
                              AxisSpace space)
Estimates the space (height or width) required to draw the axis.
Overrides:
reserveSpace in interface ValueAxis
Parameters:
g2 - the graphics device.
plot - the plot that the axis belongs to.
plotArea - the area within which the plot (including axes) should be drawn.
edge - the axis location.
space - space already reserved.
Returns:
The space required to draw the axis (including pre-reserved space).

setAutoRangeTimePeriodClass

public void setAutoRangeTimePeriodClass(Class c)
Sets the class used to create the first and last time periods for the axis range when the auto-range flag is set to true and sends an AxisChangeEvent to all registered listeners.
Parameters:
c - the class (null not permitted).

setFirst

public void setFirst(RegularTimePeriod first)
Sets the first time period in the axis range and sends an AxisChangeEvent to all registered listeners.
Parameters:
first - the time period (null not permitted).

setLabelInfo

public void setLabelInfo(PeriodAxisLabelInfo[] info)
Sets the array of label info records.
Parameters:
info - the info.

setLast

public void setLast(RegularTimePeriod last)
Sets the last time period in the axis range and sends an AxisChangeEvent to all registered listeners.
Parameters:
last - the time period (null not permitted).

setMajorTickTimePeriodClass

public void setMajorTickTimePeriodClass(Class c)
Sets the class that controls the spacing of the major tick marks, and sends an AxisChangeEvent to all registered listeners.
Parameters:
c - the class (a subclass of RegularTimePeriod is expected).

setMinorTickMarkInsideLength

public void setMinorTickMarkInsideLength(float length)
Sets the inside length of the minor tick marks and sends an AxisChangeEvent to all registered listeners.
Parameters:
length - the length.

setMinorTickMarkOutsideLength

public void setMinorTickMarkOutsideLength(float length)
Sets the outside length of the minor tick marks and sends an AxisChangeEvent to all registered listeners.
Parameters:
length - the length.

setMinorTickMarkPaint

public void setMinorTickMarkPaint(Paint paint)
Sets the paint used to display minor tick marks, if they are visible, and sends a AxisChangeEvent to all registered listeners.
Parameters:
paint - the paint (null not permitted).

setMinorTickMarkStroke

public void setMinorTickMarkStroke(Stroke stroke)
Sets the stroke used to display minor tick marks, if they are visible, and sends a AxisChangeEvent to all registered listeners.
Parameters:
stroke - the stroke (null not permitted).

setMinorTickMarksVisible

public void setMinorTickMarksVisible(boolean visible)
Sets the flag that controls whether or not minor tick marks are displayed for the axis, and sends a AxisChangeEvent to all registered listeners.
Parameters:
visible - the flag.

setMinorTickTimePeriodClass

public void setMinorTickTimePeriodClass(Class c)
Sets the class that controls the spacing of the minor tick marks, and sends an AxisChangeEvent to all registered listeners.
Parameters:
c - the class (a subclass of RegularTimePeriod is expected).

setRange

public void setRange(Range range,
                     boolean turnOffAutoRange,
                     boolean notify)
Sets the range for the axis, if requested, sends an AxisChangeEvent to all registered listeners. As a side-effect, the auto-range flag is set to false (optional).
Overrides:
setRange in interface ValueAxis
Parameters:
range - the range (null not permitted).
turnOffAutoRange - a flag that controls whether or not the auto range is turned off.
notify - a flag that controls whether or not listeners are notified.

setTimeZone

public void setTimeZone(TimeZone zone)
Sets the time zone that is used to convert the time periods into absolute milliseconds.
Parameters:
zone - the time zone (null not permitted).

valueToJava2D

public double valueToJava2D(double value,
                            Rectangle2D area,
                            RectangleEdge edge)
Converts a data value to a coordinate in Java2D space, assuming that the axis runs along one edge of the specified dataArea.

Note that it is possible for the coordinate to fall outside the area.

Overrides:
valueToJava2D in interface ValueAxis
Parameters:
value - the data value.
area - the area for plotting the data.
edge - the edge along which the axis lies.
Returns:
The Java2D coordinate.