info.monitorenter.gui.chart.axis
Class AAxis.AChart2DDataAccessor

java.lang.Object
  extended by info.monitorenter.gui.chart.axis.AAxis.AChart2DDataAccessor
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AAxis.XDataAccessor, AAxis.YDataAccessor
Enclosing class:
AAxis

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:
Serialized Form

Field Summary
protected  Chart2D m_chart
          The chart that is accessed.
protected  IRangePolicy m_rangePolicy
          A pluggable range policy.
 
Constructor Summary
protected AAxis.AChart2DDataAccessor(Chart2D chart)
          Constructor with the chart that is acessed.
 
Method Summary
 Chart2D getChart()
          Returns the chart that is accessed.
abstract  int getDimension()
          Returns the constant for the dimension that is accessed on the chart.
abstract  int getHeight(Graphics2D g2d)
          Returns the height in pixel the corresponding axis needs to paint itself.
protected abstract  double getMax()
          Returns the maximum value from the Chart2D's axis (X or Y) this instance is standing for with respect to the installed range policy.
abstract  double getMaxFromAxis()
           
protected abstract  double getMaximumPixelForLabel(Graphics g2d)
          Returns the maximum pixels that will be needed to paint a label.
protected abstract  double getMin()
           
abstract  double getMinFromAxis()
           
protected 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.
protected abstract  int getPixelRange()
          Returns the amount of pixel avalable for displaying the values on the chart in the dimension this accessor stands for.
 IRangePolicy getRangePolicy()
           
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.
abstract  int getWidth(Graphics2D g2d)
          Returns the width in pixel the corresponding axis needs to paint itself.
protected abstract  void scale()
          Scales all ITrace2D instances in the dimension represented by this axis.
protected abstract  void scaleTrace(ITrace2D trace, Range range)
          Scales the given trace in the dimension represented by this axis.
 void setRangePolicy(IRangePolicy rangePolicy)
          Sets the RangePolicy.
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.
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 Detail

m_chart

protected Chart2D m_chart
The chart that is accessed.


m_rangePolicy

protected IRangePolicy m_rangePolicy
A pluggable range policy.

Constructor Detail

AAxis.AChart2DDataAccessor

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

Parameters:
chart - the chart that is acessed.
Method Detail

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(Graphics2D 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.

getMax

protected abstract double getMax()
Returns the maximum value from the Chart2D's axis (X or Y) this instance is standing for with respect to the installed range policy.

Returns:
the maximum value from the Chart2D's axis (X or Y) this instance is standing for with respect to the installed range policy.

getMaxFromAxis

public abstract double getMaxFromAxis()
Returns:
the maximum value from the Chart2D's "axis" (X or Y) this instance is standing for.

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.

getMin

protected abstract double getMin()
Returns:
the minimum value from the Chart2D's "axis" (X or Y) this instance is standing for with respect to the installed range policy.

getMinFromAxis

public abstract double getMinFromAxis()
Returns:
the minimum value from the Chart2D's "axis" (X or Y) this instance is standing for.

getMinimumValueDistanceForLabels

protected 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.

getPixelRange

protected abstract int getPixelRange()
Returns the amount of pixel avalable 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 (neccessary underlying values then are computed new).

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

getRangePolicy

public final IRangePolicy getRangePolicy()
Returns:
Returns the rangePolicy.

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 addes 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 scalepoints 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 coords for the scalepoints of the axis.

getWidth

public abstract int getWidth(Graphics2D 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.

scale

protected abstract void scale()
Scales all ITrace2D instances in the dimension represented by this axis.

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


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.

setRangePolicy

public final void setRangePolicy(IRangePolicy rangePolicy)
Sets the RangePolicy.

A new Range with minimum and maxium of the chart is set to it to ensure that after the change all traces are shown.

Parameters:
rangePolicy - The rangePolicy to set.

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.


Copyright © 2001 - 2007 LGPL, All Rights Footloose.