Class AAxis.AChart2DDataAccessor

java.lang.Object
info.monitorenter.gui.chart.axis.AAxis.AChart2DDataAccessor
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AAxis.XDataAccessor, AAxis.YDataAccessor
Enclosing class:
AAxis<T extends IAxisScalePolicy>

public abstract class AAxis.AChart2DDataAccessor extends Object implements Serializable
An internal connector class that will connect the axis to the a Chart2D.

It is aggregated to the AAxis in order to access either y values or x values of the Chart2D thus making the IAxis an Y Axis or X axis. This strategy reduces redundant code for label creation. It avoids complex inheritance / interface implements for different IAxis implementation that would be necessary for y-axis / x-axis implementations.

Author:
Achim Westermann
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Chart2D
    The chart that is accessed.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor with the chart that is accessed.
  • Method Summary

    Modifier and Type
    Method
    Description
    final Chart2D
    Returns the chart that is accessed.
    abstract int
    Returns the constant for the dimension that is accessed on the chart.
    abstract int
    Returns the height in pixel the corresponding axis needs to paint itself.
    protected abstract double
    Returns the maximum pixels that will be needed to paint a label.
    protected abstract double
    Returns the max value of the given trace according to the dimension the outer axis belongs to.
    abstract double
    Returns the minimum amount of increase in the value that will be needed to display all labels without overwriting each others.
    protected abstract double
    Returns the min value of the given trace according to the dimension the outer axis belongs to.
    protected abstract int
    Returns the amount of pixel available for displaying the values on the chart in the dimension this accessor stands for.
    protected abstract double
    Returns the value of the given point according to the dimension the outer axis belongs to.
    protected abstract double
    Returns the value distance on the current chart that exists for the given amount of pixel distance in the given direction of this AAxis.
    abstract int
    Returns the width in pixel the corresponding axis needs to paint itself.
    protected abstract void
    scaleTrace(ITrace2D trace, Range range)
    Scales the given trace in the dimension represented by this axis.
    abstract double
    Returns the translation of the mouse event coordinates of the given mouse event to the value within the chart for the dimension (x,y) covered by this axis.
    abstract double
    translatePxToValue(int pixel)
    Transforms the given pixel value (which has to be a awt value like MouseEvent.getX() into the chart value.
    abstract int
    translateValueToPx(double value)
    Transforms the given chart data value into the corresponding awt pixel value for the chart.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • m_chart

      protected Chart2D m_chart
      The chart that is accessed.
  • Constructor Details

    • AChart2DDataAccessor

      protected AChart2DDataAccessor(Chart2D chart)
      Constructor with the chart that is accessed.

      Parameters:
      chart - the chart that is accessed.
  • Method Details

    • getChart

      public final Chart2D getChart()
      Returns the chart that is accessed.

      Returns:
      the chart that is accessed.
    • getDimension

      public abstract int getDimension()
      Returns the constant for the dimension that is accessed on the chart.

      Returns:
      Chart2D.X, Chart2D.Y or -1 if this axis is not assigned to a chart.
    • getHeight

      public abstract int getHeight(Graphics g2d)
      Returns the height in pixel the corresponding axis needs to paint itself.

      This includes the axis line, it's ticks and labels and it's title.

      Parameters:
      g2d - needed for font metric information.
      Returns:
      the height in pixel the corresponding axis needs to paint itself.
    • getMaximumPixelForLabel

      protected abstract double getMaximumPixelForLabel(Graphics g2d)
      Returns the maximum pixels that will be needed to paint a label.

      Parameters:
      g2d - provides information about the graphics context to paint on (e.g. font size).
      Returns:
      the maximum pixels that will be needed to paint a label.
    • getMaxValue

      protected abstract double getMaxValue(ITrace2D trace)
      Returns the max value of the given trace according to the dimension the outer axis belongs to.

      This is either an x or an y value depending on the dimension the outer axis is working in.

      Parameters:
      trace - the trace to read the maximum of.
      Returns:
      the max value of the given trace according to the dimension the outer axis belongs to.
    • getMinimumValueDistanceForLabels

      public abstract double getMinimumValueDistanceForLabels(Graphics g2d)
      Returns the minimum amount of increase in the value that will be needed to display all labels without overwriting each others.

      This procedure needs the amount of pixels needed by the largest possible label and relies on the implementation of getMaximumPixelForLabel(Graphics), whose result is multiplied with the "value per pixel" quantifier.

      Parameters:
      g2d - the current graphic context to use in case further information is required.
      Returns:
      the minimum amount of increase in the value that will be needed to display all labels without overwriting each others.
    • getMinValue

      protected abstract double getMinValue(ITrace2D trace)
      Returns the min value of the given trace according to the dimension the outer axis belongs to.

      This is either an x or an y value depending on the dimension the outer axis is working in.

      Parameters:
      trace - the trace to read the maximum of.
      Returns:
      the min value of the given trace according to the dimension the outer axis belongs to.
    • getPixelRange

      protected abstract int getPixelRange()
      Returns the amount of pixel available for displaying the values on the chart in the dimension this accessor stands for.

      This method must not be called within the first lines of a paint cycle (necessary underlying values then are computed new).

      Returns:
      the amount of pixel available for displaying the values on the chart in the dimension this accessor stands for.
    • getValue

      protected abstract double getValue(ITracePoint2D point)
      Returns the value of the given point according to the dimension the outer axis belongs to.

      This is either ITracePoint2D.getX() or ITracePoint2D.getY().

      Parameters:
      point - the point to read ITracePoint2D.getX() or ITracePoint2D.getY() from.
      Returns:
      the value of the given point according to the dimension the outer axis belongs to.
    • getValueDistanceForPixel

      protected abstract double getValueDistanceForPixel(int pixel)
      Returns the value distance on the current chart that exists for the given amount of pixel distance in the given direction of this AAxis.

      Depending on the width of the actual Chart2D and the contained values, the relation between displayed distances (pixel) and value distances (the values of the added ITrace2D instances changes.

      This method calculates depending on the actual painting area of the Chart2D, the shift in value between two points that have a screen distance of the given pixel.
      This method is not used by the chart itself but a helper for outside use.

      Parameters:
      pixel - The desired distance between to scale points of the x- axis in pixel.
      Returns:
      a scaled (from pixel to internal value-range) and normed (to the factor of the current unit of the axis) value usable to calculate the coordinates for the scale points of the axis.
    • getWidth

      public abstract int getWidth(Graphics g2d)
      Returns the width in pixel the corresponding axis needs to paint itself.

      This includes the axis line, it's ticks and labels and it's title.

      Parameters:
      g2d - needed for font metric information.
      Returns:
      the width in pixel the corresponding axis needs to paint itself.
    • scaleTrace

      protected abstract void scaleTrace(ITrace2D trace, Range range)
      Scales the given trace in the dimension represented by this axis.

      This method is not deadlock - safe and should be called by the Chart2D only!

      Parameters:
      trace - the trace to scale.
      range - the range to use as scaler.
    • translateMousePosition

      public abstract double translateMousePosition(MouseEvent mouseEvent)
      Returns the translation of the mouse event coordinates of the given mouse event to the value within the chart for the dimension (x,y) covered by this axis.

      Note that the mouse event has to be an event fired on this component!

      Parameters:
      mouseEvent - a mouse event that has been fired on this component.
      Returns:
      the translation of the mouse event coordinates of the given mouse event to the value within the chart for the dimension covered by this axis (x or y) or null if no calculations could be performed as the chart was not painted before.
    • translatePxToValue

      public abstract double translatePxToValue(int pixel)
      Transforms the given pixel value (which has to be a awt value like MouseEvent.getX() into the chart value.

      Internal use only, the interface does not guarantee that the pixel corresponds to any valid awt pixel value within the chart component.

      Warning: A value transformed to a pixel by translateValueToPx(double) and then retransformed by translatePxToValue(int) will most often have changed, as the transformation from value to px a) has to hit an exact int b) most often will map from a bigger domain (value range) to a smaller one (range of chart on the screen).

      Parameters:
      pixel - a pixel value of the chart component as used by awt.
      Returns:
      the awt pixel value transformed to the chart value.
    • translateValueToPx

      public abstract int translateValueToPx(double value)
      Transforms the given chart data value into the corresponding awt pixel value for the chart.

      The inverse transformation to translatePxToValue(int).

      Parameters:
      value - a chart data value.
      Returns:
      the awt pixel value corresponding to the chart data value.