info.monitorenter.gui.chart.axis
Class AAxis<T extends IAxisScalePolicy>

java.lang.Object
  extended by info.monitorenter.gui.chart.axis.AAxis<T>
Type Parameters:
T - Subtypes may be more picky which scale policies the accept to disallow incorrect scales: This supports it (see IAxis.setAxisScalePolicy(IAxisScalePolicy)).
All Implemented Interfaces:
IAxis<T>, java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener
Direct Known Subclasses:
AAxisTransformation, AxisInverse, AxisLinear

public abstract class AAxis<T extends IAxisScalePolicy>
extends java.lang.Object
implements IAxis<T>, java.beans.PropertyChangeListener

The base class for an axis of the Chart2D.

Normally - as the design and interaction of an Axis with the Chart2DD is very fine-grained - it is not instantiated by users of jchart2d: It is automatically instantiated by the constructor of Chart2D. It then may be retrieved from the Chart2D by the methods Chart2D.getAxisX() and Chart2D.getAxisY() for further configuration.

Version:
$Revision: 1.61 $
Author:
Achim Westermann
See Also:
Serialized Form

Nested Class Summary
 class AAxis.AChart2DDataAccessor
          An internal connector class that will connect the axis to the a Chart2D.
 class AAxis.XDataAccessor
          An accessor for the x axis of a chart.
protected  class AAxis.YDataAccessor
          Accesses the y axis of the Chart2D.
 
Nested classes/interfaces inherited from interface info.monitorenter.gui.chart.IAxis
IAxis.AxisTitle
 
Field Summary
static boolean DEBUG
          Debugging flag for sysouts.
protected  AAxis.AChart2DDataAccessor m_accessor
          The accessor to the Chart2D.
protected  IAxisLabelFormatter m_formatter
          Formatting of the labels.
protected  double m_majorTickSpacing
          The major tick spacing for label generations.
protected  double m_max
          The current maximum value for all points in all traces.
protected  double m_min
          The current minimum value for all points in all traces.
protected  double m_minorTickSpacing
          The minor tick spacing for label generations.
protected  boolean m_needsFullRescale
          Flag to detect if a re-scaling has to be done.
protected  IRangePolicy m_rangePolicy
          A plugable range policy.
 
Fields inherited from interface info.monitorenter.gui.chart.IAxis
PROPERTY_ADD_REMOVE_TRACE, PROPERTY_AXIS_SCALE_POLICY_CHANGED, PROPERTY_LABELFORMATTER, PROPERTY_PAINTGRID, PROPERTY_PAINTSCALE, PROPERTY_RANGEPOLICY
 
Constructor Summary
AAxis()
          Default constructor that uses a LabelFormatterAutoUnits for formatting labels.
AAxis(IAxisLabelFormatter formatter, T scalePolicy)
          Constructor that uses the given label formatter for formatting labels.
 
Method Summary
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Add a listener for the given property.
 boolean addTrace(ITrace2D trace)
          Adds a trace that belongs to this axis.
protected abstract  AAxis.AChart2DDataAccessor createAccessor(Chart2D chart, int dimension, int position)
          Template method to create the proper AAxis.AChart2DDataAccessor implementation.
protected  void ensureInitialized()
          Ensures that no deadlock / NPE due to a missing internal chart reference may occur.
 boolean equals(java.lang.Object obj)
           
protected  double findMax()
          Searches for the maximum value of all contained ITraces in the dimension this axis stands for.
protected  double findMin()
          Searches for the minimum value of all contained ITraces in the dimension this axis stands for.
 AAxis.AChart2DDataAccessor getAccessor()
          Returns the accessor to the chart.
 int getAxisPosition()
          Returns the constant for the position of this axis for the chart.
 IAxisScalePolicy getAxisScalePolicy()
          Returns the axis scale policy which controls the position and distance of the ticks to draw.
 IAxis.AxisTitle getAxisTitle()
          Returns the title of this axis.
 int getDimension()
          Returns the constant for the dimension this axis stands for in the chart.
 java.lang.String getDimensionString()
          Returns the String constant for the dimension this axis stands for in the chart.
 IAxisLabelFormatter getFormatter()
          Returns the formatter for labels.
 int getHeight(java.awt.Graphics g2d)
          Returns the height in pixel this axis needs to paint itself.
 double getMajorTickSpacing()
          Get the major tick spacing for label generation.
 double getMax()
          Returns the maximum value from all traces of this axis with respect to the installed range policy.
 double getMaxValue()
          Returns the maximum value of all TracePoint2D instances in all ITrace2D instances in this axis regardless of the configured IRangePolicy (see IAxis.setRangePolicy(IRangePolicy)).
 double getMin()
          Returns the minimum value of all traces of this axis with respect to the installed range policy.
 double getMinorTickSpacing()
          Get the minor tick spacing for label generation.
 double getMinValue()
          Returns the minimum value of all TracePoint2D instances in all ITrace2D instances in this axis regardless of the configured IRangePolicy (see IAxis.setRangePolicy(IRangePolicy)).
 int getPixelXLeft()
          Returns the left pixel of this axis coordinate in the graphic context of the current paint operation.
 int getPixelXRight()
          Returns the right pixel coordinate of this axis in the graphic context of the current paint operation.
 int getPixelYBottom()
          Returns the bottom pixel coordinate of this axis in the graphic context of the current paint operation.
 int getPixelYTop()
          Returns the top pixel coordinate of this axis in the graphic context of the current paint operation.
 java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
          Returns an array of all the listeners that were added to the this instance with IAxis.addPropertyChangeListener(String, PropertyChangeListener).
 Range getRange()
          This method is used by the Chart2D to scale it's values during painting.
 IRangePolicy getRangePolicy()
          Returns the range policy of this axis.
 java.lang.String getTitle()
          Deprecated. use getAxisTitle() and on the result IAxis.AxisTitle#getTitle().
 IAxisTitlePainter getTitlePainter()
          Deprecated. this method might be dropped because the painter should be of no concern.
 java.util.Set<ITrace2D> getTraces()
          Returns a Set<ITrace2D> with all traces covered by this axis.
protected  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 Axis.
 int getWidth(java.awt.Graphics g2d)
          Returns the width in pixel this axis needs to paint itself.
 int hashCode()
           
 boolean hasTrace(ITrace2D trace)
          Returns true if this axis is responsible for rendering the scale of the given trace (IAxis.addTrace(ITrace2D) was called on this instance with the given trace).
 void initPaintIteration()
          Performs expensive calculations for various values that are used by many calls throughout a paint iterations.
 boolean isDirtyScaling()
          Returns true if the bounds in the given dimension of all TracePoint2D instances of all internal ITrace2D instances have changed since all points have been normalized to a value between 0 and 1 or true if this axis has different range since the last call to IAxis.scale().
 boolean isPaintGrid()
          Returns whether the x grid is painted or not.
 boolean isPaintScale()
          Returns whether the scale for this axis should be painted or not.
 boolean isStartMajorTick()
          Check whether scale values are started from major ticks.
 boolean isVisible()
          Check if this axis is visible, i.e.
 void paint(java.awt.Graphics g2d)
          Renders the axis line along with title, scale, scale labels and unit label.
 int paintTitle(java.awt.Graphics g2d)
          Routine for painting the title of this axis.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          Receives all PropertyChangeEvent from all instances the chart registers itself as a PropertyChangeListener .
 java.util.Set<ITrace2D> removeAllTraces()
          Convenience method for removing all contained ITrace2D instances of this axis.
 IAxis.AxisTitle removeAxisTitle()
          Removes the title of this axis.
 void removePropertyChangeListener(java.lang.String property, java.beans.PropertyChangeListener listener)
          Remove a PropertyChangeListener for a specific property.
 boolean removeTrace(ITrace2D trace)
          Removes the given trace from this axis.
 void scale()
          Scales all ITrace2D instances in the dimension represented by this axis.
protected  void scalePoint(ITracePoint2D point)
          Internally rescales the given ITracePoint2D in the dimension this axis works in.
 void scaleTrace(ITrace2D trace)
          Scales the given ITrace2D in the dimension represented by this axis.
protected  void setAccessor(AAxis.AChart2DDataAccessor accessor)
          Sets the accessor to the axis of the chart.
protected  void setAxisPosition(int axisPosition)
          Sets the axisPosition.
 IAxisScalePolicy setAxisScalePolicy(T axisScalePolicy)
          The default used is AxisScalePolicyAutomaticBestFit.
 void setAxisTitle(IAxis.AxisTitle axisTitle)
          Sets the title of this axis.
 void setChart(Chart2D chart, int dimension, int position)
          Callback that allows the chart to register itself with the axis when the axis is added to the chart.
 void setFormatter(IAxisLabelFormatter formatter)
          Sets the formatter to use for labels.
 void setMajorTickSpacing(double majorTickSpacing)
          This method sets the major tick spacing for label generation.
 void setMinorTickSpacing(double minorTickSpacing)
          This method sets the minor tick spacing for label generation.
 void setPaintGrid(boolean grid)
          Set whether the grid in this dimension should be painted or not.
 void setPaintScale(boolean show)
          Set if the scale for this axis should be shown.
 void setPixelXLeft(int pixelXLeft)
          Sets a Range to use for filtering the view to the the connected Axis.
 void setPixelXRight(int pixelXRight)
          Sets the right pixel of this axis coordinate in the graphic context of the current paint operation.
 void setPixelYBottom(int pixelYBottom)
          Sets the bottom pixel of this axis coordinate in the graphic context of the current paint operation.
 void setPixelYTop(int pixelYTop)
          Sets the top pixel of this axis coordinate in the graphic context of the current paint operation.
 void setRange(Range range)
           Sets a Range to use for filtering the view to the the connected Axis.
 void setRangePolicy(IRangePolicy rangePolicy)
           Sets the RangePolicy.
 void setStartMajorTick(boolean majorTick)
          Set wether scale values are started from major ticks.
 java.lang.String setTitle(java.lang.String title)
          Deprecated. use getAxisTitle() and on the result IAxis.AxisTitle#setTitle(String)
 IAxisTitlePainter setTitlePainter(IAxisTitlePainter painter)
          Deprecated. use getAxisTitle() and on the result IAxis.AxisTitle#setTitlePainter(IAxisTitlePainter) instead.
 void setVisible(boolean visible)
          Set the visibility of this axis.
 double translateMousePosition(java.awt.event.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.
 double translatePxToValue(int pixel)
          Transforms the given pixel value (which has to be a awt value like MouseEvent.getY() into the chart value.
 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, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface info.monitorenter.gui.chart.IAxis
getScaledValue
 

Field Detail

DEBUG

public static final boolean DEBUG
Debugging flag for sysouts.

See Also:
Constant Field Values

m_accessor

protected AAxis.AChart2DDataAccessor m_accessor
The accessor to the Chart2D.

It determines, which axis (x or y) this instance is representing.


m_formatter

protected IAxisLabelFormatter m_formatter
Formatting of the labels.


m_majorTickSpacing

protected double m_majorTickSpacing
The major tick spacing for label generations.

See Also:
setMajorTickSpacing(double)

m_max

protected double m_max
The current maximum value for all points in all traces.


m_min

protected double m_min
The current minimum value for all points in all traces.


m_minorTickSpacing

protected double m_minorTickSpacing
The minor tick spacing for label generations.

See Also:
setMinorTickSpacing(double)

m_needsFullRescale

protected boolean m_needsFullRescale
Flag to detect if a re-scaling has to be done.

It is set to false in scale() which is triggered from the painting Thread. Whenever a bound change is detected in propertyChange(PropertyChangeEvent) this is set to true.

Please remind: In previous versions there was only a test if the bounds had changed since the last scaling. This was not always correct: If in between two paint cycles the bounds were changed and new points added but at the point in time when the 2nd paint cycle starts the bounds would be equal no full rescaling would be performed even if the added points would have been scaled in relation to the changed bounds at their adding time: Bounds checks are not sufficient!


m_rangePolicy

protected IRangePolicy m_rangePolicy
A plugable range policy.

Constructor Detail

AAxis

public AAxis()
Default constructor that uses a LabelFormatterAutoUnits for formatting labels.


AAxis

public AAxis(IAxisLabelFormatter formatter,
             T scalePolicy)
Constructor that uses the given label formatter for formatting labels.

Parameters:
formatter - needed for formatting labels of this axis.
scalePolicy - controls the ticks/labels and their distance.
Method Detail

getAxisScalePolicy

public IAxisScalePolicy getAxisScalePolicy()
Description copied from interface: IAxis
Returns the axis scale policy which controls the position and distance of the ticks to draw.

Specified by:
getAxisScalePolicy in interface IAxis<T extends IAxisScalePolicy>
Returns:
the axis scale policy which controls the position and distance of the ticks to draw.
See Also:
IAxis.getAxisScalePolicy()

setAxisScalePolicy

public IAxisScalePolicy setAxisScalePolicy(T axisScalePolicy)
The default used is AxisScalePolicyAutomaticBestFit.

Specified by:
setAxisScalePolicy in interface IAxis<T extends IAxisScalePolicy>
Parameters:
axisScalePolicy - the axis scale policy which controls the position and distance of the ticks to draw to use.
Returns:
the previous axis scale policy that was used before.
See Also:
IAxis.setAxisScalePolicy(info.monitorenter.gui.chart.IAxisScalePolicy)

getDimensionString

public java.lang.String getDimensionString()
Description copied from interface: IAxis
Returns the String constant for the dimension this axis stands for in the chart.

Specified by:
getDimensionString in interface IAxis<T extends IAxisScalePolicy>
Returns:
"X", "Y" or null if not assigned to a Chart2D.
See Also:
IAxis.getDimensionString()

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)
Description copied from interface: IAxis
Add a listener for the given property.

The following PropertyChangeEvent types should be fired to listeners:

getPropertyName() getSource() getOldValue() getNewValue()
IAxis.PROPERTY_ADD_REMOVE_TRACE IAxis that changed null - a new trace was added. ITrace2D, the new trace.
IAxis.PROPERTY_ADD_REMOVE_TRACE IAxis that changed ITrace2D, the old trace. null - the trace was removed.
IAxis.PROPERTY_RANGEPOLICY IAxis that changed IRangePolicy, the old value. IRangePolicy, the new value.
IAxis.PROPERTY_PAINTGRID IAxis that changed Boolean, the old value. Boolean, the new value.
IAxis.PROPERTY_LABELFORMATTER IAxis that changed IAxisLabelFormatter, the old value or null if there was no formatter before. IAxisLabelFormatter, the new value.
IAxis.PROPERTY_AXIS_SCALE_POLICY_CHANGED IAxis that changed IAxisScalePolicy, the old value. IAxisScalePolicy, the new value.

Specified by:
addPropertyChangeListener in interface IAxis<T extends IAxisScalePolicy>
Parameters:
propertyName - the property to be informed about changes.
listener - the listener that will be informed.
See Also:
IAxis.addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)

addTrace

public boolean addTrace(ITrace2D trace)
Description copied from interface: IAxis
Adds a trace that belongs to this axis.

Adding a trace that is already contained may be problematic, so an exception should be raised in that case to warn you that your code is doing unnecessary to malicious operations.

Specified by:
addTrace in interface IAxis<T extends IAxisScalePolicy>
Parameters:
trace - the trace to add.
Returns:
true if the trace was added, false else.
See Also:
IAxis.addTrace(info.monitorenter.gui.chart.ITrace2D)

createAccessor

protected abstract AAxis.AChart2DDataAccessor createAccessor(Chart2D chart,
                                                             int dimension,
                                                             int position)
Template method to create the proper AAxis.AChart2DDataAccessor implementation.

Parameters:
chart - the chart to access.
dimension - Chart2D.X or Chart2D.Y.
position - Chart2D.CHART_POSITION_BOTTOM, Chart2D.CHART_POSITION_LEFT, Chart2D.CHART_POSITION_RIGHT or Chart2D.CHART_POSITION_TOP.
Returns:
the proper AAxis.AChart2DDataAccessor implementation.

equals

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

findMax

protected final double findMax()
Searches for the maximum value of all contained ITraces in the dimension this axis stands for.

This method is triggered when a trace fired a property change for property ITrace2D.PROPERTY_MAX_X or ITrace2D.PROPERTY_MAX_Y with a value lower than the internal stored maximum.

Performance breakdown is avoided because all ITrace2D implementations cache their max and min values.

Returns:
the maximum value of all traces for the dimension this axis works in.

findMin

protected final double findMin()
Searches for the minimum value of all contained ITraces in the dimension this axis stands for.

This method is triggered when a trace fired a property change for property ITrace2D.PROPERTY_MAX_X or ITrace2D.PROPERTY_MAX_Y with a value lower than the internal stored minimum.

Performance breakdown is avoided because all ITrace2D implementations cache their max and min values.

Returns:
the minimum value of all traces for the dimension this axis works in.

getAccessor

public AAxis.AChart2DDataAccessor getAccessor()
Returns the accessor to the chart.

Specified by:
getAccessor in interface IAxis<T extends IAxisScalePolicy>
Returns:
the accessor to the chart.

getAxisPosition

public int getAxisPosition()
Description copied from interface: IAxis
Returns the constant for the position of this axis for the chart.

Specified by:
getAxisPosition in interface IAxis<T extends IAxisScalePolicy>
Returns:
Chart2D.CHART_POSITION_LEFT, Chart2D.CHART_POSITION_RIGHT, Chart2D.CHART_POSITION_TOP, Chart2D.CHART_POSITION_BOTTOM or -1 if this axis is not assigned to a chart.
See Also:
IAxis.getAxisPosition()

getAxisTitle

public IAxis.AxisTitle getAxisTitle()
Description copied from interface: IAxis
Returns the title of this axis.

Specified by:
getAxisTitle in interface IAxis<T extends IAxisScalePolicy>
Returns:
the axis title used.
See Also:
IAxis.getAxisTitle()

getDimension

public int getDimension()
Description copied from interface: IAxis
Returns the constant for the dimension this axis stands for in the chart.

Specified by:
getDimension in interface IAxis<T extends IAxisScalePolicy>
Returns:
Chart2D.X, Chart2D.Y or -1 if this axis is not assigned to a chart.
See Also:
IAxis.getDimension()

getFormatter

public final IAxisLabelFormatter getFormatter()
Description copied from interface: IAxis
Returns the formatter for labels.

Specified by:
getFormatter in interface IAxis<T extends IAxisScalePolicy>
Returns:
Returns the formatter.

getHeight

public final int getHeight(java.awt.Graphics g2d)
Description copied from interface: IAxis
Returns the height in pixel this axis needs to paint itself.

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

Note:
For an y axis the hight only includes the overhang it needs on the upper edge for painting a complete lable, not the complete space it needs for the complete line.

Specified by:
getHeight in interface IAxis<T extends IAxisScalePolicy>
Parameters:
g2d - needed for font metric information.
Returns:
the height in pixel this axis needs to paint itself.
See Also:
IAxis.getHeight(java.awt.Graphics)

getMajorTickSpacing

public double getMajorTickSpacing()
Description copied from interface: IAxis
Get the major tick spacing for label generation.

Specified by:
getMajorTickSpacing in interface IAxis<T extends IAxisScalePolicy>
Returns:
the major tick spacing for label generation.
See Also:
IAxis.getMajorTickSpacing()

getMax

public double getMax()
Description copied from interface: IAxis
Returns the maximum value from all traces of this axis with respect to the installed range policy.

Specified by:
getMax in interface IAxis<T extends IAxisScalePolicy>
Returns:
the maximum value from all traces of this axis with respect to the installed range policy.
See Also:
IAxis.getMax()

getMaxValue

public double getMaxValue()
Description copied from interface: IAxis
Returns the maximum value of all TracePoint2D instances in all ITrace2D instances in this axis regardless of the configured IRangePolicy (see IAxis.setRangePolicy(IRangePolicy)). The returned value is either in x or y dimension - depending on the dimension this axis is working in for the chart.

Specified by:
getMaxValue in interface IAxis<T extends IAxisScalePolicy>
Returns:
the maximum value of all TracePoint2D instances in all ITrace2D instances in this axis regardless of the configured IRangePolicy (see IAxis.setRangePolicy(IRangePolicy)).
See Also:
IAxis.getMaxValue()

getMin

public double getMin()
Description copied from interface: IAxis
Returns the minimum value of all traces of this axis with respect to the installed range policy.

Specified by:
getMin in interface IAxis<T extends IAxisScalePolicy>
Returns:
the minimum value of all traces of this axis with respect to the installed range policy.
See Also:
IAxis.getMin()

getMinorTickSpacing

public double getMinorTickSpacing()
Get the minor tick spacing for label generation.

Specified by:
getMinorTickSpacing in interface IAxis<T extends IAxisScalePolicy>
Returns:
he minor tick spacing for label generation.
See Also:
setMinorTickSpacing(double)

getMinValue

public double getMinValue()
Description copied from interface: IAxis
Returns the minimum value of all TracePoint2D instances in all ITrace2D instances in this axis regardless of the configured IRangePolicy (see IAxis.setRangePolicy(IRangePolicy)). The returned value is either in x or y dimension - depending on the dimension this axis is working in for the chart.

Specified by:
getMinValue in interface IAxis<T extends IAxisScalePolicy>
Returns:
the minimum value of all TracePoint2D instances in all ITrace2D instances in this axis regardless of the configured IRangePolicy (see IAxis.setRangePolicy(IRangePolicy)).
See Also:
IAxis.getMinValue()

getPixelXLeft

public final int getPixelXLeft()
Description copied from interface: IAxis
Returns the left pixel of this axis coordinate in the graphic context of the current paint operation.

Note that this value is only valid throughout a Chart2D.paint(java.awt.Graphics) invocation.

Specified by:
getPixelXLeft in interface IAxis<T extends IAxisScalePolicy>
Returns:
the left pixel coordinate of this axis in the graphic context of the current paint operation.
See Also:
IAxis.getPixelXLeft()

getPixelXRight

public final int getPixelXRight()
Description copied from interface: IAxis
Returns the right pixel coordinate of this axis in the graphic context of the current paint operation.

Note that this value is only valid throughout a Chart2D.paint(java.awt.Graphics) invocation.

Specified by:
getPixelXRight in interface IAxis<T extends IAxisScalePolicy>
Returns:
the right pixel coordinate of this axis in the graphic context of the current paint operation.
See Also:
IAxis.getPixelXRight()

getPixelYBottom

public final int getPixelYBottom()
Description copied from interface: IAxis
Returns the bottom pixel coordinate of this axis in the graphic context of the current paint operation.

Note that this value is only valid throughout a Chart2D.paint(java.awt.Graphics) invocation.

Specified by:
getPixelYBottom in interface IAxis<T extends IAxisScalePolicy>
Returns:
the bottom pixel coordinate of this axis in the graphic context of the current paint operation.
See Also:
IAxis.getPixelYBottom()

getPixelYTop

public final int getPixelYTop()
Description copied from interface: IAxis
Returns the top pixel coordinate of this axis in the graphic context of the current paint operation.

Note that this value is only valid throughout a Chart2D.paint(java.awt.Graphics) invocation.

Specified by:
getPixelYTop in interface IAxis<T extends IAxisScalePolicy>
Returns:
the top pixel coordinate of this axis in the graphic context of the current paint operation.
See Also:
IAxis.getPixelYTop()

getPropertyChangeListeners

public java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
Description copied from interface: IAxis
Returns an array of all the listeners that were added to the this instance with IAxis.addPropertyChangeListener(String, PropertyChangeListener).

Specified by:
getPropertyChangeListeners in interface IAxis<T extends IAxisScalePolicy>
Parameters:
propertyName - The name of the property being listened to.
Returns:
an array of all the listeners that were added to the this instance with IAxis.addPropertyChangeListener(String, PropertyChangeListener).
See Also:
IAxis.getPropertyChangeListeners(java.lang.String)

getRange

public final Range getRange()
This method is used by the Chart2D to scale it's values during painting.

Caution: This method does not necessarily return the Range configured with setRange(Range). The internal IRangePolicy is taken into account.

Specified by:
getRange in interface IAxis<T extends IAxisScalePolicy>
Returns:
the range corresponding to the upper and lower bound of the values that will be visible on this Axis of the Chart2D.
See Also:
setRangePolicy(IRangePolicy)

getRangePolicy

public IRangePolicy getRangePolicy()
Returns the range policy of this axis.

Specified by:
getRangePolicy in interface IAxis<T extends IAxisScalePolicy>
Returns:
the range policy of this axis.

getTitle

@Deprecated
public final java.lang.String getTitle()
Deprecated. use getAxisTitle() and on the result IAxis.AxisTitle#getTitle().

Description copied from interface: IAxis
Returns the title or null if there was no title configured before.

Specified by:
getTitle in interface IAxis<T extends IAxisScalePolicy>
Returns:
the title or null if there was no title configured before.
See Also:
IAxis.getTitlePainter()

getTitlePainter

@Deprecated
public final IAxisTitlePainter getTitlePainter()
Deprecated. this method might be dropped because the painter should be of no concern.

Description copied from interface: IAxis
Returns the instance that will paint the title of this axis.

Specified by:
getTitlePainter in interface IAxis<T extends IAxisScalePolicy>
Returns:
the instance that will paint the title of this axis.
See Also:
IAxis.getTitlePainter()

getTraces

public java.util.Set<ITrace2D> getTraces()
Description copied from interface: IAxis
Returns a Set<ITrace2D> with all traces covered by this axis.

Caution!
The original internal modifiable set is returned for performance reasons and by contract (to allow removing traces) so do not mess with it to avoid ugly unpredictable side effects!

Specified by:
getTraces in interface IAxis<T extends IAxisScalePolicy>
Returns:
a Set<ITrace2D> with all traces covered by this axis.
See Also:
IAxis.getTraces()

getValueDistanceForPixel

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

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 final int getWidth(java.awt.Graphics g2d)
Description copied from interface: IAxis
Returns the width in pixel this axis needs to paint itself.

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

Note:
For an x axis the width only includes the overhang it needs on the right edge for painting a complete label, not the complete space it needs for the complete line.

Specified by:
getWidth in interface IAxis<T extends IAxisScalePolicy>
Parameters:
g2d - needed for font metric information.
Returns:
the width in pixel this axis needs to paint itself.
See Also:
IAxis.getWidth(java.awt.Graphics)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

hasTrace

public final boolean hasTrace(ITrace2D trace)
Description copied from interface: IAxis
Returns true if this axis is responsible for rendering the scale of the given trace (IAxis.addTrace(ITrace2D) was called on this instance with the given trace).

Specified by:
hasTrace in interface IAxis<T extends IAxisScalePolicy>
Parameters:
trace - the trace to check for containment.
Returns:
true if this axis is responsible for rendering the scale of the given trace (IAxis.addTrace(ITrace2D) was called on this instance with the given trace).
See Also:
IAxis.hasTrace(info.monitorenter.gui.chart.ITrace2D)

initPaintIteration

public void initPaintIteration()
Performs expensive calculations for various values that are used by many calls throughout a paint iterations.

These values are constant throughout a paint iteration by the contract that no point is added removed or changed in this period. Because these values are used from many methods it is impossible to calculate them at a "transparent" method that may perform this caching over a paint period without knowledge from outside. The first method called in a paint iteration is called several further times in the iteration. So this is the common hook to invoke before painting a chart.

Specified by:
initPaintIteration in interface IAxis<T extends IAxisScalePolicy>

isDirtyScaling

public final boolean isDirtyScaling()
Description copied from interface: IAxis
Returns true if the bounds in the given dimension of all TracePoint2D instances of all internal ITrace2D instances have changed since all points have been normalized to a value between 0 and 1 or true if this axis has different range since the last call to IAxis.scale().

Specified by:
isDirtyScaling in interface IAxis<T extends IAxisScalePolicy>
Returns:
true if the bounds in the given dimension of all TracePoint2D instances of all internal ITrace2D instances have changed since all points have been normalized to a value between 0 and 1 or true if this axis has different range since the last call to IAxis.scale().
See Also:
IAxis.isDirtyScaling()

isPaintGrid

public final boolean isPaintGrid()
Returns whether the x grid is painted or not.

Specified by:
isPaintGrid in interface IAxis<T extends IAxisScalePolicy>
Returns:
whether the x grid is painted or not.

isPaintScale

public final boolean isPaintScale()
Returns whether the scale for this axis should be painted or not.

Specified by:
isPaintScale in interface IAxis<T extends IAxisScalePolicy>
Returns:
whether the scale for this axis should be painted or not.

isStartMajorTick

public boolean isStartMajorTick()
Check whether scale values are started from major ticks.

Specified by:
isStartMajorTick in interface IAxis<T extends IAxisScalePolicy>
Returns:
true if scale values start from major ticks.
See Also:
setMajorTickSpacing(double)

isVisible

public boolean isVisible()
Check if this axis is visible, i.e. needs to be painted on the chart.

Specified by:
isVisible in interface IAxis<T extends IAxisScalePolicy>
Returns:
true if this axis has to be painted on the chart.

paint

public void paint(java.awt.Graphics g2d)
Description copied from interface: IAxis
Renders the axis line along with title, scale, scale labels and unit label.

This should only be called from Chart2D, all other uses may cause damaged UI or deadlocks.

Specified by:
paint in interface IAxis<T extends IAxisScalePolicy>
Parameters:
g2d - the graphics context to use.
See Also:
IAxis.paint(java.awt.Graphics)

paintTitle

public int paintTitle(java.awt.Graphics g2d)
Description copied from interface: IAxis
Routine for painting the title of this axis.

Intended for Chart2D only!!!

Specified by:
paintTitle in interface IAxis<T extends IAxisScalePolicy>
Parameters:
g2d - needed for painting.
Returns:
the width consumed in pixel for y axis, the height consumed in pixel for x axis.
See Also:
IAxis.paintTitle(java.awt.Graphics)

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Receives all PropertyChangeEvent from all instances the chart registers itself as a PropertyChangeListener .

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
evt - the property change event that was fired.
See Also:
PropertyChangeListener.propertyChange(java.beans.PropertyChangeEvent)

removeAllTraces

public final java.util.Set<ITrace2D> removeAllTraces()
Description copied from interface: IAxis
Convenience method for removing all contained ITrace2D instances of this axis.

Implementations should fire a PropertyChangeEvent for the PropertyChangeEvent.getPropertyName() IAxis.PROPERTY_ADD_REMOVE_TRACE for every single trace removed. This is done best by delegating this call to several calls to IAxis.removeTrace(ITrace2D).

Specified by:
removeAllTraces in interface IAxis<T extends IAxisScalePolicy>
Returns:
a shallow copy of the set of traces that were contained before.
See Also:
IAxis.removeAllTraces()

removeAxisTitle

public IAxis.AxisTitle removeAxisTitle()
Description copied from interface: IAxis
Removes the title of this axis.

Prefer this method instead of IAxis.getAxisTitle() if you want to drop the axis title as this method also "unlistens" this axis from it's title.

Specified by:
removeAxisTitle in interface IAxis<T extends IAxisScalePolicy>
Returns:
the removed title.
See Also:
IAxis.removeAxisTitle()

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String property,
                                         java.beans.PropertyChangeListener listener)
Description copied from interface: IAxis
Remove a PropertyChangeListener for a specific property. If listener was added more than once to the same event source for the specified property, it will be notified one less time after being removed. If propertyName is null, no exception is thrown and no action is taken. If listener is null, or was never added for the specified property, no exception is thrown and no action is taken.

Specified by:
removePropertyChangeListener in interface IAxis<T extends IAxisScalePolicy>
Parameters:
property - The name of the property that was listened on.
listener - The PropertyChangeListener to be removed.
See Also:
IAxis.removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)

removeTrace

public boolean removeTrace(ITrace2D trace)
Description copied from interface: IAxis
Removes the given trace from this axis.

A PropertyChangeEvent for the PropertyChangeEvent.getPropertyName() IAxis.PROPERTY_ADD_REMOVE_TRACE has to be fired on the registered PropertyChangeListener for the trace removed.

Specified by:
removeTrace in interface IAxis<T extends IAxisScalePolicy>
Parameters:
trace - the trace to remove from this axis.
Returns:
true if the given trace could be removed from this axis, false else.
See Also:
IAxis.removeTrace(info.monitorenter.gui.chart.ITrace2D)

scalePoint

protected final void scalePoint(ITracePoint2D point)
Internally rescales the given ITracePoint2D in the dimension this axis works in.

Parameters:
point - the point to scale (between 0.0 and 1.0) according to the internal bounds.

scale

public void scale()
Description copied from interface: IAxis
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!

Specified by:
scale in interface IAxis<T extends IAxisScalePolicy>
See Also:
IAxis.scale()

scaleTrace

public void scaleTrace(ITrace2D trace)
Description copied from interface: IAxis
Scales the given ITrace2D in the dimension represented by this axis.

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

Specified by:
scaleTrace in interface IAxis<T extends IAxisScalePolicy>
Parameters:
trace - the trace to scale.
See Also:
IAxis.scaleTrace(info.monitorenter.gui.chart.ITrace2D)

setAccessor

protected final void setAccessor(AAxis.AChart2DDataAccessor accessor)
Sets the accessor to the axis of the chart.

Parameters:
accessor - the accessor to the axis of the chart.

setAxisPosition

protected final void setAxisPosition(int axisPosition)
Sets the axisPosition.

Parameters:
axisPosition - Chart2D.CHART_POSITION_LEFT, Chart2D.CHART_POSITION_RIGHT, Chart2D.CHART_POSITION_TOP, Chart2D.CHART_POSITION_BOTTOM or -1 if this axis is not assigned to a chart.

setAxisTitle

public void setAxisTitle(IAxis.AxisTitle axisTitle)
Description copied from interface: IAxis
Sets the title of this axis.

Specified by:
setAxisTitle in interface IAxis<T extends IAxisScalePolicy>
Parameters:
axisTitle - the axis title to use.
See Also:
IAxis.setAxisTitle(info.monitorenter.gui.chart.IAxis.AxisTitle)

setChart

public void setChart(Chart2D chart,
                     int dimension,
                     int position)
Callback that allows the chart to register itself with the axis when the axis is added to the chart.

This is intended for Chart2D only!. Please do not use this from anywhere in your code. It allows to

Parameters:
chart - the chart to register itself with this axis.
dimension - Chart2D.X or Chart2D.Y.
position - Chart2D.CHART_POSITION_BOTTOM, Chart2D.CHART_POSITION_LEFT, Chart2D.CHART_POSITION_RIGHT or Chart2D.CHART_POSITION_TOP.

setFormatter

public void setFormatter(IAxisLabelFormatter formatter)
Sets the formatter to use for labels.

Specified by:
setFormatter in interface IAxis<T extends IAxisScalePolicy>
Parameters:
formatter - The formatter to set.

setMajorTickSpacing

public void setMajorTickSpacing(double majorTickSpacing)
This method sets the major tick spacing for label generation.

Only values between 0.0 and 100.0 are allowed.

The number that is passed-in represents the distance, measured in values, between each major tick mark. If you have a trace with a range from 0 to 50 and the major tick spacing is set to 10, you will get major ticks next to the following values: 0, 10, 20, 30, 40, 50.

Note:
Ticks are free of any multiples of 1000. If the chart contains values between 0 an 1000 and configured a tick of 2 the values 0, 200, 400, 600, 800 and 1000 will highly probable to be displayed. This depends on the size (in pixels) of the Chart2D<. Of course there is a difference: ticks are used in divisions and multiplications: If the internal values are very low and the ticks are very high, huge rounding errors might occur (division by ticks results in very low values a double cannot hit exactly. So prefer setting ticks between 0 an 10 or - if you know your values are very small (e.g. in nano range [10 -9 ]) use a small value (e.g. 2*10 -9 ).

Specified by:
setMajorTickSpacing in interface IAxis<T extends IAxisScalePolicy>
Parameters:
majorTickSpacing - the major tick spacing for label generation.

setMinorTickSpacing

public void setMinorTickSpacing(double minorTickSpacing)
This method sets the minor tick spacing for label generation.

The number that is passed-in represents the distance, measured in values, between each major tick mark. If you have a trace with a range from 0 to 50 and the major tick spacing is set to 10, you will get major ticks next to the following values: 0, 10, 20, 30, 40, 50.

Note:
Ticks are free of any powers of 10. There is no difference between setting a tick to 2, 200 or 20000 because ticks cannot break the rule that every scale label has to be visible. If the chart contains values between 0 an 1000 and configured a tick of 2 the values 0, 200, 400, 600, 800 and 1000 will highly probable to be displayed. This depends on the size (in pixels) of the Chart2D<. Of course there is a difference: ticks are used in divisions and multiplications: If the internal values are very low and the ticks are very high, huge rounding errors might occur (division by ticks results in very low values a double cannot hit exactly. So prefer setting ticks between 0 an 10 or - if you know your values are very small (e.g. in nano range [10 -9 ]) use a small value (e.g. 2*10 -9 ).

Specified by:
setMinorTickSpacing in interface IAxis<T extends IAxisScalePolicy>
Parameters:
minorTickSpacing - the minor tick spacing to set.

setPaintGrid

public final void setPaintGrid(boolean grid)
Set whether the grid in this dimension should be painted or not.

Specified by:
setPaintGrid in interface IAxis<T extends IAxisScalePolicy>
Parameters:
grid - true if the grid should be painted or false if not.

setPaintScale

public final void setPaintScale(boolean show)
Set if the scale for this axis should be shown.

Specified by:
setPaintScale in interface IAxis<T extends IAxisScalePolicy>
Parameters:
show - true if the scale on this axis should be shown, false else.

setPixelXLeft

public final void setPixelXLeft(int pixelXLeft)
Description copied from interface: IAxis
Sets a Range to use for filtering the view to the the connected Axis. Note that it's effect will be affected by the internal IRangePolicy.

This must only be called from the Chart2D itself!

Specified by:
setPixelXLeft in interface IAxis<T extends IAxisScalePolicy>
Parameters:
pixelXLeft - the left pixel coordinate of this axis in the graphic context of the current paint operation.
See Also:
IAxis.setPixelXLeft(int)

setPixelXRight

public final void setPixelXRight(int pixelXRight)
Description copied from interface: IAxis
Sets the right pixel of this axis coordinate in the graphic context of the current paint operation.

This must only be called from the Chart2D itself!

Specified by:
setPixelXRight in interface IAxis<T extends IAxisScalePolicy>
Parameters:
pixelXRight - the right pixel coordinate of this axis in the graphic context of the current paint operation.
See Also:
IAxis.setPixelXRight(int)

setPixelYBottom

public final void setPixelYBottom(int pixelYBottom)
Description copied from interface: IAxis
Sets the bottom pixel of this axis coordinate in the graphic context of the current paint operation.

This must only be called from the Chart2D itself!

Specified by:
setPixelYBottom in interface IAxis<T extends IAxisScalePolicy>
Parameters:
pixelYBottom - the bottom pixel coordinate of this axis in the graphic context of the current paint operation.
See Also:
IAxis.setPixelYBottom(int)

setPixelYTop

public final void setPixelYTop(int pixelYTop)
Description copied from interface: IAxis
Sets the top pixel of this axis coordinate in the graphic context of the current paint operation.

This must only be called from the Chart2D itself!

Specified by:
setPixelYTop in interface IAxis<T extends IAxisScalePolicy>
Parameters:
pixelYTop - the top pixel coordinate of this axis in the graphic context of the current paint operation.
See Also:
IAxis.setPixelYTop(int)

setRange

public final void setRange(Range range)

Sets a Range to use for filtering the view to the the connected Axis. Note that it's effect will be affected by the internal IRangePolicy.

To get full control use:
setRangePolicy(new <AnARangePolicy>(range);

Specified by:
setRange in interface IAxis<T extends IAxisScalePolicy>
Parameters:
range - Range to use for filtering the view to the the connected Axis.
See Also:
getRangePolicy(), IRangePolicy.setRange(Range)

ensureInitialized

protected final void ensureInitialized()
Ensures that no deadlock / NPE due to a missing internal chart reference may occur.

Throws:
java.lang.IllegalStateException - if this axis is not assigned to a chart.

setRangePolicy

public void setRangePolicy(IRangePolicy rangePolicy)

Sets the RangePolicy.

If the given RangePolicy has an unconfigured internal Range ( Range.RANGE_UNBOUNDED) the old internal RangePolicy is taken into account:
If the old RangePolicy has a configured Range this is transferred to the new RangePolicy.

A property change event for IAxis.PROPERTY_RANGEPOLICY is fired and receives listeners if a change took place.

Specified by:
setRangePolicy in interface IAxis<T extends IAxisScalePolicy>
Parameters:
rangePolicy - The rangePolicy to set.

setStartMajorTick

public void setStartMajorTick(boolean majorTick)
Set wether scale values are started from major ticks.

Specified by:
setStartMajorTick in interface IAxis<T extends IAxisScalePolicy>
Parameters:
majorTick - true if scale values shall start with a major tick.
See Also:
setMajorTickSpacing(double)

setTitle

@Deprecated
public final java.lang.String setTitle(java.lang.String title)
Deprecated. use getAxisTitle() and on the result IAxis.AxisTitle#setTitle(String)

Description copied from interface: IAxis
Sets the title of this axis will be painted by the {IAxisTitlePainter} of this instance.

Specified by:
setTitle in interface IAxis<T extends IAxisScalePolicy>
Parameters:
title - the title to set.
Returns:
the previous Title or null if there was no title configured before.
See Also:
IAxis.setTitlePainter(IAxisTitlePainter)

setTitlePainter

@Deprecated
public final IAxisTitlePainter setTitlePainter(IAxisTitlePainter painter)
Deprecated. use getAxisTitle() and on the result IAxis.AxisTitle#setTitlePainter(IAxisTitlePainter) instead.

Sets the title painter of this axis which is by default AxisTitlePainterDefault .

Specified by:
setTitlePainter in interface IAxis<T extends IAxisScalePolicy>
Parameters:
painter - the instance that will paint the title of this axis.
Returns:
the previous title painter of this axis or null if there was none configured before.

setVisible

public void setVisible(boolean visible)
Set the visibility of this axis.

Specified by:
setVisible in interface IAxis<T extends IAxisScalePolicy>
Parameters:
visible - true to show, false to hide

translateMousePosition

public double translateMousePosition(java.awt.event.MouseEvent mouseEvent)
                              throws java.lang.IllegalArgumentException
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 the correspondinig chart 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.
Throws:
java.lang.IllegalArgumentException - if the given mouse event is out of the current graphics context (not a mouse event of the chart component).

translatePxToValue

public double translatePxToValue(int pixel)
Description copied from interface: IAxis
Transforms the given pixel value (which has to be a awt value like MouseEvent.getY() 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.

Specified by:
translatePxToValue in interface IAxis<T extends IAxisScalePolicy>
Parameters:
pixel - a pixel value of the chart component as used by awt.
Returns:
the awt pixel value transformed to the chart value.
See Also:
IAxis.translatePxToValue(int)

translateValueToPx

public final int translateValueToPx(double value)
Description copied from interface: IAxis
Transforms the given chart data value into the corresponding awt pixel value for the chart.

Specified by:
translateValueToPx in interface IAxis<T extends IAxisScalePolicy>
Parameters:
value - a chart data value.
Returns:
the awt pixel value corresponding to the chart data value.
See Also:
IAxis.translateValueToPx(double)


Copyright © 2001 - 2010 LGPL, All Rights Footloose.