Class LabelFormatterDate

  • All Implemented Interfaces:
    IAxisLabelFormatter, java.io.Serializable

    public class LabelFormatterDate
    extends ALabelFormatter
    implements IAxisLabelFormatter
    An ILabelFormatter instance that uses a DateFormat to format the labels.

    Caution:
    It only makes sense to use this class if the data of the corresponding axis may be interpreted as long number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

    Caution:
    This implementation is not completely conform with the constraint: instance.parse(instance.format(value)) == value
    This only works for subsequent call: one call to format contains the next value to return from parse to be the same as the format. That value is cached as date / time formatting produces truncation of the internal value (e.g. if no year is displayed).
    Use:

     
         Chart2D chart = new <Constructor>
         Axis axis = new AxisSimple();
         axis.setFormatter(new LabelFormatterDate(DateFormat.getDateInstance()));
         chart.setAxisX(axis);
     
     
    to use this class.

    Version:
    $Revision: 1.11 $
    Author:
    Achim Westermann
    See Also:
    Date, Serialized Form
    • Constructor Detail

      • LabelFormatterDate

        public LabelFormatterDate()
        Default constructor that uses the local datetime ( DateFormat.getDateTimeInstance(int, int)) with DateFormat.SHORT style.

      • LabelFormatterDate

        public LabelFormatterDate​(java.text.SimpleDateFormat dateFormat)
        Creates a formatter that uses the given date format.

        Parameters:
        dateFormat - the date format to use.
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class ALabelFormatter
        See Also:
        Object.equals(java.lang.Object)
      • format

        public java.lang.String format​(double value)
        Description copied from interface: IAxisLabelFormatter
        Provide a String for the value. Subclasses should override the label formatting here. The raw value is passed here to allow a general treatment. Transformations of this raw value should be done here (e.g. division by multiples of 1000 for scientific unit system display, date formatting,...).

        Specified by:
        format in interface IAxisLabelFormatter
        Parameters:
        value - the value to format.
        Returns:
        the formatted value.
        See Also:
        IAxisLabelFormatter.format(double)
      • getMinimumValueShiftForChange

        public double getMinimumValueShiftForChange()
        Description copied from interface: IAxisLabelFormatter
        Returns the minimum change in the value to format that will cause to return a different formatted String.

        To achieve two different formatted Strings to be returned from the format method the corresponding values given to the format method have to differ at least by this value.

        Some implementations (e.g. a formatter for date) have to use their own format method an increas a value to determine when the first change will occur. This is expensive and it's recommended that this action is performed once only and the result is stored. Additionally this routine has to start with an "even" (see IAxisLabelFormatter.getNextEvenValue(double, boolean)) value to get a correct result (the distance from even number to even number).

        Specified by:
        getMinimumValueShiftForChange in interface IAxisLabelFormatter
        Returns:
        the minimum change in the value to format that will cause to return a different formatted String.
        See Also:
        IAxisLabelFormatter.getMinimumValueShiftForChange()
      • getNextEvenValue

        public double getNextEvenValue​(double value,
                                       boolean ceiling)
        Description copied from interface: IAxisLabelFormatter
        Returns the next "even" value to the given one. "Even" means that the format method will exactly return the String for the value and not cut or round any information. A label String created with an "even" number will be exactly at the position it describes.

        Specified by:
        getNextEvenValue in interface IAxisLabelFormatter
        Parameters:
        value - the value to get the next "even" value for.
        ceiling - if true, the next higher number will returned, else the next lower one.
        Returns:
        the next "even" value to the given one.
        See Also:
        IAxisLabelFormatter.getNextEvenValue(double, boolean)