Class PeriodAxis

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, PublicCloneable

    public class PeriodAxis
    extends ValueAxis
    implements java.lang.Cloneable, PublicCloneable, java.io.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.
    See Also:
    Serialized Form
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        For serialization.
        See Also:
        Constant Field Values
      • timeZone

        private java.util.TimeZone timeZone
        The time zone used to convert 'first' and 'last' to absolute milliseconds.
      • locale

        private java.util.Locale locale
        The locale (never null).
      • calendar

        private java.util.Calendar calendar
        A calendar used for date manipulations in the current time zone and locale.
      • autoRangeTimePeriodClass

        private java.lang.Class autoRangeTimePeriodClass
        The RegularTimePeriod subclass used to automatically determine the axis range.
      • majorTickTimePeriodClass

        private java.lang.Class majorTickTimePeriodClass
        Indicates the RegularTimePeriod subclass that is used to determine the spacing of the major tick marks.
      • minorTickMarksVisible

        private boolean minorTickMarksVisible
        A flag that indicates whether or not tick marks are visible for the axis.
      • minorTickTimePeriodClass

        private java.lang.Class minorTickTimePeriodClass
        Indicates the RegularTimePeriod subclass that is used to determine the spacing of the minor tick marks.
      • minorTickMarkInsideLength

        private float minorTickMarkInsideLength
        The length of the tick mark inside the data area (zero permitted).
      • minorTickMarkOutsideLength

        private float minorTickMarkOutsideLength
        The length of the tick mark outside the data area (zero permitted).
      • minorTickMarkStroke

        private transient java.awt.Stroke minorTickMarkStroke
        The stroke used to draw tick marks.
      • minorTickMarkPaint

        private transient java.awt.Paint minorTickMarkPaint
        The paint used to draw tick marks.
    • Constructor Detail

      • PeriodAxis

        public PeriodAxis​(java.lang.String label)
        Creates a new axis.
        Parameters:
        label - the axis label.
      • PeriodAxis

        public PeriodAxis​(java.lang.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​(java.lang.String label,
                          RegularTimePeriod first,
                          RegularTimePeriod last,
                          java.util.TimeZone timeZone,
                          java.util.Locale locale)
        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).
        locale - the locale (null not permitted).
    • Method Detail

      • getFirst

        public RegularTimePeriod getFirst()
        Returns the first time period in the axis range.
        Returns:
        The first time period (never null).
      • 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).
      • getLast

        public RegularTimePeriod getLast()
        Returns the last time period in the axis range.
        Returns:
        The last time period (never null).
      • 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).
      • getTimeZone

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

        public void setTimeZone​(java.util.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).
      • getLocale

        public java.util.Locale getLocale()
        Returns the locale for this axis.
        Returns:
        The locale (never (null).
      • getAutoRangeTimePeriodClass

        public java.lang.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).
      • setAutoRangeTimePeriodClass

        public void setAutoRangeTimePeriodClass​(java.lang.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).
      • getMajorTickTimePeriodClass

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

        public void setMajorTickTimePeriodClass​(java.lang.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).
      • getMinorTickTimePeriodClass

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

        public void setMinorTickTimePeriodClass​(java.lang.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).
      • getMinorTickMarkStroke

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

        public void setMinorTickMarkStroke​(java.awt.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).
      • getMinorTickMarkPaint

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

        public void setMinorTickMarkPaint​(java.awt.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).
      • getLabelInfo

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

        public void setLabelInfo​(PeriodAxisLabelInfo[] info)
        Sets the array of label info records and sends an AxisChangeEvent to all registered listeners.
        Parameters:
        info - the info.
      • 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 class 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.
        See Also:
        ValueAxis.getRange()
      • 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).
        Specified by:
        configure in class Axis
      • reserveSpace

        public AxisSpace reserveSpace​(java.awt.Graphics2D g2,
                                      Plot plot,
                                      java.awt.geom.Rectangle2D plotArea,
                                      RectangleEdge edge,
                                      AxisSpace space)
        Estimates the space (height or width) required to draw the axis.
        Overrides:
        reserveSpace in class 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).
      • draw

        public AxisState draw​(java.awt.Graphics2D g2,
                              double cursor,
                              java.awt.geom.Rectangle2D plotArea,
                              java.awt.geom.Rectangle2D dataArea,
                              RectangleEdge edge,
                              PlotRenderingInfo plotState)
        Draws the axis on a Java 2D graphics device (such as the screen or a printer).
        Specified by:
        draw in class 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).
      • drawTickMarks

        protected void drawTickMarks​(java.awt.Graphics2D g2,
                                     AxisState state,
                                     java.awt.geom.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​(java.awt.Graphics2D g2,
                                               AxisState state,
                                               java.awt.geom.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​(java.awt.Graphics2D g2,
                                             AxisState state,
                                             java.awt.geom.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.
      • drawTickLabels

        protected AxisState drawTickLabels​(int band,
                                           java.awt.Graphics2D g2,
                                           AxisState state,
                                           java.awt.geom.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.
      • refreshTicks

        public java.util.List refreshTicks​(java.awt.Graphics2D g2,
                                           AxisState state,
                                           java.awt.geom.Rectangle2D dataArea,
                                           RectangleEdge edge)
        Calculates the positions of the ticks for the axis, storing the results in the tick list (ready for drawing).
        Specified by:
        refreshTicks in class 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.
      • valueToJava2D

        public double valueToJava2D​(double value,
                                    java.awt.geom.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.

        Specified by:
        valueToJava2D in class 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.
        See Also:
        ValueAxis.java2DToValue(double, Rectangle2D, RectangleEdge)
      • java2DToValue

        public double java2DToValue​(double java2DValue,
                                    java.awt.geom.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.
        Specified by:
        java2DToValue in class 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.
        See Also:
        ValueAxis.valueToJava2D(double, Rectangle2D, RectangleEdge)
      • autoAdjustRange

        protected void autoAdjustRange()
        Rescales the axis to ensure that all data is visible.
        Specified by:
        autoAdjustRange in class ValueAxis
      • equals

        public boolean equals​(java.lang.Object obj)
        Tests the axis for equality with an arbitrary object.
        Overrides:
        equals in class ValueAxis
        Parameters:
        obj - the object (null permitted).
        Returns:
        A boolean.
      • hashCode

        public int hashCode()
        Returns a hash code for this object.
        Overrides:
        hashCode in class Axis
        Returns:
        A hash code.
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Returns a clone of the axis.
        Specified by:
        clone in interface PublicCloneable
        Overrides:
        clone in class ValueAxis
        Returns:
        A clone.
        Throws:
        java.lang.CloneNotSupportedException - this class is cloneable, but subclasses may not be.
      • createInstance

        private RegularTimePeriod createInstance​(java.lang.Class periodClass,
                                                 java.util.Date millisecond,
                                                 java.util.TimeZone zone,
                                                 java.util.Locale locale)
        A utility method used to create a particular subclass of the RegularTimePeriod class that includes the specified millisecond, assuming the specified time zone.
        Parameters:
        periodClass - the class.
        millisecond - the time.
        zone - the time zone.
        locale - the locale.
        Returns:
        The time period.
      • writeObject

        private void writeObject​(java.io.ObjectOutputStream stream)
                          throws java.io.IOException
        Provides serialization support.
        Parameters:
        stream - the output stream.
        Throws:
        java.io.IOException - if there is an I/O error.
      • readObject

        private void readObject​(java.io.ObjectInputStream stream)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
        Provides serialization support.
        Parameters:
        stream - the input stream.
        Throws:
        java.io.IOException - if there is an I/O error.
        java.lang.ClassNotFoundException - if there is a classpath problem.